Skip to content
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
12 changes: 12 additions & 0 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,12 @@
# desired in distributions, for example.
#rust.rpath = true

# Additional flags to pass to `rustc`.
# Takes precedence over bootstrap's own flags but not over per target rustflags nor env. vars. like RUSTFLAGS.
# Applies to all stages and targets.
#
#rust.rustflags = []

# Indicates whether symbols should be stripped using `-Cstrip=symbols`.
#rust.strip = false

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

# Additional flags to pass to `rustc`.
# Takes precedence over bootstrap's own flags and `rust.rustflags` but not over env. vars. like RUSTFLAGS.
# Applies to all stages.
#
#rustflags = rust.rustflags

# Force static or dynamic linkage of the standard library for this target. If
# this target is a host for rustc, this will also affect the linkage of the
# compiler itself. This is useful for building rustc on targets that normally
Expand Down
16 changes: 16 additions & 0 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub struct Cargo {
allow_features: String,
release_build: bool,
build_compiler_stage: u32,
extra_rustflags: Vec<String>,
}

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

for arg in &cargo.extra_rustflags {
cargo.rustflags.arg(arg);
cargo.rustdocflags.arg(arg);
}

// Propagate the envs here at the very end to make sure they override any previously set flags.
cargo.rustflags.propagate_rustflag_envs(cargo.build_compiler_stage);
cargo.rustdocflags.propagate_rustflag_envs(cargo.build_compiler_stage);
Expand Down Expand Up @@ -1379,6 +1385,15 @@ impl Builder<'_> {
rustflags.arg("-Zmir_strip_debuginfo=locals-in-tiny-functions");
}

// take target-specific extra rustflags if any otherwise take `rust.rustflags`
let extra_rustflags = self
.config
.target_config
.get(&target)
.map(|t| &t.rustflags)
.unwrap_or(&self.config.rust_rustflags)
.clone();

let release_build = self.config.rust_optimize.is_release() &&
// cargo bench/install do not accept `--release` and miri doesn't want it
!matches!(cmd_kind, Kind::Bench | Kind::Install | Kind::Miri | Kind::MiriSetup | Kind::MiriTest);
Expand All @@ -1394,6 +1409,7 @@ impl Builder<'_> {
allow_features,
release_build,
build_compiler_stage,
extra_rustflags,
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ pub struct Config {
pub rust_std_features: BTreeSet<String>,
pub rust_break_on_ice: bool,
pub rust_parallel_frontend_threads: Option<u32>,
pub rust_rustflags: Vec<String>,

pub llvm_profile_use: Option<String>,
pub llvm_profile_generate: bool,
Expand Down Expand Up @@ -575,6 +576,7 @@ impl Config {
bootstrap_override_lld_legacy: rust_bootstrap_override_lld_legacy,
std_features: rust_std_features,
break_on_ice: rust_break_on_ice,
rustflags: rust_rustflags,
} = toml.rust.unwrap_or_default();

let Llvm {
Expand Down Expand Up @@ -864,6 +866,7 @@ impl Config {
sanitizers: target_sanitizers,
profiler: target_profiler,
rpath: target_rpath,
rustflags: target_rustflags,
crt_static: target_crt_static,
musl_root: target_musl_root,
musl_libdir: target_musl_libdir,
Expand Down Expand Up @@ -947,6 +950,7 @@ impl Config {
target.sanitizers = target_sanitizers;
target.profiler = target_profiler;
target.rpath = target_rpath;
target.rustflags = target_rustflags.unwrap_or_default();
target.optimized_compiler_builtins = target_optimized_compiler_builtins;
target.jemalloc = target_jemalloc;
if let Some(backends) = target_codegen_backends {
Expand Down Expand Up @@ -1441,6 +1445,7 @@ impl Config {
rust_randomize_layout: rust_randomize_layout.unwrap_or(false),
rust_remap_debuginfo: rust_remap_debuginfo.unwrap_or(false),
rust_rpath: rust_rpath.unwrap_or(true),
rust_rustflags: rust_rustflags.unwrap_or_default(),
rust_stack_protector,
rust_std_features: rust_std_features
.unwrap_or(BTreeSet::from([String::from("panic-unwind")])),
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/src/core/config/toml/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ define_config! {
channel: Option<String> = "channel",
musl_root: Option<String> = "musl-root",
rpath: Option<bool> = "rpath",
rustflags: Option<Vec<String>> = "rustflags",
strip: Option<bool> = "strip",
frame_pointers: Option<bool> = "frame-pointers",
stack_protector: Option<String> = "stack-protector",
Expand Down Expand Up @@ -375,6 +376,7 @@ pub fn check_incompatible_options_for_ci_rustc(
parallel_frontend_threads: _,
bootstrap_override_lld: _,
bootstrap_override_lld_legacy: _,
rustflags: _,
} = ci_rust_config;

// There are two kinds of checks for CI rustc incompatible options:
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/src/core/config/toml/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ define_config! {
sanitizers: Option<bool> = "sanitizers",
profiler: Option<StringOrBool> = "profiler",
rpath: Option<bool> = "rpath",
rustflags: Option<Vec<String>> = "rustflags",
crt_static: Option<bool> = "crt-static",
musl_root: Option<String> = "musl-root",
musl_libdir: Option<String> = "musl-libdir",
Expand Down Expand Up @@ -70,6 +71,7 @@ pub struct Target {
pub sanitizers: Option<bool>,
pub profiler: Option<StringOrBool>,
pub rpath: Option<bool>,
pub rustflags: Vec<String>,
pub crt_static: Option<bool>,
pub musl_root: Option<PathBuf>,
pub musl_libdir: Option<PathBuf>,
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/utils/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Info,
summary: "The `-Zannotate-moves` option is now always enabled when building rustc, sysroot and tools.",
},
ChangeInfo {
change_id: 148795,
severity: ChangeSeverity::Info,
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.",
},
];
Loading