Skip to content
Open
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 @@ -705,6 +705,12 @@
# desired in distributions, for example.
#rust.rpath = true

# Additional flags to pass to `rustc`.
# Passed before everything else (including per target `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 @@ -1005,6 +1011,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`.
# Passed after global `rust.rustflags` but before everything else.
# Applies to all stages.
#
#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
20 changes: 17 additions & 3 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ struct Rustflags(String, TargetSelection);

impl Rustflags {
fn new(target: TargetSelection) -> Rustflags {
let mut ret = Rustflags(String::new(), target);
ret.propagate_cargo_env("RUSTFLAGS");
ret
Rustflags(String::new(), target)
}

/// By default, cargo will pick up on various variables in the environment. However, bootstrap
Expand Down Expand Up @@ -601,6 +599,22 @@ impl Builder<'_> {
}

let mut rustflags = Rustflags::new(target);

for arg in &self.config.rust_rustflags {
rustflags.arg(arg);
}

// target specific rustflags take precedence over general rustflags
if let Some(target_rustflags) =
self.config.target_config.get(&target).map(|t| &t.rustflags[..])
{
for arg in target_rustflags {
rustflags.arg(arg);
}
}

rustflags.propagate_cargo_env("RUSTFLAGS");

if build_compiler_stage != 0 {
if let Ok(s) = env::var("CARGOFLAGS_NOT_BOOTSTRAP") {
cargo.args(s.split_whitespace());
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 @@ -224,6 +224,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 @@ -571,6 +572,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 @@ -854,6 +856,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 @@ -937,6 +940,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 @@ -1431,6 +1435,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 @@ -373,6 +374,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 @@ -581,4 +581,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Info,
summary: "The `build.python` option is now respected on macOS (previously ignored and forced to be /usr/bin/python3).",
},
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 (are passed after) global `rust.rustflags` ones.",
},
];
Loading