git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 1/2] rust: pick a GCC-compatible Cargo target under MSYS2/MinGW

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 13, 2026, 15:57 UTC
Message-ID
<6e8648b21cc88d0a79c3fdff51ba5539ff642145.1789315032.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2213.v4.git.1789315032.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

When Git is built under MSYS2/MinGW with Rust support enabled, the Makefile expects `cargo build` to drop a `target/release/libgitcore.a` that is linkable by the same MinGW GCC used for every other object. With Rust installed via `rustup` (the way it ships on the GitHub-hosted `windows-2022` and `windows-11-arm` runners that build git/git and its forks), the default toolchain targets the MSVC ABI; cargo then writes `target/release/gitcore.lib` instead, which the MinGW `ld.exe` cannot consume:

    LINK git-shell.exe
    D:\git-sdk-64-minimal\mingw64\bin/ld.exe: cannot find target/release/libgitcore.a: No such file or directory
    collect2.exe: error: ld returned 1 exit status

See https://github.com/microsoft/git/actions/runs/27341625000 for a full example log.

Let's define the correct target, using the `CARGO_BUILD_TARGET` variable that will be picked up by Rust, see https://dirname.github.io/rust-std-doc/cargo/reference/environment-variables.html#:~:text=CARGO%5FBUILD%5FTARGET

Re-use (and fix) the existing `HOST_CPU` variable to determine the correct value. Avoid relying on environment variables that are simply not defined in Git for Windows' minimal SDK that Git uses in its CI runs.

Assisted-by: Claude Opus 4.7
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 Makefile         |  2 +-
 config.mak.uname | 25 ++++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index fac3e8879c..ad1ba26f91 100644
--- a/Makefile
+++ b/Makefile
@@ -959,7 +959,7 @@ RUST_LIB_NAME = gitcore.lib
 else
 RUST_LIB_NAME = libgitcore.a
 endif
-RUST_LIB = target/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME)
+RUST_LIB = target$(if $(CARGO_BUILD_TARGET),/$(CARGO_BUILD_TARGET))/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME)
 endif
 
 GITLIBS = common-main.o $(LIB_FILE)
diff --git a/config.mak.uname b/config.mak.uname
index 0b63be10b7..f3f3bcc4ef 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -758,7 +758,30 @@ ifeq ($(uname_S),MINGW)
 			MINGW_PREFIX := /$(shell echo '$(MSYSTEM)' | tr A-Z a-z)
                 endif
 		prefix = $(MINGW_PREFIX)
-		HOST_CPU = $(patsubst %-w64-mingw32,%,$(MINGW_CHOST))
+
+		# A rustup-managed Rust on Windows defaults to the MSVC ABI and
+		# produces a `gitcore.lib` that the MinGW `ld.exe` cannot link.
+		# Pick a GCC-compatible Rust target triple matching the MSYS2
+		# subsystem instead: `*-pc-windows-gnullvm` for the Clang/LLVM
+		# subsystems (which on Windows is also the only choice for
+		# ARM64, where no MinGW-GCC port exists) and `*-pc-windows-gnu`
+		# for the MSVCRT-based MinGW subsystems. For a `staticlib`
+		# crate-type Cargo does not invoke an external linker, so
+		# `rustup target add <triple>` is sufficient.
+                ifneq (,$(filter %ARM64, $(MSYSTEM)))
+			HOST_CPU = aarch64
+                else ifneq (,$(filter %32, $(MSYSTEM)))
+			HOST_CPU = i686
+                else
+			HOST_CPU = x86_64
+                endif
+                ifneq (,$(filter CLANG%, $(MSYSTEM)))
+			CARGO_BUILD_TARGET = $(HOST_CPU)-pc-windows-gnullvm
+                else
+			CARGO_BUILD_TARGET = $(HOST_CPU)-pc-windows-gnu
+                endif
+		export CARGO_BUILD_TARGET
+
 		BASIC_LDFLAGS += -Wl,--pic-executable
 		COMPAT_CFLAGS += -DDETECT_MSYS_TTY \
 			-DENSURE_MSYSTEM_IS_SET="\"$(MSYSTEM)\"" \
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 16 of 21 in “Use Rust in the Windows CI jobs”
  1. 0/2 Use Rust in the Windows CI jobsJohannes Schindelin via GitGitGadget, Sep 1, 2026
  2. 1/2 rust: pick a GCC-compatible Cargo target under MSYS2/MinGWJohannes Schindelin via GitGitGadget, Sep 1, 2026
  3. Junio C HamanoSep 2, 2026
  4. Johannes SchindelinSep 11, 2026
  5. 2/2 ci(windows): build with RustJohannes Schindelin via GitGitGadget, Sep 1, 2026
  6. 0/2 Use Rust in the Windows CI jobsJohannes Schindelin via GitGitGadget, Sep 11, 2026
  7. 2/2 ci(windows): build with RustJohannes Schindelin via GitGitGadget, Sep 11, 2026
  8. 1/2 rust: pick a GCC-compatible Cargo target under MSYS2/MinGWJohannes Schindelin via GitGitGadget, Sep 11, 2026
  9. Junio C HamanoSep 11, 2026
  10. James Le CuirotSep 11, 2026
  11. Johannes SchindelinSep 13, 2026
  12. 0/2 Use Rust in the Windows CI jobsJohannes Schindelin via GitGitGadget, Sep 13, 2026
  13. 1/2 rust: pick a GCC-compatible Cargo target under MSYS2/MinGWJohannes Schindelin via GitGitGadget, Sep 13, 2026
  14. 2/2 ci(windows): build with RustJohannes Schindelin via GitGitGadget, Sep 13, 2026
  15. 0/2 Use Rust in the Windows CI jobsJohannes Schindelin via GitGitGadget, Sep 13, 2026
  16. 1/2 rust: pick a GCC-compatible Cargo target under MSYS2/MinGWJohannes Schindelin via GitGitGadget, Sep 13, 2026
  17. 2/2 ci(windows): build with RustJohannes Schindelin via GitGitGadget, Sep 13, 2026
  18. Junio C HamanoSep 13, 2026
  19. Junio C HamanoSep 18, 2026
  20. Johannes SchindelinSep 21, 2026
  21. Junio C HamanoSep 21, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.