Repository: ergoplatform/sigma-rust (language: rust)

Issue:
Minimize Wasm binary



Discussion / hints:

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index b6d893762..41be49db5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,5 +22,5 @@ members = [
 
 [profile.release]
 # Tell `rustc` to optimize for small code size.
-opt-level = "s"
+opt-level = "z"
 lto = true
diff --git a/bindings/ergo-lib-c-core/Cargo.toml b/bindings/ergo-lib-c-core/Cargo.toml
index 11468c21f..ec5b88375 100644
--- a/bindings/ergo-lib-c-core/Cargo.toml
+++ b/bindings/ergo-lib-c-core/Cargo.toml
@@ -31,6 +31,6 @@ version = "^0.7.0"
 features = ["serde"]
 
 [features]
-default = ["mnemonic_gen"]
+default = ["mnemonic_gen", "ergo-lib/compiler"]
 rest = ["tokio", "ergo-lib/rest"]
 mnemonic_gen = ["ergo-lib/mnemonic_gen"]
diff --git a/bindings/ergo-lib-wasm/Cargo.toml b/bindings/ergo-lib-wasm/Cargo.toml
index 9d68ccb88..e2c322cf9 100644
--- a/bindings/ergo-lib-wasm/Cargo.toml
+++ b/bindings/ergo-lib-wasm/Cargo.toml
@@ -13,6 +13,7 @@ crate-type = ["cdylib", "rlib"]
 [features]
 default = ["console_error_panic_hook"]
 rest = ["ergo-lib/rest"]
+compiler = ["ergo-lib/compiler"]
 
 [dependencies]
 base16 = "0.2.1"
@@ -73,5 +74,5 @@ default-features = false
 features = ["std"]
 
 [package.metadata.wasm-pack.profile.release]
-# wasm-opt = ["-O", "--enable-mutable-globals"]
-wasm-opt = false
+wasm-opt = ["-Os", "--enable-mutable-globals"]
+# wasm-opt = false
diff --git a/bindings/ergo-lib-wasm/src/contract.rs b/bindings/ergo-lib-wasm/src/contract.rs
index 3f234cb2b..bf3ad8b32 100644
--- a/bindings/ergo-lib-wasm/src/contract.rs
+++ b/bindings/ergo-lib-wasm/src/contract.rs
@@ -1,6 +1,5 @@
 //! Contract, for easier ErgoTree generation
 use ergo_lib::chain;
-use ergo_lib::ergoscript_compiler::script_env::ScriptEnv;
 use wasm_bindgen::prelude::*;
 
 use crate::address::Address;
@@ -27,10 +26,14 @@ impl Contract {
     }
 
     /// Compiles a contract from ErgoScript source code
+    #[cfg(feature = "compiler")]
     pub fn compile(source: &str) -> Result<Contract, JsValue> {
-        chain::contract::Contract::compile(source, ScriptEnv::new())
-            .map_err(|e| JsValue::from_str(e.pretty_desc(source).as_str()))
-            .map(Contract)
+        chain::contract::Contract::compile(
+            source,
+            ergo_lib::ergoscript_compiler::script_env::ScriptEnv::new(),
+        )
+        .map_err(|e| JsValue::from_str(e.pretty_desc(source).as_str()))
+        .map(Contract)
     }
 
     /// Get the ErgoTree of the contract
diff --git a/ergo-lib/Cargo.toml b/ergo-lib/Cargo.toml
index 0db1bbaf4..526b88527 100644
--- a/ergo-lib/Cargo.toml
+++ b/ergo-lib/Cargo.toml
@@ -58,7 +58,7 @@ features = [ "json" ]
 optional = true
 
 [features]
-default = ["json", "compiler"]
+default = ["json"]
 json = ["serde", "serde_json", "serde_with", "bounded-vec/serde"]
 compiler = ["ergoscript-compiler"]
 arbitrary = ["proptest", "proptest-derive", "ergotree-ir/arbitrary", "ergo-chain-types/arbitrary", "ergotree-interpreter/arbitrary"]
diff --git a/ergotree-ir/src/chain/ergo_box/register.rs b/ergotree-ir/src/chain/ergo_box/register.rs
index 877894db0..541223f3f 100644
--- a/ergotree-ir/src/chain/ergo_box/register.rs
+++ b/ergotree-ir/src/chain/ergo_box/register.rs
@@ -120,7 +120,7 @@ impl TryFrom<String> for NonMandatoryRegisterId {
     type Error = NonMandatoryRegisterIdParsingError;
     fn try_from(str: String) -> Result<Self, Self::Error> {
         if str.len() == 2 && &str[..1] == "R" {
-            let index = (&str[1..2])
+            let index = str[1..2]
                 .parse::<usize>()
                 .map_err(|_| NonMandatoryRegisterIdParsingError())?;
             if (NonMandatoryRegisterId::START_INDEX..=NonMandatoryRegisterId::END_INDEX)


Test patch:
diff --git a/bindings/ergo-lib-wasm/tests/test_contract.js b/bindings/ergo-lib-wasm/tests/test_contract.js
index 8a539a5e9..613420a73 100644
--- a/bindings/ergo-lib-wasm/tests/test_contract.js
+++ b/bindings/ergo-lib-wasm/tests/test_contract.js
@@ -6,7 +6,9 @@ beforeEach(async () => {
   ergo_wasm = await ergo;
 });
 
-it("Contract compiles from ErgoScript", async () => {
-  let contract = ergo_wasm.Contract.compile("HEIGHT");
-  assert(contract != null);
-});
+// enable when ergo-lib-wasm is built with "compiler" feature enabled
+//
+// it("Contract compiles from ErgoScript", async () => {
+//   let contract = ergo_wasm.Contract.compile("HEIGHT");
+//   assert(contract != null);
+// });