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

Bootstrap fails to wipe the sysroot directory on Windows if proc-macro-server is being used #107018

Closed
jyn514 opened this issue Jan 18, 2023 · 5 comments · Fixed by #110979
Closed
Labels
A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself C-bug Category: This is a bug. O-windows Operating system: Windows T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@jyn514
Copy link
Member

jyn514 commented Jan 18, 2023

I tried this:

x build

I expected to see this happen: Bootstrap rebuilds the compiler.

Instead, this happened:

PS C:\Users\Joshua Nelson\src\rust> x b clippy --stage 1
Traceback (most recent call last):
  File "C:\Users\Joshua Nelson\src\rust\x.py", line 28, in <module>
    bootstrap.main()
  File "C:\Users\Joshua Nelson\src\rust\src\bootstrap\bootstrap.py", line 937, in main
    bootstrap(help_triggered)
  File "C:\Users\Joshua Nelson\src\rust\src\bootstrap\bootstrap.py", line 912, in bootstrap
    build.download_toolchain()
  File "C:\Users\Joshua Nelson\src\rust\src\bootstrap\bootstrap.py", line 428, in download_toolchain
    shutil.rmtree(bin_root)
  File "C:\Users\Joshua Nelson\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 749, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Users\Joshua Nelson\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 614, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\Joshua Nelson\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 619, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Users\Joshua Nelson\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 617, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\Joshua Nelson\\src\\rust\\build\\x86_64-pc-windows-msvc\\stage0\\libexec\\rust-analyzer-proc-macro-srv.exe'

Meta

git merge-base origin/master HEAD is 9709a43

@jyn514 jyn514 added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) C-bug Category: This is a bug. O-windows Operating system: Windows A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself labels Jan 18, 2023
@jyn514
Copy link
Member Author

jyn514 commented Jan 18, 2023

Bootstrap fails to wipe the sysroot directory on Windows if proc-macro-server is being used

In particular, this happens when rust-analyzer is running in the background and you have this config set:

    "rust-analyzer.procMacro.server": "./build/x86_64-pc-windows-msvc/stage0/libexec/rust-analyzer-proc-macro-srv",

We currently recommend that config in https://rustc-dev-guide.rust-lang.org/building/suggested.html#configuring-rust-analyzer-for-rustc.

@jyn514
Copy link
Member Author

jyn514 commented Jan 18, 2023

@albertlarsan68
Copy link
Member

This happens because Windows doesn't allow deleting a running executable/DLL.

The way forward would be to special-case it as it is already the case with the bootstrap.exe file and ignore failures, or to make a double sysroot as you proposed.

@ChrisDenton
Copy link
Member

You can usually rename a running executable so it may be possible to simulate a delete by moving it within the same filesystem.

However, having a public and a private sysroot seems like a more generally useful solution.

@jyn514
Copy link
Member Author

jyn514 commented Jan 18, 2023

👍 I'm happy with both solutions. I think special casing proc-macro-server in the short term seems fine, but if we do that, we should open another issue for the public and private sysroot.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 29, 2023
windows: kill rust-analyzer-proc-macro-srv before deleting stage0 directory

This fixes the following recurring error on windows:
```
Traceback (most recent call last):
  File "C:\Users\jyn\src\rust\x.py", line 29, in <module>
    bootstrap.main()
  File "C:\Users\jyn\src\rust\src\bootstrap\bootstrap.py", line 963, in main
    bootstrap(args)
  File "C:\Users\jyn\src\rust\src\bootstrap\bootstrap.py", line 927, in bootstrap
    build.download_toolchain()
  File "C:\Users\jyn\src\rust\src\bootstrap\bootstrap.py", line 437, in download_toolchain
    shutil.rmtree(bin_root)
  File "C:\Users\jyn\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
    return _rmtree_unsafe(path, onerror)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\jyn\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\jyn\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 622, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Users\jyn\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 620, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\jyn\\src\\rust\\build\\x86_64-pc-windows-msvc\\stage0\\bin\\rust-analyzer-proc-macro-srv.exe'
```

Fixes rust-lang#107018.

r? `@ChrisDenton`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 29, 2023
windows: kill rust-analyzer-proc-macro-srv before deleting stage0 directory

This fixes the following recurring error on windows:
```
Traceback (most recent call last):
  File "C:\Users\jyn\src\rust\x.py", line 29, in <module>
    bootstrap.main()
  File "C:\Users\jyn\src\rust\src\bootstrap\bootstrap.py", line 963, in main
    bootstrap(args)
  File "C:\Users\jyn\src\rust\src\bootstrap\bootstrap.py", line 927, in bootstrap
    build.download_toolchain()
  File "C:\Users\jyn\src\rust\src\bootstrap\bootstrap.py", line 437, in download_toolchain
    shutil.rmtree(bin_root)
  File "C:\Users\jyn\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
    return _rmtree_unsafe(path, onerror)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\jyn\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\jyn\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 622, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Users\jyn\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 620, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\jyn\\src\\rust\\build\\x86_64-pc-windows-msvc\\stage0\\bin\\rust-analyzer-proc-macro-srv.exe'
```

Fixes rust-lang#107018.

r? ``@ChrisDenton``
@bors bors closed this as completed in 72de69e Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself C-bug Category: This is a bug. O-windows Operating system: Windows T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants