diff --git a/.dockerignore b/.dockerignore index c09afb245..20124ceb0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,4 @@ Cargo.lock -examples build target .gitnore diff --git a/examples/polkadot/polkadot_config.toml b/examples/polkadot/polkadot_config.toml new file mode 100644 index 000000000..77f08716d --- /dev/null +++ b/examples/polkadot/polkadot_config.toml @@ -0,0 +1,63 @@ +[package] +authors = ["Your Name "] +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 \ No newline at end of file diff --git a/examples/polkadot/substrate_config.toml b/examples/polkadot/substrate_config.toml deleted file mode 100644 index 5ed062c01..000000000 --- a/examples/polkadot/substrate_config.toml +++ /dev/null @@ -1,34 +0,0 @@ -[package] -authors = ["sesa"] -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"} - - -[target] -name = "polkadot" # Valid targets are "solana" and "polkadot" -address_length = 32 -value_length = 16 - - -[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. - -[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" - -[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 \ No newline at end of file diff --git a/examples/solana/solana_config.toml b/examples/solana/solana_config.toml index 528ed0989..ed9725e62 100644 --- a/examples/solana/solana_config.toml +++ b/examples/solana/solana_config.toml @@ -1,18 +1,33 @@ [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 @@ -20,11 +35,21 @@ 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 \ No newline at end of file +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 \ No newline at end of file diff --git a/src/bin/cli/test.rs b/src/bin/cli/test.rs index dec234c77..38ef7ae1f 100644 --- a/src/bin/cli/test.rs +++ b/src/bin/cli/test.rs @@ -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(); @@ -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#" @@ -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 } diff --git a/src/bin/solang.rs b/src/bin/solang.rs index 27c98c310..038ad1871 100644 --- a/src/bin/solang.rs +++ b/src/bin/solang.rs @@ -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); @@ -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 diff --git a/src/bin/solang_new_examples/polkadot/flipper.sol b/src/bin/solang_new_examples/polkadot/flipper.sol deleted file mode 100644 index 4a3336e87..000000000 --- a/src/bin/solang_new_examples/polkadot/flipper.sol +++ /dev/null @@ -1,20 +0,0 @@ -contract flipper { - bool private value; - - /// Constructor that initializes the `bool` value to the given `init_value`. - constructor(bool initvalue) { - value = initvalue; - } - - /// A message that can be called on instantiated contracts. - /// This one flips the value of the stored `bool` from `true` - /// to `false` and vice versa. - function flip() public { - value = !value; - } - - /// Simply returns the current value of our `bool`. - function get() public view returns (bool) { - return value; - } -} diff --git a/src/bin/solang_new_examples/polkadot/polkadot_config.toml b/src/bin/solang_new_examples/polkadot/polkadot_config.toml deleted file mode 100644 index 6083b13f5..000000000 --- a/src/bin/solang_new_examples/polkadot/polkadot_config.toml +++ /dev/null @@ -1,35 +0,0 @@ -[package] -authors = ["sesa"] -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"} - - -[target] -name = "polkadot" # Valid targets are "solana" and "polkadot" -address_length = 32 -value_length = 16 - - -[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. - -[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" -wasm_opt = 1 - -[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 \ No newline at end of file diff --git a/src/bin/solang_new_examples/solana/flipper.sol b/src/bin/solang_new_examples/solana/flipper.sol deleted file mode 100644 index e23b05b2a..000000000 --- a/src/bin/solang_new_examples/solana/flipper.sol +++ /dev/null @@ -1,22 +0,0 @@ -@program_id("F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC") -contract flipper { - bool private value; - - /// Constructor that initializes the `bool` value to the given `init_value`. - @payer(payer) - constructor(bool initvalue) { - value = initvalue; - } - - /// A message that can be called on instantiated contracts. - /// This one flips the value of the stored `bool` from `true` - /// to `false` and vice versa. - function flip() public { - value = !value; - } - - /// Simply returns the current value of our `bool`. - function get() public view returns (bool) { - return value; - } -} diff --git a/src/bin/solang_new_examples/solana/solana_config.toml b/src/bin/solang_new_examples/solana/solana_config.toml deleted file mode 100644 index 0af1c1a42..000000000 --- a/src/bin/solang_new_examples/solana/solana_config.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -authors = ["sesa"] -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"} - - -[target] -name = "solana" # Valid targets are "solana" and "polkadot" - -[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. - -[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" - -[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 \ No newline at end of file