cargo
cargo copied to clipboard
"error: path too long" on Windows when doing "cargo install --git"
Problem
When attempting to install a crate via git, the checkout process gets to 48% and then errors out with "error: path too long".
Steps
- Run Windows
- Run
cargo install --git https://github.com/web-infra-dev/rspack
Possible Solution(s)
No response
Notes
This repo probably doesn't even work, especially since I don't see a binary if I manually check it out and try to build it. However I'm opening this issue because it's very reproducible and the error is generated very early on.
Version
cargo 1.74.0 (ecb9851af 2023-10-18)
release: 1.74.0
commit-hash: ecb9851afd3095e988daaa35a48bc7f3cb748e04
commit-date: 2023-10-18
host: x86_64-pc-windows-msvc
libgit2: 1.7.1 (sys:0.18.0 vendored)
libcurl: 8.4.0-DEV (sys:0.4.68+curl-8.4.0 vendored ssl:Schannel)
os: Windows 10.0.22621 (Windows 11 Professional) [64-bit]
Also tested on:
cargo 1.75.0-nightly (8eb8acbb1 2023-10-17)
release: 1.75.0-nightly
commit-hash: 8eb8acbb116e7923ea2ce33a50109933ed5ab375
commit-date: 2023-10-17
host: x86_64-pc-windows-msvc
libgit2: 1.7.1 (sys:0.18.1 vendored)
libcurl: 8.4.0-DEV (sys:0.4.68+curl-8.4.0 vendored ssl:Schannel)
os: Windows 10.0.22621 (Windows 11 Professional) [64-bit]
Can you paste the full error output? Feel free to censor paths if you'd prefer.
Sure, here you go.
Install in progress:
[9:58:46 pm] ~> cargo +nightly install --git https://github.com/web-infra-dev/rspack
Updating git repository `https://github.com/web-infra-dev/rspack`
Checkout [=====> ] 26.55%
After it reaches around 48%:
[9:58:18 pm] ~> cargo +nightly install --git https://github.com/web-infra-dev/rspack
Updating git repository `https://github.com/web-infra-dev/rspack`
error: path too long: 'C:/Users/Sean/.cargo/git/checkouts/rspack-8e5e29a4ab8196b6/549d473/webpack-examples/build-http/webpack.lock.data/https_cdn.skypack.dev/escape-string-regex_v5.0.0-SUDdAhYOdAgXIYndxZss_dist_es2020_mode_imports_optimized_escape-string-regexp_95a4ae8a862c0536f335.js'; class=Filesystem (30)
[9:58:25 pm] ~>
Yeah, you need to set registry to long paths. Usually git enables this on instalation https://helpdeskgeek.com/windows-11/how-to-fix-the-path-too-long-error-on-windows/
I.e. navigate to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem then set LongPathsEnabled to 1.
Would it make sense to have cargo recommend this?
Cargo would first need #7986 to make use of the registry setting. Without the manifest option set, the registry setting will be ignored. See Enable Long Paths in Windows 10, Version 1607, and Later.
It would make sense for cargo to offer it as a fix, in my opinion.
Hmm... I do have LongPathsEnabled set to 1, so that doesn't appear to be the cause of the cargo failure.
See my reply above. It's something Cargo would need to opt into. Note that this doesn't affect Cargo's own code (only libgit2 dependency) because the Rust standard library works around the problem even without the registry setting and manifest option.
Demonstrating that it's enabled:
[10:20:43 pm] ~> Get-ItemProperty -path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\ | Select-Object LongPathsEnabled
LongPathsEnabled
----------------
1
[10:21:06 pm] ~> cargo +nightly install --git https://github.com/web-infra-dev/rspack
Updating git repository `https://github.com/web-infra-dev/rspack`
error: path too long: 'C:/Users/Sean/.cargo/git/checkouts/rspack-8e5e29a4ab8196b6/a1be897/webpack-examples/build-http/webpack.lock.data/https_cdn.skypack.dev/escape-string-regexp_v5.0.0-SUDdAhYOdAgXIYndxZss_dist_es2020_mode_imports_optimized_escape-string-regexp_95a4ae8a862c0536f335.js'; class=Filesystem (30)
[10:21:27 pm] ~>
Ok, I can reproduce but there is another setting I'm trying https://answers.microsoft.com/en-us/windows/forum/all/long-path-enabled-does-not-work/4fcfc97e-17da-4f3b-8a50-26eb5da263a5
Cargo also needs to opt in. This can only be done via an application manifest. From my link above:
The application manifest must also include the longPathAware element.
<application xmlns="urn:schemas-microsoft-com:asm.v3"> <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings"> <ws2:longPathAware>true</ws2:longPathAware> </windowsSettings> </application>
Can you try with https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli set?
No change:
[11:12:40 pm] ~> $env:CARGO_NET_GIT_FETCH_WITH_CLI="true"
[11:12:43 pm] ~> cargo +nightly install --git https://github.com/web-infra-dev/rspack
Updating git repository `https://github.com/web-infra-dev/rspack`
error: path too long: 'C:/Users/Sean/.cargo/git/checkouts/rspack-8e5e29a4ab8196b6/a1be897/webpack-examples/build-http/webpack.lock.data/https_cdn.skypack.dev/escape-string-regexp_v5.0.0-SUDdAhYOdAgXIYndxZss_dist_es2020_mode_imports_optimized_escape-string-regexp_95a4ae8a862c0536f335.js'; class=Filesystem (30)
[11:12:51 pm] ~>
You might also need to run:
git config --system core.longpaths true
That fixes it, @ChrisDenton though I need to run that command from an elevated command prompt.
Is this something interesting and worth fixing? Is it desirable to put this in a readme somewhere? At the very least this Issues chain should give a workaround for people who run into this problem in the future, but should there be a long-term solution and if so what should it be?
Oh maybe git config --global core.longpaths true would have worked while avoiding admin. It's just that the gui installer uses system if you select the option during install.
I guess Cargo could detect the error and suggest using setting core.longpaths to true. But I'm not on the Cargo team and don't know how feasible that would be.
One thought is to have cargo automatically set that option when creating dependency or index clones. I think that should work, and should be safe, and doesn't appear to require setting a registry entry.
A risk is that the user has independent tooling, like a backup program or something that inspects the ~/.cargo directory, and that tooling does not handle long paths. However, that seems like a low risk, and perhaps something we can respond to if someone reports it.
One thought is to have cargo automatically set that option when creating dependency or index clones. I think that should work, and should be safe, and doesn't appear to require setting a registry entry.
Yeah it's designed so it can be a repository local setting, no problem. The .git directory itself does however need to be under the MAX_PATH limit but that's always true no matter what.
you can Use Git with Core.LongPaths by running git config --global core.longpaths true