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

Align WASM feature set in scrypto compiler #1973

Merged
merged 10 commits into from
Oct 25, 2024
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
20 changes: 18 additions & 2 deletions radix-clis/src/scrypto/cmd_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub struct Build {
features: Option<String>,

/// Environment variables to define. Specify as NAME=VALUE or NAME.
/// Scrypto compiler internally sets some compilation flags `TARGET_CFLAGS` for C libraries
/// to configure WASM with the same features as Radix Engine.
/// If you want to override it, then you can use this option.
/// If you want to remove TARGET_CFLAGS, then use `--unset-env` option
#[clap(short, long)]
env: Option<Vec<String>>,

Expand Down Expand Up @@ -68,6 +72,10 @@ pub struct Build {
/// Pass any additional option to `cargo build` call.
#[clap(long)]
custom_option: Option<Vec<String>>,

/// Prints compilation steps.
#[clap(short, long)]
verbose: bool,
}

impl Build {
Expand Down Expand Up @@ -111,19 +119,27 @@ impl Build {
compiler_builder.package(p);
});
}
compiler_builder.debug(self.verbose);

if let Some(env) = &self.env {
let env_variables_decoded: Vec<Vec<&str>> = env
.iter()
.map(|e| e.split('=').collect::<Vec<&str>>())
.map(|e|
// Split string on the first '=' occurence.
// This is to cover cases like this:
// ENV_NAME=foo=bar
match e.split_once('=') {
Some((key, val)) => vec![key, val],
None => vec![e.as_str()],
})
.collect();
for v in env_variables_decoded {
if v.len() == 1 {
compiler_builder.env(v[0], EnvironmentVariableAction::Set("".into()));
} else if v.len() == 2 {
compiler_builder.env(v[0], EnvironmentVariableAction::Set(v[1].into()));
} else {
return Err(Error::BuildError(BuildError::ProfileNameError).into());
return Err(Error::BuildError(BuildError::EnvParsingError).into());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion radix-clis/src/utils/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum BuildError {

WorkspaceNotSupported,

ProfileNameError,
EnvParsingError,
}

#[derive(Debug)]
Expand Down
7 changes: 5 additions & 2 deletions radix-clis/tests/scrypto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $scrypto new-package hello-world --path $test_pkg --local
#
# To test that the generated Cargo.lock is good, we run a build with the --locked command below.
# This checks that the templated cargo lock is complete.
#
#
# If this line fails, run ./update-cargo-locks-minimally.sh from the repo root to
# regenerate the Cargo.lock_template which is used.
$scrypto build --path $test_pkg --locked
Expand All @@ -30,6 +30,9 @@ $scrypto test --path $test_pkg --locked
$scrypto test --path $test_pkg --locked -- test_hello --nocapture
$scrypto test --path $test_pkg --locked -- --nocapture

# Check envs parsing
$scrypto build --path $test_pkg --locked --env ENV_NAME=foo=bar

# Logging
$scrypto build --path ../examples/everything --log-level ERROR --locked
size1=$(ls -la ../examples/everything/target/wasm32-unknown-unknown/release/everything.wasm | cut -d ' ' -f 5)
Expand All @@ -51,4 +54,4 @@ else
fi

# Clean up
rm -fr $test_pkg
rm -fr $test_pkg
135 changes: 81 additions & 54 deletions scrypto-compiler/src/lib.rs

Large diffs are not rendered by default.

Loading
Loading