Repository: rust
Issue: Generating documentation using fabricate fails during copy stage on Windows due to long destination paths
Labels: T-bootstrap,C-bug

I am working on upgrading my company's build of rust from 1.41 to 1.52.1. I am finding that the Windows build is failing because fabricate is failing to copy a file.

Build root is: C:\dev\cayman_rust\build\w

Command output is:

```
08:39:38.450 python     INFO         Dist rustc-dev-1.52.1-dev-x86_64-pc-windows-msvc
08:39:38.450 python     INFO         running: "C:\\dev\\cayman_rust\\build\\w\\build\\x86_64-pc-windows-msvc\\stage0-tools-bin\\fabricate.exe" "generate" "--image-dir" "C:\\dev\\cayman_rust\\build\\w\\build\\tmp\\tarball\\rustc-dev\\x86_64-pc-windows-msvc\\image" "--component-name=rustc-dev" "--rel-manifest-dir=rustlib" "--legacy-manifest-dirs=rustlib,cargo" "--product-name=Rust" "--success-message=rustc-dev installed." "--package-name=rustc-dev-1.52.1-dev-x86_64-pc-windows-msvc" "--non-installed-overlay" "C:\\dev\\cayman_rust\\build\\w\\build\\tmp\\tarball\\rustc-dev\\x86_64-pc-windows-msvc\\overlay" "--output-dir" "C:\\dev\\cayman_rust\\build\\w\\build\\dist" "--work-dir" "C:\\dev\\cayman_rust\\build\\w\\build\\tmp\\tarball\\rustc-dev\\x86_64-pc-windows-msvc"
08:39:38.825 python     INFO         Error: failed to generate installer
08:39:38.825 python     INFO
08:39:38.826 python     INFO         Caused by:
08:39:38.826 python     INFO             0: failed to copy 'C:\dev\cayman_rust\build\w\build\tmp\tarball\rustc-dev\x86_64-pc-windows-msvc\image\lib\rustlib\rustc-src\rust\compiler\rustc_codegen_cranelift\crate_patches\0001-compiler-builtins-Remove-rotate_left-from-Int.patch' to 'C:\dev\cayman_rust\build\w\build\tmp\tarball\rustc-dev\x86_64-pc-windows-msvc\rustc-dev-1.52.1-dev-x86_64-pc-windows-msvc\rustc-dev\lib\rustlib\rustc-src\rust\compiler\rustc_codegen_cranelift\crate_patches\0001-compiler-builtins-Remove-rotate_left-from-Int.patch'
08:39:38.827 python     INFO             1: The system cannot find the path specified. (os error 3)
```

The root cause is that the destination file name is longer than the Windows 260-character maximum path limit. This can be worked around in Windows using the methods in https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd which are both:
1. Set a registry value on Win10 1607 or later (I have done this).
2. Add a manifest entry to the process stating that it is long-path aware.

I confirmed that the code that fails calls std::fs::copy which calls CopyFileExW. CopyFileExW is documented to be exempt from long path restrictions if the above two steps are followed. However, fabricate.exe does not have the manifest entry listed in #2.

As a result, I believe that the fix for this is to embed a manifest entry in fabricate.exe that has the following contents:

```
<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>
```

I traced the build code to src/bootstrap/tool.rs but then couldn't find a good way to embed a manifest.