Remote docker throws "sh: 1: cargo: not found" error if cargo comes from nix distribution
david9991 opened this issue · 2 comments
Checklist
- I've looked through the issues and pull requests for similar reports
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?
- macOS
- Windows
- Linux / BSD
- other OS (specify in description)
What architecture is the host?
- x86_64 / AMD64
- arm32
- arm64 (including Mac M1)
What container engine is cross using?
- docker
- podman
- other container engine (specify in description)
cross version
cross 0.2.5
Example
No response
Additional information / notes
No response
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
@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.