Repository: rust
Issue: build_script_build.exe in a Windows Sandbox shared folder is filled with zero bytes
Labels: O-windows,O-windows-msvc,C-bug

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->


Testing this on Windows 10.0.19045.2846, Windows Sandbox and Hyper-V enabled.

* First, create a .wsb file with the following contents:

```xml
<Configuration>
  <MappedFolders>
    <MappedFolder> 
      <HostFolder>C:\test</HostFolder> 
      <SandboxFolder>C:\test</SandboxFolder> 
    </MappedFolder>
  </MappedFolders>
</Configuration>
```

* Create c:\test on your host PC.
* Double click the wsb file to launch the sandbox.
* Confirm you have c:\test inside the sandbox.

The next steps should be done inside the sandbox.


* Install Rust via rustup-init.exe. This will also pull down a "minimal" Visual Studio (sidenote: you can add a flag to your VS setup invocation to make it run without user input, but still show what it's doing)

* Close the Visual Studio windows that are launched (?) so that rustup-init continues.


* Then try creating a new application and add proc-macro2 to its dependencies (this does *not* just impact this package, it'll be anything that uses build_script_build.exe IMO). Note that I am using the shared folder here.


```
PS C:\Users\WDAGUtilityAccount> cd c:\test
PS C:\test> cargo new build-test
     Created binary (application) `build-test` package
PS C:\test> cd .\build-test\
PS C:\test\build-test> cargo add proc-macro2
    Updating crates.io index
      Adding proc-macro2 v1.0.56 to dependencies.
             Features:
             + proc-macro
             - nightly
             - span-locations
    Updating crates.io index
PS C:\test\build-test> cargo build
  Downloaded proc-macro2 v1.0.56
  Downloaded unicode-ident v1.0.8
  Downloaded 2 crates (86.4 KB) in 0.78s
   Compiling proc-macro2 v1.0.56
   Compiling unicode-ident v1.0.8
error: failed to run custom build command for `proc-macro2 v1.0.56`
Caused by:
  could not execute process `C:\test\build-test\target\debug\build\proc-macro2-367b58302398b1c3\build-script-build` (never executed)

Caused by:
  The file or directory is corrupted and unreadable. (os error 1392)
```

If I create a *new* directory that IS NOT shared and create a new application

```
PS C:\test2> cargo add proc-macro2; cargo build
    Updating crates.io index
      Adding proc-macro2 v1.0.56 to dependencies.
             Features:
             + proc-macro
             - nightly
             - span-locations
    Updating crates.io index
   Compiling proc-macro2 v1.0.56
   Compiling unicode-ident v1.0.8
   Compiling test2 v0.1.0 (C:\test2)
    Finished dev [unoptimized + debuginfo] target(s) in 1.57s
```

Now, the most interesting part of this:

.exe files created in the shared folder, e.g. `C:\test\build-test\target\debug\build\proc-macro2-367b58302398b1c3` are zeroed. the .d file and the .pdb seem to be fine though!

[build-test.zip](https://github.com/rust-lang/rust/files/11241102/build-test.zip)
[cargo-build-msvc-link.zip - procmon trace, stable](https://github.com/rust-lang/rust/files/11241257/cargo-build-msvc-link.zip)

I first noticed this on stable, reproduced here with 

```
rustc 1.71.0-nightly (5cdb7886a 2023-04-15)
cargo 1.71.0-nightly (84b7041fd 2023-04-13)
```

I believe this to be an issue with the way Windows Sandbox shared folders work but it needs someone with more experience in both Windows and Rust to have a look.

This may need to be re-tested on Windows 11 as well.

__[Edit: I can't reproduce this with the GNU toolchain!]__