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

Pass cargo configuration flags to docker. #869

Merged
merged 1 commit into from
Jun 26, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased] - ReleaseDate

### Changed

- #869 - ensure cargo configuration environment variable flags are passed to the docker container.
Alexhuszagh marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

- #867 - fixed parsing of `build.env,passthrough` config values.
Expand Down
35 changes: 35 additions & 0 deletions src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,40 @@ pub(crate) fn cargo_safe_command(uses_xargo: bool) -> SafeCommand {
}
}

fn add_cargo_configuration_envvars(docker: &mut Command) {
let non_cargo_prefix = &[
"http_proxy",
"TERM",
"RUSTDOCFLAGS",
"RUSTFLAGS",
"BROWSER",
"HTTPS_PROXY",
"HTTP_TIMEOUT",
"https_proxy",
];
let cargo_prefix_skip = &[
"CARGO_HOME",
"CARGO_TARGET_DIR",
"CARGO_BUILD_TARGET_DIR",
"CARGO_BUILD_RUSTC",
"CARGO_BUILD_RUSTC_WRAPPER",
"CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER",
"CARGO_BUILD_RUSTDOC",
];
let is_cargo_passthrough = |key: &str| -> bool {
non_cargo_prefix.contains(&key)
|| key.starts_with("CARGO_") && !cargo_prefix_skip.contains(&key)
};

// also need to accept any additional flags used to configure
// cargo, but only pass what's actually present.
for (key, _) in env::vars() {
if is_cargo_passthrough(&key) {
docker.args(&["-e", &key]);
}
}
}

pub(crate) fn mount(docker: &mut Command, val: &Path, prefix: &str) -> Result<String> {
let host_path = file::canonicalize(val)?;
let mount_path = canonicalize_mount_path(&host_path)?;
Expand Down Expand Up @@ -248,6 +282,7 @@ pub(crate) fn docker_envvars(docker: &mut Command, config: &Config, target: &Tar
.args(&["-e", "CARGO_HOME=/cargo"])
.args(&["-e", "CARGO_TARGET_DIR=/target"])
.args(&["-e", &cross_runner]);
add_cargo_configuration_envvars(docker);

if let Some(username) = id::username().unwrap() {
docker.args(&["-e", &format!("USER={username}")]);
Expand Down