Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support target specific optimized-compiler-builtins #135326

Merged
merged 5 commits into from
Jan 11, 2025
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
9 changes: 9 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,15 @@
# argument as the test binary.
#runner = <none> (string)

# Use the optimized LLVM C intrinsics for `compiler_builtins`, rather than Rust intrinsics
# on this target.
# Requires the LLVM submodule to be managed by bootstrap (i.e. not external) so that `compiler-rt`
# sources are available.
#
# Setting this to `false` generates slower code, but removes the requirement for a C toolchain in
# order to run `x check`.
#optimized-compiler-builtins = build.optimized-compiler-builtins (bool)

# =============================================================================
# Distribution options
#
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
// If `compiler-rt` is available ensure that the `c` feature of the
// `compiler-builtins` crate is enabled and it's configured to learn where
// `compiler-rt` is located.
let compiler_builtins_c_feature = if builder.config.optimized_compiler_builtins {
let compiler_builtins_c_feature = if builder.config.optimized_compiler_builtins(target) {
// NOTE: this interacts strangely with `llvm-has-rust-patches`. In that case, we enforce `submodules = false`, so this is a no-op.
// But, the user could still decide to manually use an in-tree submodule.
//
Expand Down
13 changes: 13 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ pub struct Target {
pub runner: Option<String>,
pub no_std: bool,
pub codegen_backends: Option<Vec<String>>,
pub optimized_compiler_builtins: Option<bool>,
}

impl Target {
Expand Down Expand Up @@ -1219,6 +1220,7 @@ define_config! {
no_std: Option<bool> = "no-std",
codegen_backends: Option<Vec<String>> = "codegen-backends",
runner: Option<String> = "runner",
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
}
}

Expand Down Expand Up @@ -2096,6 +2098,7 @@ impl Config {
target.sanitizers = cfg.sanitizers;
target.profiler = cfg.profiler;
target.rpath = cfg.rpath;
target.optimized_compiler_builtins = cfg.optimized_compiler_builtins;

if let Some(ref backends) = cfg.codegen_backends {
let available_backends = ["llvm", "cranelift", "gcc"];
Expand Down Expand Up @@ -2609,6 +2612,13 @@ impl Config {
self.target_config.get(&target).and_then(|t| t.rpath).unwrap_or(self.rust_rpath)
}

pub fn optimized_compiler_builtins(&self, target: TargetSelection) -> bool {
self.target_config
.get(&target)
.and_then(|t| t.optimized_compiler_builtins)
.unwrap_or(self.optimized_compiler_builtins)
}

pub fn llvm_enabled(&self, target: TargetSelection) -> bool {
self.codegen_backends(target).contains(&"llvm".to_owned())
}
Expand Down Expand Up @@ -3162,6 +3172,9 @@ fn check_incompatible_options_for_ci_rustc(

let profiler = &ci_cfg.profiler;
err!(current_cfg.profiler, profiler, "build");

let optimized_compiler_builtins = &ci_cfg.optimized_compiler_builtins;
err!(current_cfg.optimized_compiler_builtins, optimized_compiler_builtins, "build");
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/bootstrap/src/core/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ fn override_toml() {
"--set=change-id=1".to_owned(),
"--set=rust.lto=fat".to_owned(),
"--set=rust.deny-warnings=false".to_owned(),
"--set=build.optimized-compiler-builtins=true".to_owned(),
"--set=build.gdb=\"bar\"".to_owned(),
"--set=build.tools=[\"cargo\"]".to_owned(),
"--set=llvm.build-config={\"foo\" = \"bar\"}".to_owned(),
"--set=target.x86_64-unknown-linux-gnu.runner=bar".to_owned(),
"--set=target.x86_64-unknown-linux-gnu.rpath=false".to_owned(),
"--set=target.aarch64-unknown-linux-gnu.sanitizers=false".to_owned(),
"--set=target.aarch64-apple-darwin.runner=apple".to_owned(),
"--set=target.aarch64-apple-darwin.optimized-compiler-builtins=false".to_owned(),
]),
|&_| {
toml::from_str(
Expand Down Expand Up @@ -167,6 +169,7 @@ runner = "x86_64-runner"
);
assert_eq!(config.gdb, Some("bar".into()), "setting string value with quotes");
assert!(!config.deny_warnings, "setting boolean value");
assert!(config.optimized_compiler_builtins, "setting boolean value");
assert_eq!(
config.tools,
Some(["cargo".to_string()].into_iter().collect()),
Expand All @@ -193,7 +196,11 @@ runner = "x86_64-runner"
..Default::default()
};
let darwin = TargetSelection::from_user("aarch64-apple-darwin");
let darwin_values = Target { runner: Some("apple".into()), ..Default::default() };
let darwin_values = Target {
runner: Some("apple".into()),
optimized_compiler_builtins: Some(false),
..Default::default()
};
assert_eq!(
config.target_config,
[(x86_64, x86_64_values), (aarch64, aarch64_values), (darwin, darwin_values)]
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 @@ -325,4 +325,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Warning,
summary: "Removed `rust.parallel-compiler` as it was deprecated in #132282 long time ago.",
},
ChangeInfo {
change_id: 135326,
severity: ChangeSeverity::Warning,
summary: "It is now possible to configure `optimized-compiler-builtins` for per target.",
},
];
Loading