Merge branch 'js/rust-in-windows-ci' into next

Update Windows CI build to support Rust.

* js/rust-in-windows-ci:
  ci(windows): build with Rust
  rust: pick a GCC-compatible Cargo target under MSYS2/MinGW
next
Junio C Hamano 2026-09-13 21:56:05 -07:00
commit fb3c42e1d9
4 changed files with 49 additions and 5 deletions

View File

@ -116,6 +116,30 @@ jobs:
steps:
- uses: actions/checkout@v6
- uses: git-for-windows/setup-git-for-windows-sdk@v2
- name: Install GCC-compatible Rust target
shell: bash
run: |
# The hosted Windows runners ship a rustup-managed Rust whose
# default toolchain targets the MSVC ABI. That produces a
# `gitcore.lib` which the MinGW GCC used by the rest of the
# build cannot link. Install the precompiled `std` for a
# GCC-compatible target triple matching the MSYS2 subsystem;
# the Makefile selects the same triple via $(MSYSTEM) and
# passes it to `cargo build --target`.
case "$MSYSTEM" in
CLANGARM64) target=aarch64-pc-windows-gnullvm ;;
CLANG64) target=x86_64-pc-windows-gnullvm ;;
CLANG32) target=i686-pc-windows-gnullvm ;;
UCRT64) target=x86_64-pc-windows-gnu ;;
MINGW64) target=x86_64-pc-windows-gnu ;;
MINGW32) target=i686-pc-windows-gnu ;;
*) echo "::error::Unsupported MSYSTEM: $MSYSTEM"; exit 1 ;;
esac &&
rustup target add "$target" &&

# Ensure that cargo.exe is found even with the minimal SDK's restricted PATH
CARGO="$(type -p cargo.exe)" &&
echo "export PATH=\$PATH:${CARGO%/cargo.exe}" >>/etc/profile
- name: build
shell: bash
env:

View File

@ -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)

View File

@ -391,9 +391,6 @@ linux-asan-ubsan)
osx-meson)
MESONFLAGS="$MESONFLAGS -Dcredential_helpers=osxkeychain"
;;
windows-*)
export NO_RUST=UnfortunatelyYes
;;
esac

MAKEFLAGS="$MAKEFLAGS CC=${CC:-cc}"

View File

@ -760,7 +760,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)\"" \