Cargo build issues with WSL2


I've upgraded my windows 10 wsl1 to wsl2, and since then I'm not able to use cargo build on any of my projects which I keep on /mnt (i.e. outside of the ubuntu root filesystem).

I'm able to run cargo clean and the rust compiler directly. However cargo build just hangs there with no output, all the while consuming a large amout of cpu.

If anyone had run into this before, how did you fix it. I'm currently running cargo 1.43.

P.S. cargo publish also has the same problem.

Does the problem still happen if you update to the latest stable version of Rust?

Running under the strace command or setting the environment variable CARGO_LOG=debug might help determine what Cargo is doing when the build hangs.

I take that to imply that it does work on filesystems local to the VM?

Cargo takes a lock on the target directory, so I would guess that's hanging on the remote filesystem.

I intend to update soon. I'll check the output of CARGO_LOG, thanks for the suggestion. I had tried strace by there was so much noise.

Yes it works fine on any project local to the vm.

CARGO_LOG=debug output is also noisy.
I compared running it on the ubuntu wsl filesystem. The output is quite similar, several "failed to get mtime of" and "failed to stat". err: failed to read /mnt/d/dev/fl/projs/fltk-rs/target/debug/.fingerprint/fltk-c823771d573c5026/lib-fltk-c823771d573c5026
Caused by:
No such file or directory (os error 2)

But the difference is that it actually finishes.

I think it's related to this issue:

Aggravated by the fact that /mnt/d is a HDD.