rust: support for Windows

The initial patch series that introduced Rust into the core of Git only cared about macOS and Linux. This specifically leaves out Windows, which indeed fails to build right now due to two issues: - The Rust runtime requires `GetUserProfileDirectoryW()`, but we don't link against "userenv.dll". - The path of the Rust library built on Windows is different than on most other systems systems. Fix both of these issues to support Windows. Note that this commit fixes the Meson-based job in GitHub's CI. Meson auto-detects the availability of Rust, and as the Windows runner has Rust installed by default it already enabled Rust support there. But due to the above issues that job fails consistently. Install Rust on GitLab CI, as well, to improve test coverage there. Based-on-patch-by: Johannes Schindelin <johannes.schindelin@gmx.de> Based-on-patch-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Oct 15, 2025 at 08:04 UTC e509b5b8be0f17467dcc75130f941d84a09d96a3
4 files changed +26 -5
.gitlab-ci.yml
+1 -1
@@ -161,7 +161,7 @@ test:mingw64:
161 - saas-windows-medium-amd64
162 before_script:
163 - *windows_before_script
164 - - choco install -y git meson ninja
164 + - choco install -y git meson ninja rust-ms
165 - Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
166 - refreshenv
167
Makefile
+12 -2
@@ -929,10 +929,17 @@ TEST_SHELL_PATH = $(SHELL_PATH)
929 LIB_FILE = libgit.a
930 XDIFF_LIB = xdiff/lib.a
931 REFTABLE_LIB = reftable/libreftable.a
932 +
933 ifdef DEBUG
933 -RUST_LIB = target/debug/libgitcore.a
934 +RUST_TARGET_DIR = target/debug
935 else
935 -RUST_LIB = target/release/libgitcore.a
936 +RUST_TARGET_DIR = target/release
937 +endif
938 +
939 +ifeq ($(uname_S),Windows)
940 +RUST_LIB = $(RUST_TARGET_DIR)/gitcore.lib
941 +else
942 +RUST_LIB = $(RUST_TARGET_DIR)/libgitcore.a
943 endif
944
945 # xdiff and reftable libs may in turn depend on what is in libgit.a
@@ -1538,6 +1545,9 @@ ALL_LDFLAGS = $(LDFLAGS) $(LDFLAGS_APPEND)
1545 ifdef WITH_RUST
1546 BASIC_CFLAGS += -DWITH_RUST
1547 GITLIBS += $(RUST_LIB)
1548 +ifeq ($(uname_S),Windows)
1549 +EXTLIBS += -luserenv
1550 +endif
1551 endif
1552
1553 ifdef SANITIZE
meson.build
+4
@@ -1707,6 +1707,10 @@ rust_option = get_option('rust').disable_auto_if(not cargo.found())
1707 if rust_option.allowed()
1708 subdir('src')
1709 libgit_c_args += '-DWITH_RUST'
1710 +
1711 + if host_machine.system() == 'windows'
1712 + libgit_dependencies += compiler.find_library('userenv')
1713 + endif
1714 else
1715 libgit_sources += [
1716 'varint.c',
src/cargo-meson.sh
+9 -2
@@ -26,7 +26,14 @@ then
26 exit $RET
27 fi
28
29 -if ! cmp "$BUILD_DIR/$BUILD_TYPE/libgitcore.a" "$BUILD_DIR/libgitcore.a" >/dev/null 2>&1
29 +case "$(cargo -vV | sed -s 's/^host: \(.*\)$/\1/')" in
30 + *-windows-*)
31 + LIBNAME=gitcore.lib;;
32 + *)
33 + LIBNAME=libgitcore.a;;
34 +esac
35 +
36 +if ! cmp "$BUILD_DIR/$BUILD_TYPE/$LIBNAME" "$BUILD_DIR/libgitcore.a" >/dev/null 2>&1
37 then
31 - cp "$BUILD_DIR/$BUILD_TYPE/libgitcore.a" "$BUILD_DIR/libgitcore.a"
38 + cp "$BUILD_DIR/$BUILD_TYPE/$LIBNAME" "$BUILD_DIR/libgitcore.a"
39 fi