cross: Build fails with `sh: 1: cargo: not found`
Maintainer’s Note: This has become a meta-issue of multiple bugs all causing the host toolchain to not be mounted in the container, and includes:
- Docker in Docker (#387)
- Nix Store (#524)
- Remote Docker support (#273, #785)
- WSL2
- WSL2 Docker-in-Docker (#728)
- Running cross in parallel (#496)
- Docker-in-Docker Fails to mount host dirs (#1283)
The build fails on a Docker container with sh: 1: cargo: not found
, the Docker container is run with a custom image that contains Docker with a wrapper to have DinD working, and Rust nightly docker run -it -v
pwd:/var/tmp -v /var/run/docker.sock:/var/run/docker.sock kariae/docker-rust-nightly sh
the command fails with sh: 1: cargo: not found
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 15
- Comments: 62 (17 by maintainers)
Commits related to this issue
- Merge rust-bitcoin/rust-bitcoin#833: Allow contributors to easily run CI locally with `act` 006193f5b65f5455a14c1fb6ffb5384b2c9dcf76 feat: Support running CI locally with `act` (Andrew Ahlers) Pull ... — committed to rust-bitcoin/rust-bitcoin by apoelstra 2 years ago
- Merge #989 989: added default nix_store value r=Alexhuszagh,otavio a=IllustratedMan-code This pull request fixes the nix related issues described in #260. Its super simple, I just made the nix_store... — committed to cross-rs/cross by bors[bot] 2 years ago
The problem is that the image uses the host’s own Rust install, which in some cases (e.g. NixOS) cannot be run on Ubuntu. You can work around it by building an image with its own Rust install, for example:
Rust is installed outside
~
so the user the build runs as can access it. About the last two lines, I wasn’t able to overrideCARGO_HOME
from the shell profile so I overrode the shell instead. Not pretty, but gets the job done.Using something from the host breakes many of the otherwise strong guarantees alike “runs fine with me, will run fine with you” docker has to offer. IMO this should be at least considered to be changed.
I can confirm this issue, it also happens on
armv7-unknown-linux-musleabihf-0.2.0
shouldn’t rust be installed in those container images ? or I misunderstood the way this tool works
@Emilgardis I just took a look at #524 . It seems to rely on a
NIX_STORE
environment variable to determine the location of the nix store. TheNIX_STORE
variable is not set by nix normally as far as I can tell. The default location is/nix/store
so I’ll try setting theNIX_STORE
variable and see if it fixes it.I have the same issue in WSL2 (Ubuntu 20.04) running in Windows 11. Running Docker via Rancher Desktop in Windows and confirmed DinD works with
docker run --rm -i hello-world
.Reproducing it like this:
Start build container that includes Docker
Install Rust and
cross
, create projectTry to build with cross
EDIT: The exact same steps works on Windows 11 and Manjaro 21.2.6 with Linux 5.17.
+1 on current NixOS unstable 21.11pre304626.8ecc61c91a5 (Porcupine)
I’m getting this issue as well. What’s the point of the Docker image if the tool isn’t preinstalled? Is this project dead?
For those running
cross
from within a Docker image, see https://github.com/rust-embedded/cross#docker-in-docker.An example of doing this interactively using the official
rust
image:Running cross with the
NIX_STORE
environment variable set to/nix/store
seems to work for me on NixOS.I hit the same issue but with a different root cause. I just want to share some notes that might help to people seeing this problem.
cross
doesn’t include rust/cargo or other tool. These image provides the libraries required for cross-compiling.cross
tool installs the requested toolchain in the system and then when docker is run some volumes are mounted to make rust visible inside the container.cargo: not found
error is because some of these volume mounts is not working correctly.Adding the
--verbose
flag to thecross build
command helps to get the docker command used to launch the container. Try to run the same command from your terminal and start checking which of the volumes is failing.Just created a pull request that should fix the NIX_STORE problem.
Yes please do!
Some more context to the WSL issue without really having a solution.
I had a look at the code for when
cross
starts a docker container and if you useDOCKER_IN_DOCKER=true
it inspects the current container (docker inspect $HOSTNAME
) to determine the volumes and tries to mount them, something like/var/lib/docker/overlay2/xxx/merged/root/.cargo:/cargo:Z
. This is needed since afaik you won’t be able to mount volumes from Docker to Docker but instead have to reference the host machine/volume (ref).However, when running Rancher Desktop (and I think Docker Desktop as well?) in combination with WSL, it sets up two different distros to host Docker:
The container data volume does not exist in
Ubuntu
orrancher-desktop
, however it exists inrancher-desktop-data
. This means that if I look at the output fordocker inspect $HOSTNAME
and.[0].GraphDriver.Data
, it will refer to paths which does not exist and is not accessible in the current container that tries to runcross
.I usually don’t use Windows or WSL so I need to read up more on how volume mounts + Windows + WSL + Docker in Docker works but right now it looks as simple as that the
cross
container that gets launched from the Docker container running in WSL basically can’t mount any toolchain successfully which also explains whycargo
is not found.This feels like a very WSL specific issue so let me know if you want me to open a new issue to track this.
@IllustratedMan-code good that it worked for you, but that solution is not how cross is supposed to work (as I alluded to here and mentioned here), cross is supposed to mount your system sysroot for x86_64-unknown-linux-gnu into
/
For nix specifically, the issue should have been fixed with #524
We have to continue and look into this, but its hard when we’re not able to reproduce the issue
this solution worked
As am i, also NixOS 20.09:
@andresv
rustembedded/cross:aarch64-unknown-linux-musl
doesn’t contain across
executable, only the corresponding cross toolchain. You already installedcross
in yourcimg/rust:1.47.0
container, so just replace the wholedocker run...
command withcross build --target aarch64-unknown-linux-musl
.I had still to make some workaround for using
cross
in gitlab-ci even when using the master branch. But I managed to do it, you can find information in this comment: https://github.com/rust-embedded/cross/issues/273#issuecomment-528300479This probably does not apply for nixOS users. But for the OP surely 😃
I am also encountering this issue. Nothing special about my setup, though.
Using NixOS 19.03 on 4.19.24 Docker: 18.09.2 Cross: 0.1.14 cargo 1.34.0-nightly (5c6aa46e6 2019-02-22)