-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add various support for cargo configuration.
Also adds support for parsing and reading configuration options/environment variables from cargo, and allows users to ignore config files in the package. This adds the `[build.env.cargo-config]` option, which can be set to `complete`, `ignore`, or `default`. If set to `complete`, cross will have access to every to every cargo config file on the host (if using remote cross, a config file is written to a temporary file which is mounted on the data volume at `/.cargo/config.toml`). If set to ignore, any `.cargo/config.toml` files outside of `CARGO_HOME` are ignored, by mounting anonymous data volumes to hide config files in any `.cargo` directories. The default behavior uses the backwards-compatible behavior, allowing cross to access any config files in the package and `CARGO_HOME` directories. If the build is called outside the workspace root or at the workspace root, then we only mount an anonymous volume at `$PWD/.cargo`. The alias support includes recursive subcommand detection, and errors before it invokes cargo. A sample error message is `[cross] error: alias y has unresolvable recursive definition: x -> y -> z -> a -> y`, and therefore can handle non-trivial recursive subcommands.
- Loading branch information
1 parent
bcbc012
commit 08fbafa
Showing
18 changed files
with
1,762 additions
and
1,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
{ | ||
"description": "deny installation of debian packages that conflict with our cross-compiler toolchains.", | ||
"type": "fixed" | ||
} | ||
[ | ||
{ | ||
"description": "add support for cargo aliases.", | ||
"type": "added", | ||
"issues": [562] | ||
}, | ||
{ | ||
"description": "allow users to ignore config files in the package.", | ||
"type": "added", | ||
"issues": [621] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"description": "deny installation of debian packages that conflict with our cross-compiler toolchains.", | ||
"type": "fixed" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::collections::HashMap; | ||
|
||
use crate::cargo_toml::CargoToml; | ||
use crate::config::{split_to_cloned_by_ws, Environment}; | ||
use crate::errors::*; | ||
|
||
pub const CARGO_NO_PREFIX_ENVVARS: &[&str] = &[ | ||
"http_proxy", | ||
"TERM", | ||
"RUSTDOCFLAGS", | ||
"RUSTFLAGS", | ||
"BROWSER", | ||
"HTTPS_PROXY", | ||
"HTTP_TIMEOUT", | ||
"https_proxy", | ||
]; | ||
|
||
#[derive(Debug)] | ||
struct CargoEnvironment(Environment); | ||
|
||
impl CargoEnvironment { | ||
fn new(map: Option<HashMap<&'static str, &'static str>>) -> Self { | ||
CargoEnvironment(Environment::new("CARGO", map)) | ||
} | ||
|
||
pub fn alias(&self, name: &str) -> Option<Vec<String>> { | ||
let key = format!("ALIAS_{name}"); | ||
self.0 | ||
.get_var(&self.0.var_name(&key)) | ||
.map(|x| split_to_cloned_by_ws(&x)) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct CargoConfig { | ||
toml: Option<CargoToml>, | ||
env: CargoEnvironment, | ||
} | ||
|
||
impl CargoConfig { | ||
pub fn new(toml: Option<CargoToml>) -> Self { | ||
CargoConfig { | ||
toml, | ||
env: CargoEnvironment::new(None), | ||
} | ||
} | ||
|
||
pub fn alias(&self, name: &str) -> Result<Option<Vec<String>>> { | ||
match self.env.alias(name) { | ||
Some(alias) => Ok(Some(alias)), | ||
None => match self.toml.as_ref() { | ||
Some(t) => t.alias(name), | ||
None => Ok(None), | ||
}, | ||
} | ||
} | ||
|
||
pub fn to_toml(&self) -> Result<Option<String>> { | ||
match self.toml.as_ref() { | ||
Some(t) => Ok(Some(t.to_toml()?)), | ||
None => Ok(None), | ||
} | ||
} | ||
} |
Oops, something went wrong.