Re: [PATCH v3 6/6] rust: support for Windows
Hi Ezekiel,
On Thu, 20 Nov 2025, Ezekiel Newren wrote:
> This is a retrospective review. I completely missed this patch series,
> and only noticed its existence after it was merged into master. The
> core problem is that these changes assume that windows builds only
> ever use the MSVC compiler, but that's not true.
Correct. I had actually worked on a solution to this in Git for Windows, but due to time constraints (after factoring in the usual time tax, other priorities dictated that I wouldn't have time to see it through) I hadn't had time to contribute it, let alone engage in reviewing Patrick's patches (I had actually not even seen them until I had written the patch and verified that it fixed the issue).
Here is my patch (with proper handling of MSVC, but obviously it no longer applies without conflicts): https://github.com/git-for-windows/git/commit/0949ff2ad5d1d085b10c63029c65293416732851
-- snipsnap --
From 0949ff2ad5d1d085b10c63029c65293416732851 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Fri, 24 Oct 2025 14:49:22 +0200
Subject: [PATCH] meson(cargo): support Windows again
For over a year, Git has been moved to a more modern build system than it had before (GNU make, or on Windows optionally CMake). Naturally, this new system breaks Windows support left and right.
For example, c184795fc0e (meson: add infrastructure to build internal Rust library, 2025-10-02) added support for building a Rust library, and it fails when Visual C is configured as compiler.
This is the reason that the `win+Meson` job of Git's `master` branch fails for the past 16 days, i.e. the latest 9 pushes of the `master` branch as of time of writing. The symptom is:
[697/905] Generating src/git_rs with a custom command
FAILED: [code=1] src/libgitcore.a "C:\Program Files\Git\bin\sh.exe" "D:/a/git/git/src/cargo-meson.sh" "D:/a/git/git" "D:/a/git/git/build/src" "--release"
cp: cannot stat 'D:/a/git/git/build/src/release/libgitcore.a': No such file or directory
The reason is that Visual C's output is called `gitcore.lib`, not `libgitcore.a`. Let's special-case Visual C and use the correct filename in all cases.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
src/cargo-meson.sh | 7 +++++--
src/meson.build | 10 +++++++++-
2 files changed, 14 insertions(+), 3 deletions(-)
Show changes to 2 files +14 −3
src/cargo-meson.sh, src/meson.build
diff --git a/src/cargo-meson.sh b/src/cargo-meson.sh
index 99400986d93..c14a08c592d 100755
--- a/src/cargo-meson.sh
+++ b/src/cargo-meson.sh
@@ -5,6 +5,9 @@ then
exit 1
fi
+target="$1"
+shift
+
SOURCE_DIR="$1"
BUILD_DIR="$2"
BUILD_TYPE=debug
@@ -26,7 +29,7 @@ then
exit $RET
fi
-if ! cmp "$BUILD_DIR/$BUILD_TYPE/libgitcore.a" "$BUILD_DIR/libgitcore.a" >/dev/null 2>&1
+if ! cmp "$BUILD_DIR/$BUILD_TYPE/$target" "$BUILD_DIR/$target" >/dev/null 2>&1
then
- cp "$BUILD_DIR/$BUILD_TYPE/libgitcore.a" "$BUILD_DIR/libgitcore.a"
+ cp "$BUILD_DIR/$BUILD_TYPE/$target" "$BUILD_DIR/$target"
fi
diff --git a/src/meson.build b/src/meson.build
index 25b9ad5a147..b2473c46994 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -3,6 +3,13 @@ libgit_rs_sources = [
'varint.rs',
]
+# The exact file name depends on the compiler
+if meson.get_compiler('c').get_id() == 'msvc'
+ target = 'gitcore.lib'
+else
+ target = 'libgitcore.a'
+endif
+
# Unfortunately we must use a wrapper command to move the output file into the
# current build directory. This can fixed once `cargo build --artifact-dir`
# stabilizes. See https://github.com/rust-lang/cargo/issues/6790 for that
@@ -10,6 +17,7 @@ libgit_rs_sources = [
cargo_command = [
shell,
meson.current_source_dir() / 'cargo-meson.sh',
+ target,
meson.project_source_root(),
meson.current_build_dir(),
]
@@ -21,7 +29,7 @@ libgit_rs = custom_target('git_rs',
input: libgit_rs_sources + [
meson.project_source_root() / 'Cargo.toml',
],
- output: 'libgitcore.a',
+ output: target,
command: cargo_command,
)
libgit_dependencies += declare_dependency(link_with: libgit_rs)
--
2.51.1.windows.1