Skip to content

Commit 8d66eb5

Browse files
Rollup merge of #148795 - karolzwolak:rustflags-bootstrap-toml, r=Kobzol
add `rust.rustflags` and per target `rustflags` options to `bootstrap.toml` Part of #148782; see also #148708 Add new options `rust.rustflags` for all targets and `rustflags` par target that will pass specified flags to rustc for all stages. Target specific flags override (are passed after) global `rust.rustflags` ones. 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"] ``` r? bootstrap
2 parents 60ed1ab + 6e63c39 commit 8d66eb5

File tree

6 files changed

+42
-0
lines changed

6 files changed

+42
-0
lines changed

bootstrap.example.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,12 @@
708708
# desired in distributions, for example.
709709
#rust.rpath = true
710710

711+
# Additional flags to pass to `rustc`.
712+
# Takes precedence over bootstrap's own flags but not over per target rustflags nor env. vars. like RUSTFLAGS.
713+
# Applies to all stages and targets.
714+
#
715+
#rust.rustflags = []
716+
711717
# Indicates whether symbols should be stripped using `-Cstrip=symbols`.
712718
#rust.strip = false
713719

@@ -1013,6 +1019,12 @@
10131019
# and will override the same option under [rust] section. It only works on Unix platforms
10141020
#rpath = rust.rpath (bool)
10151021

1022+
# Additional flags to pass to `rustc`.
1023+
# Takes precedence over bootstrap's own flags and `rust.rustflags` but not over env. vars. like RUSTFLAGS.
1024+
# Applies to all stages.
1025+
#
1026+
#rustflags = rust.rustflags
1027+
10161028
# Force static or dynamic linkage of the standard library for this target. If
10171029
# this target is a host for rustc, this will also affect the linkage of the
10181030
# compiler itself. This is useful for building rustc on targets that normally

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub struct Cargo {
105105
allow_features: String,
106106
release_build: bool,
107107
build_compiler_stage: u32,
108+
extra_rustflags: Vec<String>,
108109
}
109110

110111
impl Cargo {
@@ -403,6 +404,11 @@ impl From<Cargo> for BootstrapCommand {
403404
cargo.args.insert(0, "--release".into());
404405
}
405406

407+
for arg in &cargo.extra_rustflags {
408+
cargo.rustflags.arg(arg);
409+
cargo.rustdocflags.arg(arg);
410+
}
411+
406412
// Propagate the envs here at the very end to make sure they override any previously set flags.
407413
cargo.rustflags.propagate_rustflag_envs(cargo.build_compiler_stage);
408414
cargo.rustdocflags.propagate_rustflag_envs(cargo.build_compiler_stage);
@@ -1379,6 +1385,15 @@ impl Builder<'_> {
13791385
rustflags.arg("-Zmir_strip_debuginfo=locals-in-tiny-functions");
13801386
}
13811387

1388+
// take target-specific extra rustflags if any otherwise take `rust.rustflags`
1389+
let extra_rustflags = self
1390+
.config
1391+
.target_config
1392+
.get(&target)
1393+
.map(|t| &t.rustflags)
1394+
.unwrap_or(&self.config.rust_rustflags)
1395+
.clone();
1396+
13821397
let release_build = self.config.rust_optimize.is_release() &&
13831398
// cargo bench/install do not accept `--release` and miri doesn't want it
13841399
!matches!(cmd_kind, Kind::Bench | Kind::Install | Kind::Miri | Kind::MiriSetup | Kind::MiriTest);
@@ -1394,6 +1409,7 @@ impl Builder<'_> {
13941409
allow_features,
13951410
release_build,
13961411
build_compiler_stage,
1412+
extra_rustflags,
13971413
}
13981414
}
13991415
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ pub struct Config {
225225
pub rust_std_features: BTreeSet<String>,
226226
pub rust_break_on_ice: bool,
227227
pub rust_parallel_frontend_threads: Option<u32>,
228+
pub rust_rustflags: Vec<String>,
228229

229230
pub llvm_profile_use: Option<String>,
230231
pub llvm_profile_generate: bool,
@@ -575,6 +576,7 @@ impl Config {
575576
bootstrap_override_lld_legacy: rust_bootstrap_override_lld_legacy,
576577
std_features: rust_std_features,
577578
break_on_ice: rust_break_on_ice,
579+
rustflags: rust_rustflags,
578580
} = toml.rust.unwrap_or_default();
579581

580582
let Llvm {
@@ -864,6 +866,7 @@ impl Config {
864866
sanitizers: target_sanitizers,
865867
profiler: target_profiler,
866868
rpath: target_rpath,
869+
rustflags: target_rustflags,
867870
crt_static: target_crt_static,
868871
musl_root: target_musl_root,
869872
musl_libdir: target_musl_libdir,
@@ -947,6 +950,7 @@ impl Config {
947950
target.sanitizers = target_sanitizers;
948951
target.profiler = target_profiler;
949952
target.rpath = target_rpath;
953+
target.rustflags = target_rustflags.unwrap_or_default();
950954
target.optimized_compiler_builtins = target_optimized_compiler_builtins;
951955
target.jemalloc = target_jemalloc;
952956
if let Some(backends) = target_codegen_backends {
@@ -1441,6 +1445,7 @@ impl Config {
14411445
rust_randomize_layout: rust_randomize_layout.unwrap_or(false),
14421446
rust_remap_debuginfo: rust_remap_debuginfo.unwrap_or(false),
14431447
rust_rpath: rust_rpath.unwrap_or(true),
1448+
rust_rustflags: rust_rustflags.unwrap_or_default(),
14441449
rust_stack_protector,
14451450
rust_std_features: rust_std_features
14461451
.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",
@@ -375,6 +376,7 @@ pub fn check_incompatible_options_for_ci_rustc(
375376
parallel_frontend_threads: _,
376377
bootstrap_override_lld: _,
377378
bootstrap_override_lld_legacy: _,
379+
rustflags: _,
378380
} = ci_rust_config;
379381

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ define_config! {
3737
sanitizers: Option<bool> = "sanitizers",
3838
profiler: Option<StringOrBool> = "profiler",
3939
rpath: Option<bool> = "rpath",
40+
rustflags: Option<Vec<String>> = "rustflags",
4041
crt_static: Option<bool> = "crt-static",
4142
musl_root: Option<String> = "musl-root",
4243
musl_libdir: Option<String> = "musl-libdir",
@@ -70,6 +71,7 @@ pub struct Target {
7071
pub sanitizers: Option<bool>,
7172
pub profiler: Option<StringOrBool>,
7273
pub rpath: Option<bool>,
74+
pub rustflags: Vec<String>,
7375
pub crt_static: Option<bool>,
7476
pub musl_root: Option<PathBuf>,
7577
pub musl_libdir: Option<PathBuf>,

src/bootstrap/src/utils/change_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,4 +596,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
596596
severity: ChangeSeverity::Info,
597597
summary: "The `-Zannotate-moves` option is now always enabled when building rustc, sysroot and tools.",
598598
},
599+
ChangeInfo {
600+
change_id: 148795,
601+
severity: ChangeSeverity::Info,
602+
summary: "New options `rust.rustflags` for all targets and `rustflags` par target that will pass specified flags to rustc for all stages. Target specific flags override global `rust.rustflags` ones.",
603+
},
599604
];

0 commit comments

Comments
 (0)