cross-rs / cross

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

Remote docker throws "sh: 1: cargo: not found" error if cargo comes from nix distribution #1383

Open david9991 opened 8 months ago

david9991 commented 8 months ago

Checklist

Describe your issue

When executing the command DOCKER_HOST=... CROSS_REMOTE=1 ~/.cargo/bin/cross --verbose build --target arm-unknown-linux-gnueabi, I encountered the error sh: 1: cargo: not found.

With verbose output enabled, I discovered that the following command was executed:

/home/gitlab-workspaces/.nix-profile/bin/docker exec cross-stable-x86_64-unknown-linux-gnu-ae81e-79e9716c9-arm-unknown-linux-gnueabi-plcc-blockchain-tools-c1946 sh -c 'mkdir -p '\''/cross/cargo'\'''
/home/gitlab-workspaces/.nix-profile/bin/docker cp -a /home/gitlab-workspaces/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin cross-stable-x86_64-unknown-linux-gnu-ae81e-79e9716c9-arm-unknown-linux-gnueabi-plcc-blockchain-tools-c1946:/cross/rust

The second command copies the /home/gitlab-workspaces/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin directory as /cross/rust instead of copying the folder to /cross/rust/ if the /cross/rust directory does not exist. (Only 'cross/cargo' was created in the previous command)

This behavior will cause the subsequent command:

/home/gitlab-workspaces/.nix-profile/bin/docker exec --user 5001:5001 -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 BROWSER -e 'USER=gitlab-workspaces' -w /project cross-stable-x86_64-unknown-linux-gnu-ae81e-79e9716c9-arm-unknown-linux-gnueabi-plcc-blockchain-tools-c1946 sh -c 'PATH=$PATH:/rust/bin cargo --verbose build --target arm-unknown-linux-gnueabi --target-dir /cross/project/target`

which attempt to use the cargo executable from the /rust/bin folder to fail.

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

No response

Additional information / notes

No response

Emilgardis commented 8 months ago

I'm not sure if there was a specific fix for this done, but can you try cross installed from the main branch?

This shouldn't happen, as we create the directories here

david9991 commented 8 months ago

@Emilgardis You're right. It's a Nix related issue. the cargo was patched by Nix, so the error message isn't about the cargo itself, but its elf interpreter cannot be found in the container. It can be worked around by setting the interpreter back to /lib64/ld-linux-x86-64.so.2 before being copied from Nix environment.