Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and fix target config file templates #1546

Merged
merged 7 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Cargo.lock
examples
build
target
.gitnore
Expand Down
63 changes: 63 additions & 0 deletions examples/polkadot/polkadot_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[package]
authors = ["Your Name <[email protected]>"]
version = "0.1.0"

# Source files to be compiled.
input_files = ["flipper.sol"]

# Contracts to be compiled.
# If no contracts are specified, solang will compile all non-virtual contracts.
contracts = ["flipper"]

# Specify required import paths.
import_path = []

# Define any importmaps.
# import_map = { "@openzeppelin" = "/home/user/libraries/openzeppelin-contracts/" }
import_map = {}


[target]
name = "polkadot"
address_length = 32
value_length = 16


[debug-features]
# Log debug prints to the environment.
prints = true

# Log runtime errors to the environment.
log-runtime-errors = true

# Add debug info to the generated llvm IR.
generate-debug-info = false

[optimizations]
dead-storage = true
constant-folding = true
strength-reduce = true
vector-to-slice = true
common-subexpression-elimination = true


# Valid wasm-opt passes are: Zero, One, Two, Three, Four, S, (focusing on code size) or Z (super-focusing on code size)
wasm-opt = "Z"

# Valid LLVM optimization levels are: none, less, default, aggressive
llvm-IR-optimization-level = "aggressive"

[compiler-output]
verbose = false

# Emit compiler state at early stages. Valid options are: ast-dot, cfg, llvm-ir, llvm-bc, object, asm
# emit = "llvm-ir"

# Output directory for binary artifacts.
# output_directory = "path/to/dir"

# Output directory for the metadata.
# output_meta = "path/to/dir"

# Output everything in a JSON format on STDOUT instead of writing output files.
std_json_output = false
34 changes: 0 additions & 34 deletions examples/polkadot/substrate_config.toml

This file was deleted.

53 changes: 39 additions & 14 deletions examples/solana/solana_config.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,55 @@
[package]
version = "0.1.0"
input_files = ["flipper.sol"] # Files to be compiled. You can define multiple files as : input_files = ["file1", "file2", ..]
contracts = ["flipper"] # Contracts to include from the compiled files
import_path = []
import_map = {} # Maps to import. Define as import_map = {map = "path/to/map1", map2 = "path/to/map2"}

# Source files to be compiled.
input_files = ["flipper.sol"]

# Contracts to be compiled.
# If no contracts are specified, solang will compile all non-virtual contracts.
contracts = ["flipper"]

# Specify required import paths.
import_path = []

# Define any importmaps.
# import_map = { "@openzeppelin" = "/home/user/libraries/openzeppelin-contracts/" }
import_map = {}


[target]
name = "solana" # Valid targets are "solana" and "polkadot"
name = "solana"

[debug-features]
prints = true # Log debug prints to the environment.
log-runtime-errors = true # Log runtime errors to the environment.
generate-debug-info = false # Add debug info to the generated llvm IR.
# Log debug prints to the environment.
prints = true

# Log runtime errors to the environment.
log-runtime-errors = true

# Add debug info to the generated llvm IR.
generate-debug-info = false

[optimizations]
dead-storage = true
constant-folding = true
strength-reduce = true
vector-to-slice = true
common-subexpression-elimination = true
llvm-IR-optimization-level = "default" # Set llvm optimizer level. Valid options are "none", "less", "default", "aggressive"

# Valid LLVM optimization levels are: none, less, default, aggressive
llvm-IR-optimization-level = "aggressive"

[compiler-output]
verbose = false # show debug messages
#emit = "llvm-ir" # Emit compiler state at early stage. Valid options are: "ast-dot", "cfg", "llvm-ir", "llvm-bc", "object", "asm".
#output_directory = "path/to/dir"
#output_meta = "path/to/dir" # output directory for metadata
std_json_output = false # mimic solidity json output on stdout
verbose = false

# Emit compiler state at early stages. Valid options are: ast-dot, cfg, llvm-ir, llvm-bc, object, asm
# emit = "llvm-ir"

# Output directory for binary artifacts.
# output_directory = "path/to/dir"

# Output directory for the metadata.
# output_meta = "path/to/dir"

# Output everything in a JSON format on STDOUT instead of writing output files.
std_json_output = false
13 changes: 11 additions & 2 deletions src/bin/cli/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mod tests {
strength-reduce = false
vector-to-slice = false
common-subexpression-elimination = true
llvm-IR-optimization-level = "aggressive" # Set llvm optimizer level. Valid options are "none", "less", "default", "aggressive""#;
llvm-IR-optimization-level = "aggressive""#;

let opt: cli::Optimizations = toml::from_str(opt_toml).unwrap();

Expand All @@ -124,6 +124,15 @@ mod tests {
assert_eq!(opt.opt_level.unwrap(), "aggressive");
}

#[cfg(feature = "wasm_opt")]
#[test]
fn wasm_opt_option() {
use contract_build::OptimizationPasses;

let opt: cli::Optimizations = toml::from_str(r#"wasm-opt = "Zero""#).unwrap();
assert_eq!(opt.wasm_opt_passes, Some(OptimizationPasses::Zero));
}

#[test]
fn parse_target() {
let target_toml = r#"
Expand Down Expand Up @@ -204,7 +213,7 @@ mod tests {
strength_reduce: true,
vector_to_slice: true,
common_subexpression_elimination: true,
opt_level: Some("default".to_owned()),
opt_level: Some("aggressive".to_owned()),
#[cfg(feature = "wasm_opt")]
wasm_opt_passes: None
}
Expand Down
8 changes: 4 additions & 4 deletions src/bin/solang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ fn new_command(args: New) {
}

let flipper = match target {
"solana" => include_str!("./solang_new_examples/solana/flipper.sol"),
"polkadot" => include_str!("./solang_new_examples/polkadot/flipper.sol"),
"solana" => include_str!("../../examples/solana/flipper.sol"),
"polkadot" => include_str!("../../examples/polkadot/flipper.sol"),
"evm" => {
eprintln!("EVM target is not supported yet!");
exit(1);
Expand All @@ -110,8 +110,8 @@ fn new_command(args: New) {
let mut toml_file = create_file(&Path::new(&dir_path).join("solang.toml"));

let toml_content = match target {
"solana" => include_str!("./solang_new_examples/solana/solana_config.toml"),
"polkadot" => include_str!("./solang_new_examples/polkadot/polkadot_config.toml"),
"solana" => include_str!("../../examples/solana/solana_config.toml"),
"polkadot" => include_str!("../../examples/polkadot/polkadot_config.toml"),
_ => unreachable!(),
};
toml_file
Expand Down
20 changes: 0 additions & 20 deletions src/bin/solang_new_examples/polkadot/flipper.sol

This file was deleted.

35 changes: 0 additions & 35 deletions src/bin/solang_new_examples/polkadot/polkadot_config.toml

This file was deleted.

22 changes: 0 additions & 22 deletions src/bin/solang_new_examples/solana/flipper.sol

This file was deleted.

31 changes: 0 additions & 31 deletions src/bin/solang_new_examples/solana/solana_config.toml

This file was deleted.

Loading