diff --git a/crates/build/src/command/docker.rs b/crates/build/src/command/docker.rs index f208b41bd4..02c877d675 100644 --- a/crates/build/src/command/docker.rs +++ b/crates/build/src/command/docker.rs @@ -85,7 +85,7 @@ pub(crate) fn create_docker_command( "-e".to_string(), "RUSTC_BOOTSTRAP=1".to_string(), // allows trim-paths. "-e".to_string(), - format!("CARGO_ENCODED_RUSTFLAGS={}", get_rust_compiler_flags()), + format!("CARGO_ENCODED_RUSTFLAGS={}", get_rust_compiler_flags(args)), "--entrypoint".to_string(), "".to_string(), image, diff --git a/crates/build/src/command/local.rs b/crates/build/src/command/local.rs index 7d22194436..0e9fe68e5d 100644 --- a/crates/build/src/command/local.rs +++ b/crates/build/src/command/local.rs @@ -39,7 +39,7 @@ pub(crate) fn create_local_command( command .current_dir(canonicalized_program_dir) .env("RUSTUP_TOOLCHAIN", "succinct") - .env("CARGO_ENCODED_RUSTFLAGS", get_rust_compiler_flags()) + .env("CARGO_ENCODED_RUSTFLAGS", get_rust_compiler_flags(args)) .env_remove("RUSTC") .env("CARGO_TARGET_DIR", program_metadata.target_directory.join(HELPER_TARGET_SUBDIR)) // TODO: remove once trim-paths is supported - https://github.com/rust-lang/rust/issues/111540 diff --git a/crates/build/src/command/utils.rs b/crates/build/src/command/utils.rs index 7ddcd00336..7eef9dc9a4 100644 --- a/crates/build/src/command/utils.rs +++ b/crates/build/src/command/utils.rs @@ -44,15 +44,11 @@ pub(crate) fn get_program_build_args(args: &BuildArgs) -> Vec { } /// Rust flags for compilation of C libraries. -pub(crate) fn get_rust_compiler_flags() -> String { - let rust_flags = [ - "-C".to_string(), - "passes=loweratomic".to_string(), - "-C".to_string(), - "link-arg=-Ttext=0x00200800".to_string(), - "-C".to_string(), - "panic=abort".to_string(), - ]; +pub(crate) fn get_rust_compiler_flags(args: &BuildArgs) -> String { + let rust_flags = + ["-C", "passes=loweratomic", "-C", "link-arg=-Ttext=0x00200800", "-C", "panic=abort"]; + let rust_flags: Vec<_> = + rust_flags.into_iter().chain(args.rustflags.iter().map(String::as_str)).collect(); rust_flags.join("\x1f") } diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index b734230dbf..17b18602fc 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -37,6 +37,13 @@ pub struct BuildArgs { help = "Space or comma separated list of features to activate" )] pub features: Vec, + #[clap( + long, + action, + value_delimiter = ',', + help = "Space or comma separated list of extra flags to invokes `rustc` with" + )] + pub rustflags: Vec, #[clap(long, action, help = "Do not activate the `default` feature")] pub no_default_features: bool, #[clap(long, action, help = "Ignore `rust-version` specification in packages")] @@ -70,6 +77,7 @@ impl Default for BuildArgs { docker: false, tag: DEFAULT_TAG.to_string(), features: vec![], + rustflags: vec![], ignore_rust_version: false, binary: "".to_string(), elf_name: "".to_string(),