Cargo can't find Rustc in custom install

I'm working on a custom install of Rust, which I need for some reason.
When cargo is in /some/custom/dir/bin/cargo and rustc is in /some/other/dir/bin/rustc, and both are in $PATH and also symbolically linked in /usr/bin (and /usr/bin is also in the $PATH), here is what I get:

  • cargo -V works as expected
  • rustc -vV works as expected

cargo build fails very early with:

   0.005687684s DEBUG main:exec:compile_ws:create_bcx:new:new{path="rustc" wrapper=None workspace_wrapper=None rustup_rustc="/home/me/.cargo/bin/rustc" cache_location=Some("/src/target/.rustc_info.json")}: cargo::util::rustc: failed to read rustc info cache: failed to read `/src/target/.rustc_info.json`
   0.005709197s DEBUG main:exec:compile_ws:create_bcx:new:new{path="rustc" wrapper=None workspace_wrapper=None rustup_rustc="/home/me/.cargo/bin/rustc" cache_location=Some("/src/target/.rustc_info.json")}: cargo::util::rustc: rustc info cache miss
   0.005716204s DEBUG main:exec:compile_ws:create_bcx:new:new{path="rustc" wrapper=None workspace_wrapper=None rustup_rustc="/home/me/.cargo/bin/rustc" cache_location=Some("/src/target/.rustc_info.json")}: cargo::util::rustc: running `rustc -vV`
   0.005862119s DEBUG cargo: exit_with_error; err=CliError { error: Some(could not execute process `rustc -vV` (never executed)

Caused by:
    No such file or directory (os error 2)), exit_code: 101 }
   0.005878424s DEBUG cargo: display_error; err=could not execute process `rustc -vV` (never executed)

Caused by:
    No such file or directory (os error 2)
error: could not execute process `rustc -vV` (never executed)

Caused by:
  No such file or directory (os error 2)

Setting $RUSTC to any other value, absolute or relative, results in the exact same error (with the value of $RUSTC instead of rustc).

I initially thought this was a dynamic linking error, but statically-linked binaries do the exact same thing.

I am now out of ideas, it seems I may not understand how cargo_util::ProcessBuilder works. I'm even starting to doubt my understanding of std::process::Command :zany_face:

Btw, this is Rust 1.84 as packaged by Ubuntu.

Answering my own question, I was ignoring some seemingly unrelated lines in the strace about /dev/null not being found by statx. As I was in a chroot, this makes sense.

Now that makes me wonder why std::process::Command wants /dev/null to exist. A question for another day.

/dev/null is used as stdio if it isn't connected to anything else. Programs tend to misbehave when their stdio is closed as the first open they will do will then be used as new stdio due to open always choosing the lowest available fd, even if the fd is less than 3. Rust programs also open /dev/null as their stdio at startup if it is closed to prevent this kind of issue by the way.

1 Like