diff --git a/Cargo.lock b/Cargo.lock
index 78eb0953be..b1e7f048e7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1393,7 +1393,7 @@ checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25"
dependencies = [
"proc-macro2",
"quote",
- "syn 2.0.75",
+ "syn 2.0.87",
]
[[package]]
@@ -3880,6 +3880,7 @@ dependencies = [
"serde_json",
"sha256",
"spinoff",
+ "strum 0.25.0",
"wasm-opt",
]
diff --git a/crates/iroha_wasm_builder/Cargo.toml b/crates/iroha_wasm_builder/Cargo.toml
index 990a2ff8a9..d8864507d5 100644
--- a/crates/iroha_wasm_builder/Cargo.toml
+++ b/crates/iroha_wasm_builder/Cargo.toml
@@ -16,6 +16,7 @@ eyre = { workspace = true }
serde_json = { workspace = true, features = ["std"] }
sha256 = "1.5.0"
path-absolutize = { workspace = true }
+strum = { workspace = true, features = ["derive", "std"] }
wasm-opt = "0.116.1"
clap = { workspace = true, features = ["derive"] }
diff --git a/crates/iroha_wasm_builder/src/lib.rs b/crates/iroha_wasm_builder/src/lib.rs
index 84c2cca9c2..e4da047254 100644
--- a/crates/iroha_wasm_builder/src/lib.rs
+++ b/crates/iroha_wasm_builder/src/lib.rs
@@ -15,7 +15,24 @@ use path_absolutize::Absolutize;
/// Current toolchain used to build smartcontracts
const TOOLCHAIN: &str = "+nightly-2024-09-09";
-const OPTIMIZED_PROFILE: &str = "deploy";
+
+/// Build profile for smartcontracts
+#[derive(Debug, Copy, Clone, Eq, PartialEq, strum::Display, strum::EnumString, Default)]
+#[strum(serialize_all = "snake_case")]
+pub enum Profile {
+ /// Applies release optimization
+ #[default]
+ Release,
+ /// Applies release and size optimizations
+ Deploy,
+}
+
+impl Profile {
+ /// Checks whether profile uses optimizations from wasm-opt
+ pub fn is_optimized(profile: Self) -> bool {
+ return profile == Profile::Deploy;
+ }
+}
/// WASM Builder for smartcontracts (e.g. triggers and executors).
///
@@ -46,14 +63,14 @@ pub struct Builder<'path, 'out_dir> {
/// Flag controlling whether to show output of the build process
show_output: bool,
/// Build profile
- profile: String,
+ profile: Profile,
}
impl<'path, 'out_dir> Builder<'path, 'out_dir> {
/// Initialize [`Builder`] with path to smartcontract.
///
/// `relative_path` should be relative to `CARGO_MANIFEST_DIR`.
- pub fn new
(relative_path: &'path P, profile: &str) -> Self
+ pub fn new
(relative_path: &'path P, profile: Profile) -> Self
where
P: AsRef + ?Sized,
{
@@ -61,7 +78,7 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
path: relative_path.as_ref(),
out_dir: None,
show_output: false,
- profile: profile.to_string(),
+ profile: profile,
}
}
@@ -103,6 +120,17 @@ impl<'path, 'out_dir> Builder<'path, 'out_dir> {
///
/// Will also return error if ran on workspace and not on the concrete package.
pub fn build(self) -> Result