-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Problem
Cargo in WSL uses the windows host cargo config in %UserProfile%/.cargo/config.toml
, and it looks like values there are preferred over the WSL ~/.cargo/config.toml
.
When there is either rustc-wrapper
or target-dir
configured, cargo in WSL fails because it does not have access to those paths.
edit: The project I am trying to compile is in a folder symlinked to /c/Users/<user>/projects
. It looks like cargo unwraps the symlink, then it's pretty clear why it finds the windows config first. But I am not sure this behavior is preferrable.
/edit
I have a ~/.cargo/config.toml
in WSL with the following content:
[build]
rustc-wrapper = "/home/<user>/.cargo/bin/sccache"
target-dir = "/home/<user>/.cargo/targets"
But cargo prefers the host values.
Error when rustc-wrapper
is set on windows:
error: failed to run `rustc` to learn about target-specific information
Caused by:
could not execute process `/mnt/c/Users/<user>/C:/Users/<user>/.cargo/bin/sccache.exe rustc - --crate-name ___ --print=file-names --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (never executed)
Caused by:
No such file or directory (os error 2)
Error when target-dir
is set on windows:
error: failed to join paths from `$LD_LIBRARY_PATH` together
Check if any of path segments listed below contain an unterminated quote character or path separator:
"/mnt/c/Users/<user>/C:/Users/<user>/.cargo/targets/debug/deps"
"/home/<user>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib"
"/home/<user>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib"
Caused by:
path segment contains separator `:`
which { rustup cargo rustc }
shows WSL binaries, so there is no issue with accidentally invoking host binaries.
When I delete the contents of the windows cargo.toml
, the WSL config is applied correctly.
Steps
- Set up WSL
- Install cargo/rust in windows host and in WSL
- Set up a cargo project in
%UserProfile%/projects/<name>
- Create a
config.toml
in%UserProfile%/.cargo
with eitherrustc-wrapper
ortarget-dir
- In WSL: Create a symlink in
~/
to/mnt/c/Users/<user>/projects
- In WSL:
cargo run
in~/projects/<name>
Possible Solution(s)
Change cargo so it doesn't "unwrap" symlinks when looking for configs.
If pwd
prints ~/projects/
, cargo should not behave like it's in /mnt/c/Users/<user>/projects
.
Notes
wsl -v -l
WSL version: 1.0.3.0
Kernel version: 5.15.79.1
WSLg version: 1.0.47
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.1105
Version
cargo 1.67.0 (8ecd4f20a 2023-01-10)
release: 1.67.0
commit-hash: 8ecd4f20a9efb626975ac18a016d480dc7183d9b
commit-date: 2023-01-10
host: x86_64-unknown-linux-gnu
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.86.0-DEV (sys:0.4.59+curl-7.86.0 vendored ssl:OpenSSL/1.1.1q)
os: Ubuntu 22.04 (jammy) [64-bit]