cross-rs / cross

“Zero setup” cross compilation and “cross testing” of Rust crates
Apache License 2.0
6.73k stars 375 forks source link

`CROSS_CONTAINER_OPTS` is also used for `docker exec` when using `CROSS_REMOTE` #1301

Open tyilo opened 1 year ago

tyilo commented 1 year ago

Checklist

Describe your issue

According to the wiki CROSS_CONTAINER_OPTS should only be added $engine run commands:

However when using CROSS_REMOTE the options are also added to a $engine exec command.

This is problematic when the options only can be used with $engine run. For instance I would like to use docker run --net=host when building.

Possible solutions:

  1. CROSS_CONTAINER_OPTS should only apply to $engine run commands as currently documented in the wiki.
  2. CROSS_CONTAINER_OPTS should apply to both $engine run and $engine exec. The wiki should be updated to reflect this. Furthermore a CROSS_CONTAINER_RUN_OPTS environment variable should be supported that only gets passed to $engine run.

What target(s) are you cross-compiling for?

No response

Which operating system is the host (e.g computer cross is on) running?

What architecture is the host?

What container engine is cross using?

cross version

cross 0.2.5

Example

$ docker run -v /var/run/docker.sock:/var/run/docker.sock --rm -it rust:1.71.0
# apt-get update
# apt-get install -y docker.io
# cargo install cross
# cargo new hello-world
# cd hello-world
# CROSS_REMOTE=1 CROSS_CONTAINER_OPTS="--net=host" cross --verbose build --target x86_64-unknown-linux-gnu
+ cargo metadata --format-version 1 --filter-platform x86_64-unknown-linux-gnu
+ rustc --print sysroot
+ rustup toolchain list
+ rustup target list --toolchain 1.71.0-x86_64-unknown-linux-gnu
+ rustup component list --toolchain 1.71.0-x86_64-unknown-linux-gnu
+ rustup --verbose component add rust-src --toolchain 1.71.0-x86_64-unknown-linux-gnu
verbose: read metadata version: '12'
info: downloading component 'rust-src'
verbose: downloading file from: 'https://static.rust-lang.org/dist/2023-07-13/rust-src-1.71.0.tar.xz'
verbose: downloading with reqwest
verbose: checksum passed
info: installing component 'rust-src'
verbose: creating temp directory: /usr/local/rustup/tmp/tqr4atokf5zp5xd6_dir
verbose: creating temp file: /usr/local/rustup/tmp/mau15vxbr7jwiw53_file
verbose: creating temp file: /usr/local/rustup/tmp/ue4512m70ntmoo28_file
verbose: deleted temp directory: /usr/local/rustup/tmp/tqr4atokf5zp5xd6_dir
verbose: creating temp file: /usr/local/rustup/tmp/vlelm8n4yw84szpz_file
verbose: creating temp file: /usr/local/rustup/tmp/u9vmt5hs9dyhe6j__file
verbose: deleted temp file: /usr/local/rustup/tmp/mau15vxbr7jwiw53_file
verbose: deleted temp file: /usr/local/rustup/tmp/ue4512m70ntmoo28_file
verbose: deleted temp file: /usr/local/rustup/tmp/vlelm8n4yw84szpz_file
verbose: deleted temp file: /usr/local/rustup/tmp/u9vmt5hs9dyhe6j__file
+ /usr/bin/docker
+ /usr/bin/docker volume inspect cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2
+ /usr/bin/docker ps -a --filter 'name=cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3' --format {{.State}}
+ /usr/bin/docker run --userns host --name cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3 --rm -v /cross -v /cross/cargo/bin -d -t ghcr.io/cross-rs/x86_64-unknown-linux-gnu:0.2.5
Unable to find image 'ghcr.io/cross-rs/x86_64-unknown-linux-gnu:0.2.5' locally
0.2.5: Pulling from cross-rs/x86_64-unknown-linux-gnu
58690f9b18fc: Pull complete 
b51569e7c507: Pull complete 
da8ef40b9eca: Pull complete 
fb15d46c38dc: Pull complete 
7cd0932c59ac: Pull complete 
b8099f45b9a5: Pull complete 
640227c3e7fb: Pull complete 
feac1a957a2e: Pull complete 
2bb7cc963f55: Pull complete 
69f3cca19ad2: Pull complete 
9eae8e6ab0e2: Pull complete 
f6948013d489: Pull complete 
e63c3aabe8fe: Pull complete 
f3f8758fddaa: Pull complete 
e8df8713a13e: Pull complete 
840b2ff81099: Pull complete 
e52d8b455ef1: Pull complete 
Digest: sha256:9e5b39c09874bc1816c675ed11afca2c2ed6cee0c4ed2b3c1d5763c346c9ae3f
Status: Downloaded newer image for ghcr.io/cross-rs/x86_64-unknown-linux-gnu:0.2.5
6dc7015e7128bd2bd1fcfd9c5f4d61e9b7326eacddc4ddcde6505570a11c3b79
+ /usr/bin/docker exec cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3 sh -c 'mkdir -p '\''/cross/cargo'\'''
+ /usr/bin/docker cp -a /usr/local/cargo/bin cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3:/cross/cargo
+ /usr/bin/docker cp -a /usr/local/cargo/env cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3:/cross/cargo
+ /usr/bin/docker exec cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3 sh -c 'mkdir -p '\''/cross/rust/lib/rustlib'\'''
+ /usr/bin/docker cp -a /usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/bin cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3:/cross/rust
+ /usr/bin/docker cp -a /usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/libexec cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3:/cross/rust
+ /usr/bin/docker cp -a /usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/etc cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3:/cross/rust
lstat /usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/etc: no such file or directory
+ /usr/bin/docker cp -a /root/.local/share/cross-rs/tmp/.tmp1769Yj/lib cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3:/cross/rust
+ /usr/bin/docker cp -a /root/.local/share/cross-rs/tmp/.tmpPNauRc/lib cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3:/cross/rust
+ /usr/bin/docker cp -a /usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3:/cross/rust/lib/rustlib
+ /usr/bin/docker cp -a /root/.local/share/cross-rs/tmp/.tmpYZ3vcP cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3:/cross/project
+ /usr/bin/docker exec cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3 sh -c 'set -e pipefail
set -x
chown -R 0:0 /cross
prefix="/cross"

