Skip to content

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

Closed
@Emerentius

Description

@Emerentius

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-windowsOperating system: WindowsO-windows-msvcToolchain: MSVC, Operating system: WindowsT-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions