cargo: "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

  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]

About this issue

  • Original URL
  • State: open
  • Created 7 months ago
  • Comments: 19 (9 by maintainers)

Commits related to this issue

Most upvoted comments

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

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

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>