Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"error: path too long" on Windows when doing "cargo install --git" #13020

Open
xobs opened this issue Nov 21, 2023 · 19 comments
Open

"error: path too long" on Windows when doing "cargo install --git" #13020

xobs opened this issue Nov 21, 2023 · 19 comments
Labels
A-git Area: anything dealing with git C-bug Category: bug O-windows OS: Windows S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@xobs
Copy link

xobs commented Nov 21, 2023

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

  1. Run Windows
  2. 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]
@xobs xobs added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Nov 21, 2023
@epage epage added the O-windows OS: Windows label Nov 21, 2023
@ChrisDenton
Copy link
Member

Can you paste the full error output? Feel free to censor paths if you'd prefer.

@xobs
Copy link
Author

xobs commented Nov 21, 2023

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] ~>

@Ygg01
Copy link

Ygg01 commented Nov 21, 2023

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.

@xobs
Copy link
Author

xobs commented Nov 21, 2023

Would it make sense to have cargo recommend this?

@ChrisDenton
Copy link
Member

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.

@Ygg01
Copy link

Ygg01 commented Nov 21, 2023

It would make sense for cargo to offer it as a fix, in my opinion.

@xobs
Copy link
Author

xobs commented Nov 21, 2023

Hmm... I do have LongPathsEnabled set to 1, so that doesn't appear to be the cause of the cargo failure.

@ChrisDenton
Copy link
Member

ChrisDenton commented Nov 21, 2023

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.

@xobs
Copy link
Author

xobs commented Nov 21, 2023

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] ~>

@Ygg01
Copy link

Ygg01 commented Nov 21, 2023

@ChrisDenton
Copy link
Member

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>

@Eh2406
Copy link
Contributor

Eh2406 commented Nov 21, 2023

@xobs
Copy link
Author

xobs commented Nov 21, 2023

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] ~>

@ChrisDenton
Copy link
Member

You might also need to run:
git config --system core.longpaths true

@xobs
Copy link
Author

xobs commented Nov 21, 2023

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?

@ChrisDenton
Copy link
Member

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.

@ehuss ehuss added A-git Area: anything dealing with git S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. and removed S-triage Status: This issue is waiting on initial triage. labels Nov 22, 2023
@ehuss
Copy link
Contributor

ehuss commented Dec 8, 2023

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.

@ChrisDenton
Copy link
Member

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.

@ehuss ehuss added S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. labels Dec 8, 2023
rbalicki2 pushed a commit to isographlabs/isograph that referenced this issue Feb 17, 2024
* When building for windows, we need to set `git config --system core.longpaths true`
* This commit modifies ci.yml to do so
* See rust-lang/cargo#13020 for more info
@abdallah-221b
Copy link

you can Use Git with Core.LongPaths by running
git config --global core.longpaths true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-git Area: anything dealing with git C-bug Category: bug O-windows OS: Windows S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

No branches or pull requests

7 participants