Skip to content

Commit d483df2

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 b4057f1 commit d483df2

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
@@ -441,14 +441,8 @@ ifeq ($(uname_S),Windows)
441441
GIT_VERSION := $(GIT_VERSION).MSVC
442442
pathsep = ;
443443
# Assume that this is built in Git for Windows' SDK
444-
ifeq (MINGW32,$(MSYSTEM))
445-
prefix = /mingw32
446-
else
447-
ifeq (CLANGARM64,$(MSYSTEM))
448-
prefix = /clangarm64
449-
else
450-
prefix = /mingw64
451-
endif
444+
ifneq (,$(MSYSTEM))
445+
prefix = $(MINGW_PREFIX)
452446
endif
453447
# Prepend MSVC 64-bit tool-chain to PATH.
454448
#
@@ -736,6 +730,10 @@ ifeq ($(uname_S),MINGW)
736730
BASIC_LDFLAGS += -Wl,--dynamicbase
737731
endif
738732
ifneq (,$(MSYSTEM))
733+
ifeq ($(MINGW_PREFIX),$(filter-out /%,$(MINGW_PREFIX)))
734+
# Override if empty or does not start with a slash
735+
MINGW_PREFIX := /$(shell echo '$(MSYSTEM)' | tr A-Z a-z)
736+
endif
739737
prefix = $(MINGW_PREFIX)
740738
HOST_CPU = $(patsubst %-w64-mingw32,%,$(MINGW_CHOST))
741739
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
USE_NED_ALLOCATOR 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
@@ -1290,7 +1290,6 @@ elif host_machine.system() == 'windows'
12901290

12911291
libgit_c_args += [
12921292
'-DDETECT_MSYS_TTY',
1293-
'-DENSURE_MSYSTEM_IS_SET',
12941293
'-DNATIVE_CRLF',
12951294
'-DNOGDI',
12961295
'-DNO_POSIX_GOODIES',
@@ -1300,6 +1299,18 @@ elif host_machine.system() == 'windows'
13001299
'-D__USE_MINGW_ANSI_STDIO=0',
13011300
]
13021301

1302+
msystem = get_option('msystem')
1303+
if msystem != ''
1304+
mingw_prefix = get_option('mingw_prefix')
1305+
if mingw_prefix == ''
1306+
mingw_prefix = '/' + msystem.to_lower()
1307+
endif
1308+
libgit_c_args += [
1309+
'-DENSURE_MSYSTEM_IS_SET="' + msystem + '"',
1310+
'-DMINGW_PREFIX="' + mingw_prefix + '"'
1311+
]
1312+
endif
1313+
13031314
libgit_dependencies += compiler.find_library('ntdll')
13041315
libgit_include_directories += 'compat/win32'
13051316
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)