Skip to content

Commit

Permalink
feat: add compiler flags to BuildArgs (#1637)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Aaron-Bloom authored Oct 16, 2024
1 parent ad3a034 commit 9bdb3ad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/build/src/command/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/build/src/command/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions crates/build/src/command/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,11 @@ pub(crate) fn get_program_build_args(args: &BuildArgs) -> Vec<String> {
}

/// 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")
}

Expand Down
8 changes: 8 additions & 0 deletions crates/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ pub struct BuildArgs {
help = "Space or comma separated list of features to activate"
)]
pub features: Vec<String>,
#[clap(
long,
action,
value_delimiter = ',',
help = "Space or comma separated list of extra flags to invokes `rustc` with"
)]
pub rustflags: Vec<String>,
#[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")]
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 9bdb3ad

Please sign in to comment.