Skip to content

Commit 416418a

Browse files
committed
feat: add rust.rustflags option to bootstrap.toml
This makes easy to persistently pass any flag to the compiler when building rustc. For example you can use a different linker by putting the following in `bootstrap.toml`: ```toml [rust] rustflags = ["-Clinker=clang", "-Clink-arg=--ld-path=wild"] ```
1 parent 9312cd6 commit 416418a

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ impl Builder<'_> {
601601
}
602602

603603
let mut rustflags = Rustflags::new(target);
604+
605+
for arg in &self.config.rust_rustflags {
606+
rustflags.arg(arg);
607+
}
608+
604609
if build_compiler_stage != 0 {
605610
if let Ok(s) = env::var("CARGOFLAGS_NOT_BOOTSTRAP") {
606611
cargo.args(s.split_whitespace());

src/bootstrap/src/core/config/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ pub struct Config {
224224
pub rust_std_features: BTreeSet<String>,
225225
pub rust_break_on_ice: bool,
226226
pub rust_parallel_frontend_threads: Option<u32>,
227+
pub rust_rustflags: Vec<String>,
227228

228229
pub llvm_profile_use: Option<String>,
229230
pub llvm_profile_generate: bool,
@@ -571,6 +572,7 @@ impl Config {
571572
bootstrap_override_lld_legacy: rust_bootstrap_override_lld_legacy,
572573
std_features: rust_std_features,
573574
break_on_ice: rust_break_on_ice,
575+
rustflags: rust_rustflags,
574576
} = toml.rust.unwrap_or_default();
575577

576578
let Llvm {
@@ -1431,6 +1433,7 @@ impl Config {
14311433
rust_randomize_layout: rust_randomize_layout.unwrap_or(false),
14321434
rust_remap_debuginfo: rust_remap_debuginfo.unwrap_or(false),
14331435
rust_rpath: rust_rpath.unwrap_or(true),
1436+
rust_rustflags: rust_rustflags.unwrap_or_default(),
14341437
rust_stack_protector,
14351438
rust_std_features: rust_std_features
14361439
.unwrap_or(BTreeSet::from([String::from("panic-unwind")])),

src/bootstrap/src/core/config/toml/rust.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ define_config! {
3333
channel: Option<String> = "channel",
3434
musl_root: Option<String> = "musl-root",
3535
rpath: Option<bool> = "rpath",
36+
rustflags: Option<Vec<String>> = "rustflags",
3637
strip: Option<bool> = "strip",
3738
frame_pointers: Option<bool> = "frame-pointers",
3839
stack_protector: Option<String> = "stack-protector",
@@ -373,6 +374,7 @@ pub fn check_incompatible_options_for_ci_rustc(
373374
parallel_frontend_threads: _,
374375
bootstrap_override_lld: _,
375376
bootstrap_override_lld_legacy: _,
377+
rustflags: _,
376378
} = ci_rust_config;
377379

378380
// There are two kinds of checks for CI rustc incompatible options:

0 commit comments

Comments
 (0)