diff --git a/compat/mingw.c b/compat/mingw.c index 11173e6b2fd372..0a0ef922da148c 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -3613,6 +3613,10 @@ static size_t append_system_bin_dirs(char *path, size_t size) strip_suffix_mem(prefix, &len, "\\mingw64\\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, @@ -3718,9 +3722,13 @@ static void setup_windows_environment(void) char buf[32768]; size_t off = 0; - xsnprintf(buf, sizeof(buf), - "MINGW%d", (int)(sizeof(void *) * 8)); - setenv("MSYSTEM", buf, 1); +#if defined(__MINGW64__) || defined(_M_AMD64) + setenv("MSYSTEM", "MINGW64", 1); +#elif defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) + setenv("MSYSTEM", "CLANGARM64", 1); +#else + setenv("MSYSTEM", "MINGW32", 1); +#endif if (home) off += xsnprintf(buf + off, sizeof(buf) - off, diff --git a/environment.c b/environment.c index 9e4c7781be049a..cc853950bb24ca 100644 --- a/environment.c +++ b/environment.c @@ -82,9 +82,21 @@ int max_allowed_tree_depth = * the stack overflow can occur. */ 512; +#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; #else 2048; #endif +#endif #ifndef PROTECT_HFS_DEFAULT #define PROTECT_HFS_DEFAULT 0 diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index eb5cb6be7ee69a..5abfa202c19dca 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -621,30 +621,32 @@ test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' ' test_expect_success MINGW,RUNTIME_PREFIX 'MSYSTEM/PATH is adjusted if necessary' ' - mkdir -p "$HOME"/bin pretend/mingw64/bin \ - pretend/mingw64/libexec/git-core pretend/usr/bin && - cp "$GIT_EXEC_PATH"/git.exe pretend/mingw64/bin/ && - cp "$GIT_EXEC_PATH"/git.exe pretend/mingw64/libexec/git-core/ && + if test -z "$MINGW_PREFIX" + then + MINGW_PREFIX="/$(echo "${MSYSTEM:-MINGW64}" | tr A-Z a-z)" + fi && + mkdir -p "$HOME"/bin pretend"$MINGW_PREFIX"/bin \ + pretend"$MINGW_PREFIX"/libexec/git-core pretend/usr/bin && + cp "$GIT_EXEC_PATH"/git.exe pretend"$MINGW_PREFIX"/bin/ && + cp "$GIT_EXEC_PATH"/git.exe pretend"$MINGW_PREFIX"/libexec/git-core/ && # copy the .dll files, if any (happens when building via CMake) - case "$GIT_EXEC_PATH"/*.dll in - */"*.dll") ;; # no `.dll` files to be copied - *) - cp "$GIT_EXEC_PATH"/*.dll pretend/mingw64/bin/ && - cp "$GIT_EXEC_PATH"/*.dll pretend/mingw64/libexec/git-core/ - ;; - esac && + if test -n "$(ls "$GIT_EXEC_PATH"/*.dll 2>/dev/null)" + then + cp "$GIT_EXEC_PATH"/*.dll pretend"$MINGW_PREFIX"/bin/ && + cp "$GIT_EXEC_PATH"/*.dll pretend"$MINGW_PREFIX"/libexec/git-core/ + fi && echo "env | grep MSYSTEM=" | write_script "$HOME"/bin/git-test-home && - echo "echo mingw64" | write_script pretend/mingw64/bin/git-test-bin && + echo "echo ${MINGW_PREFIX#/}" | write_script pretend"$MINGW_PREFIX"/bin/git-test-bin && echo "echo usr" | write_script pretend/usr/bin/git-test-bin2 && ( MSYSTEM= && GIT_EXEC_PATH= && - pretend/mingw64/libexec/git-core/git.exe test-home >actual && - pretend/mingw64/libexec/git-core/git.exe test-bin >>actual && - pretend/mingw64/bin/git.exe test-bin2 >>actual + pretend"$MINGW_PREFIX"/libexec/git-core/git.exe test-home >actual && + pretend"$MINGW_PREFIX"/libexec/git-core/git.exe test-bin >>actual && + pretend"$MINGW_PREFIX"/bin/git.exe test-bin2 >>actual ) && - test_write_lines MSYSTEM=$MSYSTEM mingw64 usr >expect && + test_write_lines MSYSTEM=$MSYSTEM "${MINGW_PREFIX#/}" usr >expect && test_cmp expect actual '