Skip to content

Commit e2bb15d

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 <johannes.schindelin@gmx.de>
1 parent d3acbe4 commit e2bb15d

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

config.mak.uname

Lines changed: 6 additions & 8 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
#
@@ -744,6 +738,10 @@ ifeq ($(uname_S),MINGW)
744738
BASIC_LDFLAGS += -Wl,--dynamicbase
745739
endif
746740
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
747745
prefix = $(MINGW_PREFIX)
748746
HOST_CPU = $(patsubst %-w64-mingw32,%,$(MINGW_CHOST))
749747
BASIC_LDFLAGS += -Wl,--pic-executable

contrib/buildsystems/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
256256
_CONSOLE DETECT_MSYS_TTY STRIP_EXTENSION=".exe" NO_SYMLINK_HEAD UNRELIABLE_FSTAT
257257
NOGDI OBJECT_CREATION_MODE=1 __USE_MINGW_ANSI_STDIO=0
258258
OVERRIDE_STRDUP MMAP_PREVENTS_DELETE USE_WIN32_MMAP
259-
HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET HAVE_RTLGENRANDOM)
259+
HAVE_WPGMPTR HAVE_RTLGENRANDOM)
260+
if(CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
261+
add_compile_definitions(ENSURE_MSYSTEM_IS_SET="MINGW64" MINGW_PREFIX="mingw64")
262+
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "arm64")
263+
add_compile_definitions(ENSURE_MSYSTEM_IS_SET="CLANGARM64" MINGW_PREFIX="clangarm64")
264+
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "x86")
265+
add_compile_definitions(ENSURE_MSYSTEM_IS_SET="MINGW32" MINGW_PREFIX="mingw32")
266+
endif()
260267
list(APPEND compat_SOURCES
261268
compat/mingw.c
262269
compat/winansi.c

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)