Skip to content

Commit

Permalink
rename option to default-target
Browse files Browse the repository at this point in the history
also document the option
  • Loading branch information
Emilgardis committed Mar 24, 2022
1 parent cbb2382 commit 4cb1f3e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/cross_toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 4 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -424,7 +426,7 @@ mod tests {

static TOML_DEFAULT_TARGET: &str = r#"
[build]
target = "aarch64-unknown-linux-gnu"
default-target = "aarch64-unknown-linux-gnu"
"#;
}
}
12 changes: 8 additions & 4 deletions src/cross_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ pub struct CrossBuildEnvConfig {

/// Build configuration
#[derive(Debug, Deserialize, PartialEq, Default)]
#[serde(rename_all = "kebab-case")]
pub struct CrossBuildConfig {
env: Option<CrossBuildEnvConfig>,
xargo: Option<bool>,
target: Option<String>,
default_target: Option<String>,
}

/// Target configuration
Expand Down Expand Up @@ -92,8 +93,11 @@ impl CrossToml {
}

/// Returns the default target to build,
pub fn target(&self, target_list: &TargetList) -> Option<Target> {
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<Target> {
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`
Expand Down Expand Up @@ -134,7 +138,7 @@ mod tests {
passthrough: vec!["VAR1".to_string(), "VAR2".to_string()],
}),
xargo: Some(true),
target: None,
default_target: None,
}),
};

Expand Down

0 comments on commit 4cb1f3e

Please sign in to comment.