Skip to content

Commit 847a13c

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Based-on-patch-by: Ezekiel Newren <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 11ed16b commit 847a13c

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ test:mingw64:
161161
- saas-windows-medium-amd64
162162
before_script:
163163
- *windows_before_script
164-
- choco install -y git meson ninja
164+
- choco install -y git meson ninja rust-ms
165165
- Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
166166
- refreshenv
167167

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,10 +929,17 @@ TEST_SHELL_PATH = $(SHELL_PATH)
929929
LIB_FILE = libgit.a
930930
XDIFF_LIB = xdiff/lib.a
931931
REFTABLE_LIB = reftable/libreftable.a
932+
932933
ifdef DEBUG
933-
RUST_LIB = target/debug/libgitcore.a
934+
RUST_TARGET_DIR = target/debug
934935
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
936943
endif
937944

938945
# xdiff and reftable libs may in turn depend on what is in libgit.a
@@ -1538,6 +1545,9 @@ ALL_LDFLAGS = $(LDFLAGS) $(LDFLAGS_APPEND)
15381545
ifdef WITH_RUST
15391546
BASIC_CFLAGS += -DWITH_RUST
15401547
GITLIBS += $(RUST_LIB)
1548+
ifeq ($(uname_S),Windows)
1549+
EXTLIBS += -luserenv
1550+
endif
15411551
endif
15421552

15431553
ifdef SANITIZE

meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,10 @@ rust_option = get_option('rust').disable_auto_if(not cargo.found())
17071707
if rust_option.allowed()
17081708
subdir('src')
17091709
libgit_c_args += '-DWITH_RUST'
1710+
1711+
if host_machine.system() == 'windows'
1712+
libgit_dependencies += compiler.find_library('userenv')
1713+
endif
17101714
else
17111715
libgit_sources += [
17121716
'varint.c',

src/cargo-meson.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ then
2626
exit $RET
2727
fi
2828

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
3037
then
31-
cp "$BUILD_DIR/$BUILD_TYPE/libgitcore.a" "$BUILD_DIR/libgitcore.a"
38+
cp "$BUILD_DIR/$BUILD_TYPE/$LIBNAME" "$BUILD_DIR/libgitcore.a"
3239
fi

0 commit comments

Comments
 (0)