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

bootstrap: support target specific config overrides #125515

Merged
merged 2 commits into from
May 25, 2024
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
23 changes: 18 additions & 5 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ pub enum RustfmtState {
LazyEvaluated,
}

#[derive(Debug, Default, Clone, Copy, PartialEq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum LlvmLibunwind {
#[default]
No,
Expand All @@ -381,7 +381,7 @@ impl FromStr for LlvmLibunwind {
}
}

#[derive(Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum SplitDebuginfo {
Packed,
Unpacked,
Expand Down Expand Up @@ -542,7 +542,7 @@ impl PartialEq<&str> for TargetSelection {
}

/// Per-target configuration stored in the global configuration structure.
#[derive(Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct Target {
/// Some(path to llvm-config) if using an external LLVM.
pub llvm_config: Option<PathBuf>,
Expand Down Expand Up @@ -644,7 +644,20 @@ impl Merge for TomlConfig {
do_merge(&mut self.llvm, llvm, replace);
do_merge(&mut self.rust, rust, replace);
do_merge(&mut self.dist, dist, replace);
assert!(target.is_none(), "merging target-specific config is not currently supported");

match (self.target.as_mut(), target) {
(_, None) => {}
(None, Some(target)) => self.target = Some(target),
(Some(original_target), Some(new_target)) => {
for (triple, new) in new_target {
if let Some(original) = original_target.get_mut(&triple) {
original.merge(new, replace);
} else {
original_target.insert(triple, new);
}
}
}
}
}
}

Expand Down Expand Up @@ -899,7 +912,7 @@ define_config! {
}
}

#[derive(Clone, Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum StringOrBool {
String(String),
Expand Down
41 changes: 41 additions & 0 deletions src/bootstrap/src/core/config/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::{flags::Flags, ChangeIdWrapper, Config};
use crate::core::build_steps::clippy::get_clippy_rules_in_order;
use crate::core::config::Target;
use crate::core::config::TargetSelection;
use crate::core::config::{LldMode, TomlConfig};

use clap::CommandFactory;
Expand Down Expand Up @@ -124,6 +126,10 @@ fn override_toml() {
"--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(),
],
|&_| {
toml::from_str(
Expand All @@ -140,6 +146,17 @@ tools = []
[llvm]
download-ci-llvm = false
build-config = {}

[target.aarch64-unknown-linux-gnu]
sanitizers = true
rpath = true
runner = "aarch64-runner"

[target.x86_64-unknown-linux-gnu]
sanitizers = true
rpath = true
runner = "x86_64-runner"

"#,
)
.unwrap()
Expand All @@ -163,6 +180,30 @@ build-config = {}
[("foo".to_string(), "bar".to_string())].into_iter().collect(),
"setting dictionary value"
);

let x86_64 = TargetSelection::from_user("x86_64-unknown-linux-gnu");
let x86_64_values = Target {
sanitizers: Some(true),
rpath: Some(false),
runner: Some("bar".into()),
..Default::default()
};
let aarch64 = TargetSelection::from_user("aarch64-unknown-linux-gnu");
let aarch64_values = Target {
sanitizers: Some(false),
rpath: Some(true),
runner: Some("aarch64-runner".into()),
..Default::default()
};
let darwin = TargetSelection::from_user("aarch64-apple-darwin");
let darwin_values = Target { runner: Some("apple".into()), ..Default::default() };
assert_eq!(
config.target_config,
[(x86_64, x86_64_values), (aarch64, aarch64_values), (darwin, darwin_values)]
.into_iter()
.collect(),
"setting dictionary value"
);
}

#[test]
Expand Down
Loading