Skip to content

Commit 773e41c

Browse files
authored
clangarm64: let the tests pass! (#5586)
I encountered these issues that had hitherto escaped us [when I worked on letting the `ci-artifacts` workflow in git-sdk-arm64 also build Git and run the test suite](git-for-windows/git-sdk-arm64#37) by way of validating the `minimal-sdk` artifact. Mind, this PR does not only adjust a test case that was previously too fixated on x86_64. There are two real issues that this PR addresses and that were found via the test suite: - When the environment variable `MSYSTEM` is not yet set, it now is set appropriately even on Windows/ARM64 (and the `PATH` is adjusted accordingly). - The tree traversal limit designed to avoid stack overflows needed to be adjusted for the clangarm64 builds.
2 parents 7a18c63 + 2c3b779 commit 773e41c

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

compat/mingw.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,10 @@ static size_t append_system_bin_dirs(char *path, size_t size)
36133613
strip_suffix_mem(prefix, &len, "\\mingw64\\bin"))
36143614
off += xsnprintf(path + off, size - off,
36153615
"%.*s\\mingw64\\bin;", (int)len, prefix);
3616+
else if (strip_suffix_mem(prefix, &len, "\\clangarm64\\libexec\\git-core") ||
3617+
strip_suffix_mem(prefix, &len, "\\clangarm64\\bin"))
3618+
off += xsnprintf(path + off, size - off,
3619+
"%.*s\\clangarm64\\bin;", (int)len, prefix);
36163620
else if (strip_suffix_mem(prefix, &len, "\\mingw32\\libexec\\git-core") ||
36173621
strip_suffix_mem(prefix, &len, "\\mingw32\\bin"))
36183622
off += xsnprintf(path + off, size - off,
@@ -3718,9 +3722,13 @@ static void setup_windows_environment(void)
37183722
char buf[32768];
37193723
size_t off = 0;
37203724

3721-
xsnprintf(buf, sizeof(buf),
3722-
"MINGW%d", (int)(sizeof(void *) * 8));
3723-
setenv("MSYSTEM", buf, 1);
3725+
#if defined(__MINGW64__) || defined(_M_AMD64)
3726+
setenv("MSYSTEM", "MINGW64", 1);
3727+
#elif defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
3728+
setenv("MSYSTEM", "CLANGARM64", 1);
3729+
#else
3730+
setenv("MSYSTEM", "MINGW32", 1);
3731+
#endif
37243732

37253733
if (home)
37263734
off += xsnprintf(buf + off, sizeof(buf) - off,

environment.c

+12
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,21 @@ int max_allowed_tree_depth =
8282
* the stack overflow can occur.
8383
*/
8484
512;
85+
#else
86+
#if defined(GIT_WINDOWS_NATIVE) && defined(__clang__) && defined(__aarch64__)
87+
/*
88+
* Similar to Visual C, it seems that on Windows/ARM64 the clang-based
89+
* builds have a smaller stack space available. When running out of
90+
* that stack space, a `STATUS_STACK_OVERFLOW` is produced. When the
91+
* Git command was run from an MSYS2 Bash, this unfortunately results
92+
* in an exit code 127. Let's prevent that by lowering the maximal
93+
* tree depth; This value seems to be low enough.
94+
*/
95+
1280;
8596
#else
8697
2048;
8798
#endif
99+
#endif
88100

89101
#ifndef PROTECT_HFS_DEFAULT
90102
#define PROTECT_HFS_DEFAULT 0

t/t0060-path-utils.sh

+18-16
Original file line numberDiff line numberDiff line change
@@ -621,30 +621,32 @@ test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works'
621621
'
622622

623623
test_expect_success MINGW,RUNTIME_PREFIX 'MSYSTEM/PATH is adjusted if necessary' '
624-
mkdir -p "$HOME"/bin pretend/mingw64/bin \
625-
pretend/mingw64/libexec/git-core pretend/usr/bin &&
626-
cp "$GIT_EXEC_PATH"/git.exe pretend/mingw64/bin/ &&
627-
cp "$GIT_EXEC_PATH"/git.exe pretend/mingw64/libexec/git-core/ &&
624+
if test -z "$MINGW_PREFIX"
625+
then
626+
MINGW_PREFIX="/$(echo "${MSYSTEM:-MINGW64}" | tr A-Z a-z)"
627+
fi &&
628+
mkdir -p "$HOME"/bin pretend"$MINGW_PREFIX"/bin \
629+
pretend"$MINGW_PREFIX"/libexec/git-core pretend/usr/bin &&
630+
cp "$GIT_EXEC_PATH"/git.exe pretend"$MINGW_PREFIX"/bin/ &&
631+
cp "$GIT_EXEC_PATH"/git.exe pretend"$MINGW_PREFIX"/libexec/git-core/ &&
628632
# copy the .dll files, if any (happens when building via CMake)
629-
case "$GIT_EXEC_PATH"/*.dll in
630-
*/"*.dll") ;; # no `.dll` files to be copied
631-
*)
632-
cp "$GIT_EXEC_PATH"/*.dll pretend/mingw64/bin/ &&
633-
cp "$GIT_EXEC_PATH"/*.dll pretend/mingw64/libexec/git-core/
634-
;;
635-
esac &&
633+
if test -n "$(ls "$GIT_EXEC_PATH"/*.dll 2>/dev/null)"
634+
then
635+
cp "$GIT_EXEC_PATH"/*.dll pretend"$MINGW_PREFIX"/bin/ &&
636+
cp "$GIT_EXEC_PATH"/*.dll pretend"$MINGW_PREFIX"/libexec/git-core/
637+
fi &&
636638
echo "env | grep MSYSTEM=" | write_script "$HOME"/bin/git-test-home &&
637-
echo "echo mingw64" | write_script pretend/mingw64/bin/git-test-bin &&
639+
echo "echo ${MINGW_PREFIX#/}" | write_script pretend"$MINGW_PREFIX"/bin/git-test-bin &&
638640
echo "echo usr" | write_script pretend/usr/bin/git-test-bin2 &&
639641
640642
(
641643
MSYSTEM= &&
642644
GIT_EXEC_PATH= &&
643-
pretend/mingw64/libexec/git-core/git.exe test-home >actual &&
644-
pretend/mingw64/libexec/git-core/git.exe test-bin >>actual &&
645-
pretend/mingw64/bin/git.exe test-bin2 >>actual
645+
pretend"$MINGW_PREFIX"/libexec/git-core/git.exe test-home >actual &&
646+
pretend"$MINGW_PREFIX"/libexec/git-core/git.exe test-bin >>actual &&
647+
pretend"$MINGW_PREFIX"/bin/git.exe test-bin2 >>actual
646648
) &&
647-
test_write_lines MSYSTEM=$MSYSTEM mingw64 usr >expect &&
649+
test_write_lines MSYSTEM=$MSYSTEM "${MINGW_PREFIX#/}" usr >expect &&
648650
test_cmp expect actual
649651
'
650652

0 commit comments

Comments
 (0)