Description
Problem Description:
In the current implementation of DockerCommandExt
(located in src/docker/shared.rs
), the environment variables http_proxy
, https_proxy
, and HTTPS_PROXY
are explicitly passed through to containers via the other
list. However, the uppercase HTTP_PROXY
is missing from this list, leading to inconsistent behavior. This omission prevents users from controlling the passthrough of HTTP_PROXY
when using cross
, even if it is explicitly configured in Cross.toml
.
Furthermore, the hardcoded passthrough logic for these variables takes precedence over the passthrough
field in Cross.toml
. For example, the following configuration fails to override the proxy settings because the code prioritizes its internal list:
In Cross.toml
:
[build.env]
passthrough = [
"HTTP_PROXY=http://172.17.0.1:7897",
"HTTPS_PROXY=http://172.17.0.1:7897",
"http_proxy=http://172.17.0.1:7897",
"https_proxy=http://172.17.0.1:7897",
]
In /etc/environment
:
# other
HTTPS_PROXY=http://127.0.0.1:7897
HTTP_PROXY=http://127.0.0.1:7897
# other
In cross build container, docker inspect <container_id>
:
"Env": [
"HTTPS_PROXY=http://127.0.0.1:7897",
"HTTP_PROXY=http://172.17.0.1:7897",
// other
],
This creates confusion for users who expect the configuration file to take precedence.
Feature Request:
-
Add a Switch for Proxy Variables:
Introduce a configuration option (e.g., inCross.toml
) to enable/disable the passthrough of all four proxy-related environment variables:
http_proxy
,https_proxy
,HTTP_PROXY
, andHTTPS_PROXY
.
This would allow users to explicitly opt-in or opt-out of their propagation to containers. -
Document the Passthrough Logic:
Update the documentation to clearly explain:
• Which environment variables are passed through by default.
• How thepassthrough
field inCross.toml
interacts with the hardcoded list (e.g., whether it appends to or overrides the defaults).
• How to use the new switch to control proxy variable behavior.
Additional Notes:
• Link to code snippet: shared.rs
• Cross Version: 0.2.5
• OS: EndeavourOS
Note:
This issue description was initially generated by an LLM (language model) and subsequently edited by me for accuracy and clarity, as my native English proficiency is limited. The core problem and proposed solution reflect my actual observations and needs while using cross
.
Original Prompt:
我现在发现rust的交叉编译工具cross中的问题, 在源码src/docker/shared.rs下, 有:
fn add_configuration_envvars(&mut self) {
let other = &[
"http_proxy",
"TERM",
"RUSTDOCFLAGS",
"RUSTFLAGS",
"BROWSER",
"HTTPS_PROXY",
"HTTP_TIMEOUT",
"https_proxy",
"QEMU_STRACE",
];
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 cross_prefix_skip = &[
"CROSS_RUNNER",
"CROSS_RUSTC_MAJOR_VERSION",
"CROSS_RUSTC_MINOR_VERSION",
"CROSS_RUSTC_PATCH_VERSION",
];
let is_passthrough = |key: &str| -> bool {
other.contains(&key)
|| key.starts_with("CARGO_") && !cargo_prefix_skip.contains(&key)
|| key.starts_with("CROSS_") && !cross_prefix_skip.contains(&key)
};
// also need to accept any additional flags used to configure
// cargo or cross, but only pass what's actually present.
for (key, _) in env::vars() {
if is_passthrough(&key) {
self.args(["-e", &key]);
}
}
}
可以看到http_proxy
/https_proxy
/HTTPS_PROXY
三个变量会被透传到容器中, 但是HTTP_PROXY
不会被传递, 而且这里的优先级比Cross.toml的配置文件更高:
[build.env]
passthrough = [
"HTTP_PROXY=http://172.17.0.1:7897",
"HTTPS_PROXY=http://172.17.0.1:7897",
"http_proxy=http://172.17.0.1:7897",
"https_proxy=http://172.17.0.1:7897",
]
如上配置不会覆盖这几个代码中写死的变量, 我向在官方issues中提出功能请求:
- 增加控制
http_proxy
/https_proxy
/HTTP_PROXY
/HTTPS_PROXY
四个环境变量是否传递到容器的开关 - 在文档中写明相关环境变量传递的逻辑
用英文编写, 描述详细的问题