symlink_recurse() {
    for f in "${1}"/*; do
        dst=${f#"$prefix"}
        if [ -f "${dst}" ]; then
            echo "invalid: got unexpected file at ${dst}" 1>&2
            exit 1
        elif [ -d "${dst}" ]; then
            symlink_recurse "${f}"
        else
            ln -s "${f}" "${dst}"
        fi
    done
}

symlink_recurse "${prefix}"
'
+ chown -R 0:0 /cross
+ prefix=/cross
+ symlink_recurse /cross
+ dst=/cargo
+ [ -f /cargo ]
+ [ -d /cargo ]
+ ln -s /cross/cargo /cargo
+ dst=/project
+ [ -f /project ]
+ [ -d /project ]
+ ln -s /cross/project /project
+ dst=/rust
+ [ -f /rust ]
+ [ -d /rust ]
+ ln -s /cross/rust /rust
+ /usr/bin/docker exec --user 0:0 -e 'PKG_CONFIG_ALLOW_CROSS=1' -e 'XARGO_HOME=/xargo' -e 'CARGO_HOME=/cargo' -e 'CARGO_TARGET_DIR=/target' -e 'CROSS_RUNNER=' -e TERM -e 'USER=root' '--net=host' -w /project cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3 sh -c 'PATH=$PATH:/rust/bin cargo --verbose build --target x86_64-unknown-linux-gnu --target-dir /cross/project/target'
unknown flag: --net
See 'docker exec --help'.
+ /usr/bin/docker exec cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3 bash -c '[[ -d '\''/cross/project/target'\'' ]]'
+ /usr/bin/docker stop cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3 --time 2
cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3
+ /usr/bin/docker rm cross-1.71.0-x86_64-unknown-linux-gnu-3625a-8ede3aae2-x86_64-unknown-linux-gnu-hello-world-dd5f3
+ rustup component list --toolchain 1.71.0-x86_64-unknown-linux-gnu

Additional information / notes

No response