From c84fce26b26b3c77f53bd582df38371bda228c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Thu, 24 Mar 2022 19:23:50 +0100 Subject: [PATCH] rename option to `default-target` also document the option --- CHANGELOG.md | 1 + docs/cross_toml.md | 1 + src/config.rs | 6 ++++-- src/cross_toml.rs | 12 ++++++++---- src/main.rs | 2 +- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eb0c7b08..b82c918d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +- #624 - Add `build.default-target` - #670 - Use serde for deserialization of Cross.toml - Change rust edition to 2021 and bump MSRV for the cross binary to 1.58.1 - #654 - Use color-eyre for error reporting diff --git a/docs/cross_toml.md b/docs/cross_toml.md index 95f1306c4..32e0a39dc 100644 --- a/docs/cross_toml.md +++ b/docs/cross_toml.md @@ -6,6 +6,7 @@ The `build` key allows you to set global variables, e.g.: ```toml [build] xargo = true +default-target = "x86_64-unknown-linux-gnu" ``` # `build.env` diff --git a/src/config.rs b/src/config.rs index 352e8ff98..5b4a22c29 100644 --- a/src/config.rs +++ b/src/config.rs @@ -189,7 +189,9 @@ impl Config { if let Some(env_value) = self.env.target() { return Some(Target::from(&env_value, target_list)); } - self.toml.as_ref().map_or(None, |t| t.target(target_list)) + self.toml + .as_ref() + .and_then(|t| t.default_target(target_list)) } fn sum_of_env_toml_values( @@ -424,7 +426,7 @@ mod tests { static TOML_DEFAULT_TARGET: &str = r#" [build] - target = "aarch64-unknown-linux-gnu" + default-target = "aarch64-unknown-linux-gnu" "#; } } diff --git a/src/cross_toml.rs b/src/cross_toml.rs index b2efa1b07..2a571f175 100644 --- a/src/cross_toml.rs +++ b/src/cross_toml.rs @@ -16,10 +16,11 @@ pub struct CrossBuildEnvConfig { /// Build configuration #[derive(Debug, Deserialize, PartialEq, Default)] +#[serde(rename_all = "kebab-case")] pub struct CrossBuildConfig { env: Option, xargo: Option, - target: Option, + default_target: Option, } /// Target configuration @@ -92,8 +93,11 @@ impl CrossToml { } /// Returns the default target to build, - pub fn target(&self, target_list: &TargetList) -> Option { - self.build.as_ref().and_then(|b| b.target.as_ref()).map(|t| Target::from(t, target_list)) + pub fn default_target(&self, target_list: &TargetList) -> Option { + self.build + .as_ref() + .and_then(|b| b.default_target.as_ref()) + .map(|t| Target::from(t, target_list)) } /// Returns a reference to the [`CrossTargetConfig`] of a specific `target` @@ -134,7 +138,7 @@ mod tests { passthrough: vec!["VAR1".to_string(), "VAR2".to_string()], }), xargo: Some(true), - target: None, + default_target: None, }), }; diff --git a/src/main.rs b/src/main.rs index 228ebe2fa..eb7ad5943 100644 --- a/src/main.rs +++ b/src/main.rs @@ -274,7 +274,7 @@ fn run() -> Result { let config = Config::new(toml); let target = args .target - .or(config.target(&target_list)) + .or_else(|| config.target(&target_list)) .unwrap_or_else(|| Target::from(host.triple(), &target_list)); if host.is_supported(Some(&target)) {