Skip to content

Commit 1ea71b7

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Add full mingw-w64-git (i.e. regular MSYS2 ecosystem) support (git-for-windows#5971)
Every once in a while, there are bug reports in Git for Windows' bug tracker that describe an issue running [inside MSYS2 proper](https://gitforwindows.org/install-inside-msys2-proper), totally ignoring the big, honking warning on top of [the page](https://gitforwindows.org/install-inside-msys2-proper) that spells out clearly that this is an unsupported use case. At the same time, we cannot easily deflect and say "just use MSYS2 directly" (and leave the "and stop pestering us" out). We cannot do that because there is only an _MSYS_ `git` package in MSYS2 (i.e. a Git that uses the quite slow POSIX emulation layer provided by the MSYS2 runtime), but no `mingw-w64-git` package (which would be equivalent in speed to Git for Windows). In msys2/MINGW-packages#26470, I am preparing to change that. As part of that PR, I noticed and fixed a couple of issues _in `git-for-windows/git` that prevented full support for `mingw-w64-git` in MSYS2, such as problems with CLANG64 and UCRT64. While at it, I simplified the entire setup to trust MSYS2's `MINGW_PREFIX` & related environment variables instead of hard-coding values like the installation prefix and what `MSYSTEM` to fall back on if it is unset.
2 parents 6267152 + 87d23ce commit 1ea71b7

5 files changed

Lines changed: 54 additions & 40 deletions

File tree

config.mak.uname

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,8 @@ ifeq ($(uname_S),Windows)
452452
GIT_VERSION := $(GIT_VERSION).MSVC
453453
pathsep = ;
454454
# Assume that this is built in Git for Windows' SDK
455-
ifeq (MINGW32,$(MSYSTEM))
456-
prefix = /mingw32
457-
else
458-
ifeq (CLANGARM64,$(MSYSTEM))
459-
prefix = /clangarm64
460-
else
461-
prefix = /mingw64
462-
endif
455+
ifneq (,$(MSYSTEM))
456+
prefix = $(MINGW_PREFIX)
463457
endif
464458
# Prepend MSVC 64-bit tool-chain to PATH.
465459
#
@@ -512,7 +506,7 @@ ifeq ($(uname_S),Windows)
512506
NATIVE_CRLF = YesPlease
513507
DEFAULT_HELP_FORMAT = html
514508
SKIP_DASHED_BUILT_INS = YabbaDabbaDoo
515-
ifeq (/mingw64,$(subst 32,64,$(subst clangarm,mingw,$(prefix))))
509+
ifneq (,$(MINGW_PREFIX))
516510
# Move system config into top-level /etc/
517511
ETC_GITCONFIG = ../etc/gitconfig
518512
ETC_GITATTRIBUTES = ../etc/gitattributes
@@ -743,26 +737,23 @@ ifeq ($(uname_S),MINGW)
743737
ifneq (,$(findstring -O,$(filter-out -O0 -Og,$(CFLAGS))))
744738
BASIC_LDFLAGS += -Wl,--dynamicbase
745739
endif
746-
ifeq (MINGW32,$(MSYSTEM))
747-
prefix = /mingw32
748-
HOST_CPU = i686
749-
BASIC_LDFLAGS += -Wl,--pic-executable,-e,_mainCRTStartup
750-
endif
751-
ifeq (MINGW64,$(MSYSTEM))
752-
prefix = /mingw64
753-
HOST_CPU = x86_64
754-
BASIC_LDFLAGS += -Wl,--pic-executable,-e,mainCRTStartup
755-
else ifeq (CLANGARM64,$(MSYSTEM))
756-
prefix = /clangarm64
757-
HOST_CPU = aarch64
758-
BASIC_LDFLAGS += -Wl,--pic-executable,-e,mainCRTStartup
759-
else
760-
COMPAT_CFLAGS += -D_USE_32BIT_TIME_T
761-
BASIC_LDFLAGS += -Wl,--large-address-aware
740+
ifneq (,$(MSYSTEM))
741+
ifeq ($(MINGW_PREFIX),$(filter-out /%,$(MINGW_PREFIX)))
742+
# Override if empty or does not start with a slash
743+
MINGW_PREFIX := /$(shell echo '$(MSYSTEM)' | tr A-Z a-z)
744+
endif
745+
prefix = $(MINGW_PREFIX)
746+
HOST_CPU = $(patsubst %-w64-mingw32,%,$(MINGW_CHOST))
747+
BASIC_LDFLAGS += -Wl,--pic-executable
748+
COMPAT_CFLAGS += -DDETECT_MSYS_TTY
749+
ifeq (MINGW32,$(MSYSTEM))
750+
BASIC_LDFLAGS += -Wl,--large-address-aware
751+
endif
752+
# Move system config into top-level /etc/
753+
ETC_GITCONFIG = ../etc/gitconfig
754+
ETC_GITATTRIBUTES = ../etc/gitattributes
762755
endif
763-
CC = gcc
764-
COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 -DDETECT_MSYS_TTY \
765-
-fstack-protector-strong
756+
COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 -fstack-protector-strong
766757
EXTLIBS += -lntdll
767758
EXTRA_PROGRAMS += headless-git$X
768759
INSTALL = /bin/install
@@ -772,11 +763,6 @@ ifeq ($(uname_S),MINGW)
772763
USE_LIBPCRE = YesPlease
773764
USE_MIMALLOC = YesPlease
774765
NO_PYTHON =
775-
ifeq (/mingw64,$(subst 32,64,$(subst clangarm,mingw,$(prefix))))
776-
# Move system config into top-level /etc/
777-
ETC_GITCONFIG = ../etc/gitconfig
778-
ETC_GITATTRIBUTES = ../etc/gitattributes
779-
endif
780766
endif
781767
ifeq ($(uname_S),QNX)
782768
COMPAT_CFLAGS += -DSA_RESTART=0

contrib/buildsystems/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
281281
_CONSOLE DETECT_MSYS_TTY STRIP_EXTENSION=".exe" NO_SYMLINK_HEAD UNRELIABLE_FSTAT
282282
NOGDI OBJECT_CREATION_MODE=1 __USE_MINGW_ANSI_STDIO=0
283283
OVERRIDE_STRDUP MMAP_PREVENTS_DELETE USE_WIN32_MMAP
284-
HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET HAVE_RTLGENRANDOM)
284+
HAVE_WPGMPTR HAVE_RTLGENRANDOM)
285+
if(CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
286+
add_compile_definitions(ENSURE_MSYSTEM_IS_SET="MINGW64" MINGW_PREFIX="mingw64")
287+
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "arm64")
288+
add_compile_definitions(ENSURE_MSYSTEM_IS_SET="CLANGARM64" MINGW_PREFIX="clangarm64")
289+
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "x86")
290+
add_compile_definitions(ENSURE_MSYSTEM_IS_SET="MINGW32" MINGW_PREFIX="mingw32")
291+
endif()
285292
list(APPEND compat_SOURCES
286293
compat/mingw.c
287294
compat/winansi.c

git-compat-util.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,17 +605,23 @@ static inline bool strip_suffix(const char *str, const char *suffix,
605605
* the stack overflow can occur.
606606
*/
607607
#define DEFAULT_MAX_ALLOWED_TREE_DEPTH 512
608-
#elif defined(GIT_WINDOWS_NATIVE) && defined(__clang__) && defined(__aarch64__)
608+
#elif defined(GIT_WINDOWS_NATIVE) && defined(__clang__)
609609
/*
610-
* Similar to Visual C, it seems that on Windows/ARM64 the clang-based
611-
* builds have a smaller stack space available. When running out of
612-
* that stack space, a `STATUS_STACK_OVERFLOW` is produced. When the
610+
* Similar to Visual C, it seems that clang-based builds on Windows
611+
* have a smaller stack space available. When running out of that
612+
* stack space, a `STATUS_STACK_OVERFLOW` is produced. When the
613613
* Git command was run from an MSYS2 Bash, this unfortunately results
614614
* in an exit code 127. Let's prevent that by lowering the maximal
615-
* tree depth; This value seems to be low enough.
615+
* tree depth; Unfortunately, it seems that the exact limit differs
616+
* for aarch64 vs x86_64, and the difference is too large to simply
617+
* use a single limit.
616618
*/
619+
#if defined(__aarch64__)
617620
#define DEFAULT_MAX_ALLOWED_TREE_DEPTH 1280
618621
#else
622+
#define DEFAULT_MAX_ALLOWED_TREE_DEPTH 1152
623+
#endif
624+
#else
619625
#define DEFAULT_MAX_ALLOWED_TREE_DEPTH 2048
620626
#endif
621627

meson.build

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,6 @@ elif host_machine.system() == 'windows'
12971297

12981298
libgit_c_args += [
12991299
'-DDETECT_MSYS_TTY',
1300-
'-DENSURE_MSYSTEM_IS_SET',
13011300
'-DNATIVE_CRLF',
13021301
'-DNOGDI',
13031302
'-DNO_POSIX_GOODIES',
@@ -1307,6 +1306,18 @@ elif host_machine.system() == 'windows'
13071306
'-D__USE_MINGW_ANSI_STDIO=0',
13081307
]
13091308

1309+
msystem = get_option('msystem')
1310+
if msystem != ''
1311+
mingw_prefix = get_option('mingw_prefix')
1312+
if mingw_prefix == ''
1313+
mingw_prefix = '/' + msystem.to_lower()
1314+
endif
1315+
libgit_c_args += [
1316+
'-DENSURE_MSYSTEM_IS_SET="' + msystem + '"',
1317+
'-DMINGW_PREFIX="' + mingw_prefix + '"'
1318+
]
1319+
endif
1320+
13101321
libgit_dependencies += compiler.find_library('ntdll')
13111322
libgit_include_directories += 'compat/win32'
13121323
if compiler.get_id() == 'msvc'

meson_options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ option('runtime_prefix', type: 'boolean', value: false,
2121
description: 'Resolve ancillary tooling and support files relative to the location of the runtime binary instead of hard-coding them into the binary.')
2222
option('sane_tool_path', type: 'array', value: [],
2323
description: 'An array of paths to pick up tools from in case the normal tools are broken or lacking.')
24+
option('msystem', type: 'string', value: '',
25+
description: 'Fall-back on Windows when MSYSTEM is not set.')
26+
option('mingw_prefix', type: 'string', value: '',
27+
description: 'Fall-back on Windows when MINGW_PREFIX is not set.')
2428

2529
# Build information compiled into Git and other parts like documentation.
2630
option('build_date', type: 'string', value: '',

0 commit comments

Comments
 (0)