Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 `<mingw-prefix>\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;

Expand Down Expand Up @@ -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,
Expand Down
109 changes: 24 additions & 85 deletions config.mak.uname
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down Expand Up @@ -513,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
Expand All @@ -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
Expand Down Expand Up @@ -747,26 +743,25 @@ 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,-e,_mainCRTStartup
endif
ifeq (MINGW64,$(MSYSTEM))
prefix = /mingw64
HOST_CPU = x86_64
BASIC_LDFLAGS += -Wl,--pic-executable,-e,mainCRTStartup
else ifeq (CLANGARM64,$(MSYSTEM))
prefix = /clangarm64
HOST_CPU = aarch64
BASIC_LDFLAGS += -Wl,--pic-executable,-e,mainCRTStartup
else
COMPAT_CFLAGS += -D_USE_32BIT_TIME_T
BASIC_LDFLAGS += -Wl,--large-address-aware
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="\"$(MSYSTEM)\"" \
-DMINGW_PREFIX="\"$(patsubst /%,%,$(MINGW_PREFIX))\""
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
CC = gcc
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
Expand All @@ -776,62 +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
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/' \
<GIT-BUILD-OPTIONS >'$(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
Expand Down
9 changes: 8 additions & 1 deletion contrib/buildsystems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 10 additions & 16 deletions environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,25 @@ 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
#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;
1152;
#endif
#else
2048;
#endif
#endif

#ifndef PROTECT_HFS_DEFAULT
#define PROTECT_HFS_DEFAULT 0
Expand Down
13 changes: 12 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down
Loading