فهرست منبع

Update and fix target config file templates (#1546)

We don't want to maintain the same files twice. For Polkadot, one version was outdated.
The other one contained an invalid config for `wasm-opt`.
Cyrill Leutwiler 2 سال پیش
والد
کامیت
dd810b156f

+ 0 - 1
.dockerignore

@@ -1,5 +1,4 @@
 Cargo.lock
-examples
 build
 target
 .gitnore

+ 63 - 0
examples/polkadot/polkadot_config.toml

@@ -0,0 +1,63 @@
+[package]
+authors = ["Your Name <your@email.com>"]
+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

+ 0 - 34
examples/polkadot/substrate_config.toml

@@ -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

+ 39 - 14
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
+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

+ 11 - 2
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
                 }

+ 4 - 4
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

+ 0 - 20
src/bin/solang_new_examples/polkadot/flipper.sol

@@ -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;
-	}
-}

+ 0 - 35
src/bin/solang_new_examples/polkadot/polkadot_config.toml

@@ -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

+ 0 - 22
src/bin/solang_new_examples/solana/flipper.sol

@@ -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;
-	}
-}

+ 0 - 31
src/bin/solang_new_examples/solana/solana_config.toml

@@ -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