Skip to content

Commit 6aa2cea

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 e30502c commit 6aa2cea

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
@@ -442,14 +442,8 @@ ifeq ($(uname_S),Windows)
442442
GIT_VERSION := $(GIT_VERSION).MSVC
443443
pathsep = ;
444444
# Assume that this is built in Git for Windows' SDK
445-
ifeq (MINGW32,$(MSYSTEM))
446-
prefix = /mingw32
447-
else
448-
ifeq (CLANGARM64,$(MSYSTEM))
449-
prefix = /clangarm64
450-
else
451-
prefix = /mingw64
452-
endif
445+
ifneq (,$(MSYSTEM))
446+
prefix = $(MINGW_PREFIX)
453447
endif
454448
# Prepend MSVC 64-bit tool-chain to PATH.
455449
#
@@ -734,6 +728,10 @@ ifeq ($(uname_S),MINGW)
734728
BASIC_LDFLAGS += -Wl,--dynamicbase
735729
endif
736730
ifneq (,$(MSYSTEM))
731+
ifeq ($(MINGW_PREFIX),$(filter-out /%,$(MINGW_PREFIX)))
732+
# Override if empty or does not start with a slash
733+
MINGW_PREFIX := /$(shell echo '$(MSYSTEM)' | tr A-Z a-z)
734+
endif
737735
prefix = $(MINGW_PREFIX)
738736
HOST_CPU = $(patsubst %-w64-mingw32,%,$(MINGW_CHOST))
739737
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
@@ -1295,7 +1295,6 @@ elif host_machine.system() == 'windows'
12951295

12961296
libgit_c_args += [
12971297
'-DDETECT_MSYS_TTY',
1298-
'-DENSURE_MSYSTEM_IS_SET',
12991298
'-DNATIVE_CRLF',
13001299
'-DNOGDI',
13011300
'-DNO_POSIX_GOODIES',
@@ -1305,6 +1304,18 @@ elif host_machine.system() == 'windows'
13051304
'-D__USE_MINGW_ANSI_STDIO=0',
13061305
]
13071306

1307+
msystem = get_option('msystem')
1308+
if msystem != ''
1309+
mingw_prefix = get_option('mingw_prefix')
1310+
if mingw_prefix == ''
1311+
mingw_prefix = '/' + msystem.to_lower()
1312+
endif
1313+
libgit_c_args += [
1314+
'-DENSURE_MSYSTEM_IS_SET="' + msystem + '"',
1315+
'-DMINGW_PREFIX="' + mingw_prefix + '"'
1316+
]
1317+
endif
1318+
13081319
libgit_dependencies += compiler.find_library('ntdll')
13091320
libgit_include_directories += 'compat/win32'
13101321
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)