From 392a65e9140e415b019bbf0b5b4b5d4655d5eb75 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 21 Nov 2025 12:03:58 +0100 Subject: [PATCH 01/11] fixup! max_tree_depth: lower it for clangarm64 on Windows I have upstreamed this already as 436a42215e5 (max_tree_depth: lower it for clangarm64 on Windows, 2025-04-23). This reverts commit 1d52d303fae (max_tree_depth: lower it for clangarm64 on Windows, 2025-04-15). Signed-off-by: Johannes Schindelin --- environment.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/environment.c b/environment.c index 316e1e6f69a639..b65b85a01f18cf 100644 --- a/environment.c +++ b/environment.c @@ -101,21 +101,9 @@ int max_allowed_tree_depth = * tree depth; This value seems to be low enough. */ 1280; -#else -#if defined(GIT_WINDOWS_NATIVE) && defined(__clang__) && defined(__aarch64__) - /* - * Similar to Visual C, it seems that on Windows/ARM64 the clang-based - * builds have a smaller stack space available. When running out of - * that stack space, a `STATUS_STACK_OVERFLOW` is produced. When the - * Git command was run from an MSYS2 Bash, this unfortunately results - * in an exit code 127. Let's prevent that by lowering the maximal - * tree depth; This value seems to be low enough. - */ - 1280; #else 2048; #endif -#endif #ifndef PROTECT_HFS_DEFAULT #define PROTECT_HFS_DEFAULT 0 From a01bfe653d03e3454da86af99aa9eed430f24f82 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 23 Nov 2025 11:11:01 +0100 Subject: [PATCH 02/11] mingw: stop hard-coding `CC = gcc` This is no longer true in general, not with supporting Clang out of the box. Signed-off-by: Johannes Schindelin --- config.mak.uname | 1 - 1 file changed, 1 deletion(-) diff --git a/config.mak.uname b/config.mak.uname index b28e40caff6ae9..e1dad7c60b7bc9 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -764,7 +764,6 @@ ifeq ($(uname_S),MINGW) COMPAT_CFLAGS += -D_USE_32BIT_TIME_T BASIC_LDFLAGS += -Wl,--large-address-aware endif - CC = gcc COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 -DDETECT_MSYS_TTY \ -DENSURE_MSYSTEM_IS_SET -fstack-protector-strong EXTLIBS += -lntdll From e43f4c5e4c74990acb010dcb9d399e0752ca9851 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 21 Nov 2025 13:03:22 +0100 Subject: [PATCH 03/11] mingw: remove the Makefile target to install test artifacts It is still one of the really vexing quirks of Git's test suite that it requires executables that are not installed via the `install` target. To be able to validate MinGit, I introduced a Makefile target once upon a time to address that omission so as to be able to run the test suite on any installed Git version by bundling the test suite together with those test-supporting executables. However, I never got around to upstream this because the principal reason (moving toward a BusyBox-backed MinGit) went away: BusyBox-w32 is simply not maintained in a confidence-inducing manner and therefore I all but abandoned that initiative. Therefore, this Makefile target is not in a good shape, and it's time to let it go. Signed-off-by: Johannes Schindelin --- config.mak.uname | 51 ------------------------------------------------ 1 file changed, 51 deletions(-) diff --git a/config.mak.uname b/config.mak.uname index e1dad7c60b7bc9..ca0bd42d25a65b 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -780,57 +780,6 @@ ifeq ($(uname_S),MINGW) ETC_GITCONFIG = ../etc/gitconfig ETC_GITATTRIBUTES = ../etc/gitattributes endif - MINGW_PREFIX := $(subst /,,$(prefix)) - - DESTDIR_WINDOWS = $(shell cygpath -aw '$(DESTDIR_SQ)') - DESTDIR_MIXED = $(shell cygpath -am '$(DESTDIR_SQ)') -install-mingit-test-artifacts: - install -m755 -d '$(DESTDIR_SQ)/usr/bin' - printf '%s\n%s\n' >'$(DESTDIR_SQ)/usr/bin/perl' \ - "#!/mingw64/bin/busybox sh" \ - "exec \"$(shell cygpath -am /usr/bin/perl.exe)\" \"\$$@\"" - - install -m755 -d '$(DESTDIR_SQ)' - printf '%s%s\n%s\n%s\n%s\n%s\n' >'$(DESTDIR_SQ)/init.bat' \ - "PATH=$(DESTDIR_WINDOWS)\\$(MINGW_PREFIX)\\bin;" \ - "C:\\WINDOWS;C:\\WINDOWS\\system32" \ - "@set GIT_TEST_INSTALLED=$(DESTDIR_MIXED)/$(MINGW_PREFIX)/bin" \ - "@`echo "$(DESTDIR_WINDOWS)" | sed 's/:.*/:/'`" \ - "@cd `echo "$(DESTDIR_WINDOWS)" | sed 's/^.://'`\\test-git\\t" \ - "@echo Now, run 'helper\\test-run-command testsuite'" - - install -m755 -d '$(DESTDIR_SQ)/test-git' - sed 's/^\(NO_PERL\|NO_PYTHON\)=.*/\1=YesPlease/' \ - '$(DESTDIR_SQ)/test-git/GIT-BUILD-OPTIONS' - - install -m755 -d '$(DESTDIR_SQ)/test-git/t/helper' - install -m755 $(TEST_PROGRAMS) '$(DESTDIR_SQ)/test-git/t/helper' - (cd t && $(TAR) cf - t[0-9][0-9][0-9][0-9] lib-diff) | \ - (cd '$(DESTDIR_SQ)/test-git/t' && $(TAR) xf -) - install -m755 t/t556x_common t/*.sh '$(DESTDIR_SQ)/test-git/t' - - install -m755 -d '$(DESTDIR_SQ)/test-git/templates' - (cd templates && $(TAR) cf - blt) | \ - (cd '$(DESTDIR_SQ)/test-git/templates' && $(TAR) xf -) - - # po/build/locale for t0200 - install -m755 -d '$(DESTDIR_SQ)/test-git/po/build/locale' - (cd po/build/locale && $(TAR) cf - .) | \ - (cd '$(DESTDIR_SQ)/test-git/po/build/locale' && $(TAR) xf -) - - # git-daemon.exe for t5802, git-http-backend.exe for t5560 - install -m755 -d '$(DESTDIR_SQ)/$(MINGW_PREFIX)/bin' - install -m755 git-daemon.exe git-http-backend.exe \ - '$(DESTDIR_SQ)/$(MINGW_PREFIX)/bin' - - # git-upload-archive (dashed) for t5000 - install -m755 -d '$(DESTDIR_SQ)/$(MINGW_PREFIX)/bin' - install -m755 git-upload-archive.exe '$(DESTDIR_SQ)/$(MINGW_PREFIX)/bin' - - # git-difftool--helper for t7800 - install -m755 -d '$(DESTDIR_SQ)/$(MINGW_PREFIX)/libexec/git-core' - install -m755 git-difftool--helper \ - '$(DESTDIR_SQ)/$(MINGW_PREFIX)/libexec/git-core' endif ifeq ($(uname_S),QNX) COMPAT_CFLAGS += -DSA_RESTART=0 From 049d5f5e981c262a38593e6e43546469e6d16fc6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 21 Nov 2025 12:15:12 +0100 Subject: [PATCH 04/11] mingw: drop the -D_USE_32BIT_TIME_T option This option was added in fa93bb20d72 (MinGW: Fix stat definitions to work with MinGW runtime version 4.0, 2013-09-11), i.e. a _long_ time ago. So long, in fact, that it still targeted MinGW. But we switched to mingw-w64 in 2015, which seems not to share the problem, and therefore does not require a fix. Even worse: This flag is incompatible with UCRT64, which we are about to support by way of upstreaming `mingw-w64-git` to the MSYS2 project, see https://github.com/msys2/MINGW-packages/pull/26470 for details. So let's send that option into its well-deserved retirement. Signed-off-by: Johannes Schindelin --- config.mak.uname | 1 - 1 file changed, 1 deletion(-) diff --git a/config.mak.uname b/config.mak.uname index ca0bd42d25a65b..3934052bf05e0a 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -761,7 +761,6 @@ ifeq ($(uname_S),MINGW) HOST_CPU = aarch64 BASIC_LDFLAGS += -Wl,--pic-executable,-e,mainCRTStartup else - COMPAT_CFLAGS += -D_USE_32BIT_TIME_T BASIC_LDFLAGS += -Wl,--large-address-aware endif COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 -DDETECT_MSYS_TTY \ From 119d8afb29b538ec9ba7c01b5297531282d9b273 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 21 Nov 2025 12:38:21 +0100 Subject: [PATCH 05/11] mingw: only use -Wl,--large-address-aware for 32-bit builds That option only matters there, and is in fact only really understood in those builds; UCRT64 versions of GCC, for example, do not know what to do with that option. Signed-off-by: Johannes Schindelin --- config.mak.uname | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/config.mak.uname b/config.mak.uname index 3934052bf05e0a..824127acb2eabb 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -750,9 +750,8 @@ ifeq ($(uname_S),MINGW) ifeq (MINGW32,$(MSYSTEM)) prefix = /mingw32 HOST_CPU = i686 - BASIC_LDFLAGS += -Wl,--pic-executable,-e,_mainCRTStartup - endif - ifeq (MINGW64,$(MSYSTEM)) + BASIC_LDFLAGS += -Wl,--pic-executable,-e,_mainCRTStartup -Wl,--large-address-aware + else ifeq (MINGW64,$(MSYSTEM)) prefix = /mingw64 HOST_CPU = x86_64 BASIC_LDFLAGS += -Wl,--pic-executable,-e,mainCRTStartup @@ -761,7 +760,6 @@ ifeq ($(uname_S),MINGW) HOST_CPU = aarch64 BASIC_LDFLAGS += -Wl,--pic-executable,-e,mainCRTStartup else - BASIC_LDFLAGS += -Wl,--large-address-aware endif COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 -DDETECT_MSYS_TTY \ -DENSURE_MSYSTEM_IS_SET -fstack-protector-strong From 7ac403b9e6a35961c02ea41b04ce96ebb675fe25 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 21 Nov 2025 13:44:56 +0100 Subject: [PATCH 06/11] mingw: avoid over-specifying `--pic-executable` In bf2d5d8239e (Don't let ld strip relocations, 2016-01-16) (picked from https://github.com/git-for-windows/git/pull/612/commits/6a237925bf10), Git for Windows introduced the `-Wl,-pic-executable` flag, specifying the exact entry point via `-e`. This required discerning between i686 and x86_64 code because the former required the symbol to be prefixed with an underscore, the latter did not. As per https://sourceware.org/bugzilla/show_bug.cgi?id=10865, the specified symbols are already the default, though. So let's drop the overly-specific definition. Signed-off-by: Johannes Schindelin --- config.mak.uname | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config.mak.uname b/config.mak.uname index 824127acb2eabb..10d462b16c93d6 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -750,15 +750,15 @@ ifeq ($(uname_S),MINGW) ifeq (MINGW32,$(MSYSTEM)) prefix = /mingw32 HOST_CPU = i686 - BASIC_LDFLAGS += -Wl,--pic-executable,-e,_mainCRTStartup -Wl,--large-address-aware + BASIC_LDFLAGS += -Wl,--pic-executable -Wl,--large-address-aware else ifeq (MINGW64,$(MSYSTEM)) prefix = /mingw64 HOST_CPU = x86_64 - BASIC_LDFLAGS += -Wl,--pic-executable,-e,mainCRTStartup + BASIC_LDFLAGS += -Wl,--pic-executable else ifeq (CLANGARM64,$(MSYSTEM)) prefix = /clangarm64 HOST_CPU = aarch64 - BASIC_LDFLAGS += -Wl,--pic-executable,-e,mainCRTStartup + BASIC_LDFLAGS += -Wl,--pic-executable else endif COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 -DDETECT_MSYS_TTY \ From ca0a65a3ddffca3f0d7ad4e1326ef15439c2cb40 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 21 Nov 2025 13:53:19 +0100 Subject: [PATCH 07/11] mingw: set the prefix and HOST_CPU as per MSYS2's settings MSYS2 already defines a couple of helpful environment variables, and we can use those to infer the installation location as well as the CPU. No need for hard-coding ;-) Signed-off-by: Johannes Schindelin --- config.mak.uname | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/config.mak.uname b/config.mak.uname index 10d462b16c93d6..ae767608662ab5 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -747,19 +747,13 @@ ifeq ($(uname_S),MINGW) ifneq (,$(findstring -O,$(filter-out -O0 -Og,$(CFLAGS)))) BASIC_LDFLAGS += -Wl,--dynamicbase endif - ifeq (MINGW32,$(MSYSTEM)) - prefix = /mingw32 - HOST_CPU = i686 - BASIC_LDFLAGS += -Wl,--pic-executable -Wl,--large-address-aware - else ifeq (MINGW64,$(MSYSTEM)) - prefix = /mingw64 - HOST_CPU = x86_64 - BASIC_LDFLAGS += -Wl,--pic-executable - else ifeq (CLANGARM64,$(MSYSTEM)) - prefix = /clangarm64 - HOST_CPU = aarch64 + ifneq (,$(MSYSTEM)) + prefix = $(MINGW_PREFIX) + HOST_CPU = $(patsubst %-w64-mingw32,%,$(MINGW_CHOST)) BASIC_LDFLAGS += -Wl,--pic-executable - else + ifeq (MINGW32,$(MSYSTEM)) + BASIC_LDFLAGS += -Wl,--large-address-aware + endif endif COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 -DDETECT_MSYS_TTY \ -DENSURE_MSYSTEM_IS_SET -fstack-protector-strong From 513d221d6ca5bb7ee7cd391e4ca7981539a6f5c0 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 21 Nov 2025 14:09:40 +0100 Subject: [PATCH 08/11] mingw: only enable the MSYS2-specific stuff when compiling in MSYS2 The tell-tale is the presence of the `MSYSTEM` value while compiling, of course. In that case, we want to ensure that `MSYSTEM` is set when running `git.exe`, and also enable the magic MSYS2 tty detection. Signed-off-by: Johannes Schindelin --- config.mak.uname | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.mak.uname b/config.mak.uname index ae767608662ab5..289ded45c739a0 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -751,12 +751,12 @@ ifeq ($(uname_S),MINGW) prefix = $(MINGW_PREFIX) HOST_CPU = $(patsubst %-w64-mingw32,%,$(MINGW_CHOST)) BASIC_LDFLAGS += -Wl,--pic-executable + COMPAT_CFLAGS += -DDETECT_MSYS_TTY -DENSURE_MSYSTEM_IS_SET ifeq (MINGW32,$(MSYSTEM)) BASIC_LDFLAGS += -Wl,--large-address-aware endif endif - COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 -DDETECT_MSYS_TTY \ - -DENSURE_MSYSTEM_IS_SET -fstack-protector-strong + COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 -fstack-protector-strong EXTLIBS += -lntdll EXTRA_PROGRAMS += headless-git$X INSTALL = /bin/install From eea27f530dd37d6212e9bc587cd0f19e3b37a8b7 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 21 Nov 2025 14:17:24 +0100 Subject: [PATCH 09/11] mingw: rely on MSYS2's metadata instead of hard-coding it MSYS2 defines some helpful environment variables, e.g. `MSYSTEM`. There is code in Git for Windows to ensure that that `MSYSTEM` variable is set, hard-coding a default. However, the existing solution jumps through hoops to reconstruct the proper default, and is even incomplete doing so, as we found out when we extended it to support CLANGARM64. This is absolutely unnecessary because there is already a perfectly valid `MSYSTEM` value we can use at build time. This is even true when building the MINGW32 variant on a MINGW64 system because `makepkg-mingw` will override the `MSYSTEM` value as per the `MINGW_ARCH` array. The same is equally true for the `/mingw64`, `/mingw32` and `/clangarm64` prefix: those values are already available via the `MINGW_PREFIX` environment variable, and we just need to pass that setting through. Only when `MINGW_PREFIX` is not set (as is the case in Git for Windows' minimal SDK, where only `MSYSTEM` is guaranteed to be set correctly), we use as fall-back the top-level directory whose name is the down-cased value of the `MSYSTEM` variable. Incidentally, this also broadens the support to all the configurations supported by the MSYS2 project, i.e. clang64 & ucrt64, too. Note: This keeps the same, hard-coded MSYSTEM platform support for CMake as before, but drops it for Meson (because it is unclear how Meson could do this in a more flexible manner). Signed-off-by: Johannes Schindelin --- compat/mingw.c | 29 +++++++---------------------- config.mak.uname | 22 ++++++++++++---------- contrib/buildsystems/CMakeLists.txt | 9 ++++++++- meson.build | 13 ++++++++++++- meson_options.txt | 4 ++++ 5 files changed, 43 insertions(+), 34 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 6accd26f2a9808..9891950d4ed115 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -3625,7 +3625,7 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen) } #ifdef ENSURE_MSYSTEM_IS_SET -#if !defined(RUNTIME_PREFIX) || !defined(HAVE_WPGMPTR) +#if !defined(RUNTIME_PREFIX) || !defined(HAVE_WPGMPTR) || !defined(MINGW_PREFIX) static size_t append_system_bin_dirs(char *path UNUSED, size_t size UNUSED) { return 0; @@ -3643,25 +3643,16 @@ static size_t append_system_bin_dirs(char *path, size_t size) /* strip trailing `git.exe` */ len = slash - prefix; - /* strip trailing `cmd` or `mingw64\bin` or `mingw32\bin` or `bin` or `libexec\git-core` */ - if (strip_suffix_mem(prefix, &len, "\\mingw64\\libexec\\git-core") || - strip_suffix_mem(prefix, &len, "\\mingw64\\bin")) + /* strip trailing `cmd` or `\bin` or `bin` or `libexec\git-core` */ + if (strip_suffix_mem(prefix, &len, "\\" MINGW_PREFIX "\\libexec\\git-core") || + strip_suffix_mem(prefix, &len, "\\" MINGW_PREFIX "\\bin")) off += xsnprintf(path + off, size - off, - "%.*s\\mingw64\\bin;", (int)len, prefix); - else if (strip_suffix_mem(prefix, &len, "\\clangarm64\\libexec\\git-core") || - strip_suffix_mem(prefix, &len, "\\clangarm64\\bin")) - off += xsnprintf(path + off, size - off, - "%.*s\\clangarm64\\bin;", (int)len, prefix); - else if (strip_suffix_mem(prefix, &len, "\\mingw32\\libexec\\git-core") || - strip_suffix_mem(prefix, &len, "\\mingw32\\bin")) - off += xsnprintf(path + off, size - off, - "%.*s\\mingw32\\bin;", (int)len, prefix); + "%.*s\\" MINGW_PREFIX "\\bin;", (int)len, prefix); else if (strip_suffix_mem(prefix, &len, "\\cmd") || strip_suffix_mem(prefix, &len, "\\bin") || strip_suffix_mem(prefix, &len, "\\libexec\\git-core")) off += xsnprintf(path + off, size - off, - "%.*s\\mingw%d\\bin;", (int)len, prefix, - (int)(sizeof(void *) * 8)); + "%.*s\\" MINGW_PREFIX "\\bin;", (int)len, prefix); else return 0; @@ -3757,13 +3748,7 @@ static void setup_windows_environment(void) char buf[32768]; size_t off = 0; -#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) - setenv("MSYSTEM", "CLANGARM64", 1); -#elif defined(__MINGW64__) || defined(_M_AMD64) - setenv("MSYSTEM", "MINGW64", 1); -#else - setenv("MSYSTEM", "MINGW32", 1); -#endif + setenv("MSYSTEM", ENSURE_MSYSTEM_IS_SET, 1); if (home) off += xsnprintf(buf + off, sizeof(buf) - off, diff --git a/config.mak.uname b/config.mak.uname index 289ded45c739a0..1c8a32b2b10c8f 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -452,14 +452,8 @@ ifeq ($(uname_S),Windows) GIT_VERSION := $(GIT_VERSION).MSVC pathsep = ; # Assume that this is built in Git for Windows' SDK - ifeq (MINGW32,$(MSYSTEM)) - prefix = /mingw32 - else - ifeq (CLANGARM64,$(MSYSTEM)) - prefix = /clangarm64 - else - prefix = /mingw64 - endif + ifneq (,$(MSYSTEM)) + prefix = $(MINGW_PREFIX) endif # Prepend MSVC 64-bit tool-chain to PATH. # @@ -529,7 +523,9 @@ endif compat/win32/pthread.o compat/win32/syslog.o \ compat/win32/trace2_win32_process_info.o \ compat/win32/dirent.o compat/win32/fscache.o compat/win32/wsl.o - COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DDETECT_MSYS_TTY -DENSURE_MSYSTEM_IS_SET -DNOGDI -DHAVE_STRING_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\" + COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DDETECT_MSYS_TTY \ + -DENSURE_MSYSTEM_IS_SET="\"$(MSYSTEM)\"" -DMINGW_PREFIX="\"$(patsubst /%,%,$(MINGW_PREFIX))\"" \ + -DNOGDI -DHAVE_STRING_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\" BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO # invalidcontinue.obj allows Git's source code to close the same file # handle twice, or to access the osfhandle of an already-closed stdout @@ -748,10 +744,16 @@ ifeq ($(uname_S),MINGW) BASIC_LDFLAGS += -Wl,--dynamicbase endif ifneq (,$(MSYSTEM)) + ifeq ($(MINGW_PREFIX),$(filter-out /%,$(MINGW_PREFIX))) + # Override if empty or does not start with a slash + MINGW_PREFIX := /$(shell echo '$(MSYSTEM)' | tr A-Z a-z) + endif prefix = $(MINGW_PREFIX) HOST_CPU = $(patsubst %-w64-mingw32,%,$(MINGW_CHOST)) BASIC_LDFLAGS += -Wl,--pic-executable - COMPAT_CFLAGS += -DDETECT_MSYS_TTY -DENSURE_MSYSTEM_IS_SET + COMPAT_CFLAGS += -DDETECT_MSYS_TTY \ + -DENSURE_MSYSTEM_IS_SET="\"$(MSYSTEM)\"" \ + -DMINGW_PREFIX="\"$(patsubst /%,%,$(MINGW_PREFIX))\"" ifeq (MINGW32,$(MSYSTEM)) BASIC_LDFLAGS += -Wl,--large-address-aware endif diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 6443dfbac52663..c69f3a7ea95667 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -282,7 +282,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") _CONSOLE DETECT_MSYS_TTY STRIP_EXTENSION=".exe" NO_SYMLINK_HEAD UNRELIABLE_FSTAT NOGDI OBJECT_CREATION_MODE=1 __USE_MINGW_ANSI_STDIO=0 USE_NED_ALLOCATOR OVERRIDE_STRDUP MMAP_PREVENTS_DELETE USE_WIN32_MMAP - HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET HAVE_RTLGENRANDOM) + HAVE_WPGMPTR HAVE_RTLGENRANDOM) + if(CMAKE_GENERATOR_PLATFORM STREQUAL "x64") + add_compile_definitions(ENSURE_MSYSTEM_IS_SET="MINGW64" MINGW_PREFIX="mingw64") + elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "arm64") + add_compile_definitions(ENSURE_MSYSTEM_IS_SET="CLANGARM64" MINGW_PREFIX="clangarm64") + elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "x86") + add_compile_definitions(ENSURE_MSYSTEM_IS_SET="MINGW32" MINGW_PREFIX="mingw32") + endif() list(APPEND compat_SOURCES compat/mingw.c compat/winansi.c diff --git a/meson.build b/meson.build index 46b1369c45e8ae..03fa16012dbefc 100644 --- a/meson.build +++ b/meson.build @@ -1271,7 +1271,6 @@ elif host_machine.system() == 'windows' libgit_c_args += [ '-DDETECT_MSYS_TTY', - '-DENSURE_MSYSTEM_IS_SET', '-DNATIVE_CRLF', '-DNOGDI', '-DNO_POSIX_GOODIES', @@ -1281,6 +1280,18 @@ elif host_machine.system() == 'windows' '-D__USE_MINGW_ANSI_STDIO=0', ] + msystem = get_option('msystem') + if msystem != '' + mingw_prefix = get_option('mingw_prefix') + if mingw_prefix == '' + mingw_prefix = '/' + msystem.to_lower() + endif + libgit_c_args += [ + '-DENSURE_MSYSTEM_IS_SET="' + msystem + '"', + '-DMINGW_PREFIX="' + mingw_prefix + '"' + ] + endif + libgit_dependencies += compiler.find_library('ntdll') libgit_include_directories += 'compat/win32' if compiler.get_id() == 'msvc' diff --git a/meson_options.txt b/meson_options.txt index e0be260ae1bce8..c2d9f0bfc0c2fb 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -21,6 +21,10 @@ option('runtime_prefix', type: 'boolean', value: false, description: 'Resolve ancillary tooling and support files relative to the location of the runtime binary instead of hard-coding them into the binary.') option('sane_tool_path', type: 'array', value: [], description: 'An array of paths to pick up tools from in case the normal tools are broken or lacking.') +option('msystem', type: 'string', value: '', + description: 'Fall-back on Windows when MSYSTEM is not set.') +option('mingw_prefix', type: 'string', value: '', + description: 'Fall-back on Windows when MINGW_PREFIX is not set.') # Build information compiled into Git and other parts like documentation. option('build_date', type: 'string', value: '', From 9abcf48e2b02d6916a36ea8c83bc8cb96621b81f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 21 Nov 2025 14:45:45 +0100 Subject: [PATCH 10/11] mingw: always define `ETC_*` for MSYS2 environments Special-casing even more configurations simply does not make sense. Signed-off-by: Johannes Schindelin --- config.mak.uname | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/config.mak.uname b/config.mak.uname index 1c8a32b2b10c8f..ba399c22fbfc56 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -507,7 +507,7 @@ ifeq ($(uname_S),Windows) NATIVE_CRLF = YesPlease DEFAULT_HELP_FORMAT = html SKIP_DASHED_BUILT_INS = YabbaDabbaDoo -ifeq (/mingw64,$(subst 32,64,$(subst clangarm,mingw,$(prefix)))) +ifneq (,$(MINGW_PREFIX)) # Move system config into top-level /etc/ ETC_GITCONFIG = ../etc/gitconfig ETC_GITATTRIBUTES = ../etc/gitattributes @@ -757,6 +757,9 @@ ifeq ($(uname_S),MINGW) ifeq (MINGW32,$(MSYSTEM)) BASIC_LDFLAGS += -Wl,--large-address-aware endif + # Move system config into top-level /etc/ + ETC_GITCONFIG = ../etc/gitconfig + ETC_GITATTRIBUTES = ../etc/gitattributes endif COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 -fstack-protector-strong EXTLIBS += -lntdll @@ -768,11 +771,6 @@ ifeq ($(uname_S),MINGW) USE_LIBPCRE = YesPlease USE_MIMALLOC = YesPlease NO_PYTHON = - ifeq (/mingw64,$(subst 32,64,$(subst clangarm,mingw,$(prefix)))) - # Move system config into top-level /etc/ - ETC_GITCONFIG = ../etc/gitconfig - ETC_GITATTRIBUTES = ../etc/gitattributes - endif endif ifeq ($(uname_S),QNX) COMPAT_CFLAGS += -DSA_RESTART=0 From 0cf99d9675c98a7358543a0e42bd973bde2901ae Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 21 Nov 2025 15:15:42 +0100 Subject: [PATCH 11/11] max_tree_depth: lower it for clang builds in general on Windows In 436a42215e5 (max_tree_depth: lower it for clangarm64 on Windows, 2025-04-23), I provided a work-around for a nasty issue with clangarm builds, where the stack is exhausted before the maximal tree depth is reached, and the resulting error cannot easily be handled by Git (because it would require Windows-specific handling). Turns out that this is not at all limited to ARM64. In my tests with CLANG64 in MSYS2 on the GitHub Actions runners, the test t6700.4 failed in the exact same way. What's worse: The limit needs to be quite a bit lower for x86_64 than for aarch64. In aforementioned tests, the breaking point was 1232: With 1231 it still worked as expected, with 1232 it would fail with the `STATUS_STACK_OVERFLOW` incorrectly mapped to exit code 127. For comparison, in my tests on GitHub Actions' Windows/ARM64 runners, the breaking point was 1439 instead. Therefore the condition needs to be adapted once more, to accommodate (with some safety margin) both aarch64 and x86_64 in clang-based builds on Windows, to let that test pass. Signed-off-by: Johannes Schindelin --- environment.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/environment.c b/environment.c index b65b85a01f18cf..e2bffb3a340f55 100644 --- a/environment.c +++ b/environment.c @@ -91,16 +91,22 @@ int max_allowed_tree_depth = * the stack overflow can occur. */ 512; -#elif defined(GIT_WINDOWS_NATIVE) && defined(__clang__) && defined(__aarch64__) +#elif defined(GIT_WINDOWS_NATIVE) && defined(__clang__) /* - * Similar to Visual C, it seems that on Windows/ARM64 the clang-based - * builds have a smaller stack space available. When running out of - * that stack space, a `STATUS_STACK_OVERFLOW` is produced. When the + * Similar to Visual C, it seems that clang-based builds on Windows + * have a smaller stack space available. When running out of that + * stack space, a `STATUS_STACK_OVERFLOW` is produced. When the * Git command was run from an MSYS2 Bash, this unfortunately results * in an exit code 127. Let's prevent that by lowering the maximal - * tree depth; This value seems to be low enough. + * tree depth; Unfortunately, it seems that the exact limit differs + * for aarch64 vs x86_64, and the difference is too large to simply + * use a single limit. */ +#if defined(__aarch64__) 1280; +#else + 1152; +#endif #else 2048; #endif