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

Git pre-commit hook for tidy check uses GNU toolchain on windows by default #78150

Closed
Emerentius opened this issue Oct 20, 2020 · 2 comments · Fixed by #78513
Closed

Git pre-commit hook for tidy check uses GNU toolchain on windows by default #78150

Emerentius opened this issue Oct 20, 2020 · 2 comments · Fixed by #78513
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows O-windows-msvc Toolchain: MSVC, Operating system: Windows T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@Emerentius
Copy link
Contributor

Emerentius commented Oct 20, 2020

x.py setup offers to install a pre-commit hook that runs x.py test tidy --bless. Under Windows, when this hook runs and if build isn't set in config.toml, x.py will always try to compile using the GNU toolchain and use GCC's linker which may not be present in which case it fails.

It happens when you're using "Git for Windows", which is probably the most common way to install git on Windows.

I can compile rustc with the MSVC toolchain. Running python x.py test tidy --bless succeeds when started from a powershell window. It throws the same errors as the git hook when run from a git bash terminal.
I suppose x.py can't distinguish git's MinGW environment from a separately installed MinGW? Relevant function in the script that decides the build triple:

def default_build_triple():

I expected to see this happen:
Use the MSVC toolchain to compile and run tidy, especially when run from a powershell terminal.

Instead, this happened:
It tried to use the GNU toolchain from inside Git's MinGW environment, but GCC doesn't exist so it fails.

Error

PS C:\Users\MyUser\Code\rust> git commit
Running pre-commit script 'python C:/Users/MyUser/Code/rust/x.py test tidy --bless'
Updating only changed submodules
Submodules updated in 0.04 seconds
   Compiling proc-macro2 v1.0.19
   Compiling winapi-x86_64-pc-windows-gnu v0.4.0
   Compiling winapi v0.3.9
   Compiling syn v1.0.38
   Compiling memchr v2.3.3
   Compiling serde_derive v1.0.115
   Compiling log v0.4.11
   Compiling serde v1.0.115
   Compiling libc v0.2.79
   Compiling ryu v1.0.5
   Compiling serde_json v1.0.57
   Compiling bootstrap v0.0.0 (C:\Users\MyUser\Code\rust\src\bootstrap)
   Compiling proc-macro-error-attr v1.0.4
   Compiling proc-macro-error v1.0.4
   Compiling num-traits v0.2.12
   Compiling crossbeam-utils v0.7.2
error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: aborting due to previous error

error: could not compile `proc-macro-error-attr`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: aborting due to previous error

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: linker `x86_64-w64-mingw32-gcc` not found
  |
  = note: Das System kann die angegebene Datei nicht finden. (os error 2)

error: aborting due to previous error

error: build failed
failed to run: C:\Users\MyUser\Code\rust\build\x86_64-pc-windows-gnu\stage0\bin\cargo.exe build --manifest-path C:\Users\MyUser\Code\rust\src/bootstrap/Cargo.toml
Build completed unsuccessfully in 0:00:00

As I'm only using MSVC, I can workaround this by setting [build]\nbuild = "x86_64-pc-windows-msvc" in config.toml.

@Emerentius Emerentius added the C-bug Category: This is a bug. label Oct 20, 2020
@jonas-schievink jonas-schievink added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Oct 20, 2020
@jyn514
Copy link
Member

jyn514 commented Oct 20, 2020

Is this specific to the pre-commit hook? Doesn't x.py test tidy always have this behavior?

I guess my question is why setting build = "x86_64-pc-windows-msvc" isn't a sufficient fix.

@Emerentius
Copy link
Contributor Author

x.py test tidy will run the msvc toolchain if started from powershell or cmd, but git doesn't, even if run from powershell.

Setting build = "x86_64-pc-windows-msvc" is a valid fix, if support of compilation for both msvc and gnu from one installation is not desired.
It could be added by x.py setup.

@camelid camelid added the O-windows Operating system: Windows label Oct 20, 2020
@jyn514 jyn514 added the O-windows-msvc Toolchain: MSVC, Operating system: Windows label Oct 23, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 6, 2020
…ulacrum

Infer the default host target from the host toolchain if possible

- `beta-x86_64-unknown-linux-gnu` has beta stripped
- `rustc2` is ignored

This fixes ongoing issues where x.py will detect the wrong host triple
between MSVC and GNU.

I don't think this will break anyone's workflow - I'd be very surprised if you a) had no `[build]` section in `config.toml`, b) had rustc installed, and c) expected the default target to be something other than the default target used by `rustc`. But I could be wrong - I'm happy to hear user stories :)

Fixes rust-lang#78150.

r? `@Mark-Simulacrum`
cc `@Lokathor`
@bors bors closed this as completed in 62d3a4f Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows O-windows-msvc Toolchain: MSVC, 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.

4 participants