Skip to content

Commit

Permalink
bootstrap: test target specific config overrides
Browse files Browse the repository at this point in the history
Debug, PartialEq, and Eq are derived for testing purposes.
  • Loading branch information
weihanglo committed May 24, 2024
1 parent 9185ddb commit d1f0bc7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
8 changes: 4 additions & 4 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 @@ -912,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

0 comments on commit d1f0bc7

Please sign in to comment.