Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enable building Git for Windows with LLVM/Clang #3427

Closed
Closed
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
99 changes: 72 additions & 27 deletions .github/workflows/git-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ env:
BUILD_ONLY: "${{github.event.inputs.build_only}}"
REPOSITORY: "${{github.event.inputs.repository}}"
REF: "${{github.event.inputs.ref}}"
LLVM_VERSION: 20211002
LLVM_TYPE: msvcrt
VCPKG_VERSION_FOR_CACHE: 1

jobs:
bundle-artifacts:
Expand Down Expand Up @@ -200,9 +203,9 @@ jobs:
printf '#!/bin/sh\n\nexec /mingw64/bin/git.exe "$@"\n' >/usr/bin/git &&

# Restrict `PATH` to MSYS2 and to Visual Studio (to let `cv2pdb` find the relevant DLLs)
PATH="/mingw64/bin:/usr/bin:/C/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin${{matrix.arch.bin}}:/C/Windows/system32"
PATH="/mingw64/bin:/usr/bin:/C/Windows/system32"

type -p mspdb140.dll || exit 1
# type -p mspdb140.dll || exit 1
sh -x /usr/src/build-extra/please.sh build-mingw-w64-git --only-${{matrix.arch.bitness}}-bit --build-src-pkg -o artifacts HEAD &&
cp bundle-artifacts/ver artifacts/ &&
if test -n "$GPGKEY"
Expand Down Expand Up @@ -268,43 +271,85 @@ jobs:
git remote add -f origin https://github.com/git-for-windows/git &&
git fetch --tags bundle-artifacts/git.bundle $(cat bundle-artifacts/next_version) &&
git reset --hard $(cat bundle-artifacts/next_version)
- name: initialize vcpkg
- name: Set LLVM path
if: env.SKIP != 'true'
uses: actions/checkout@v2
shell: bash
run: echo "LLVM_PATH=`pwd`/llvm-build/llvm-mingw-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}-x86_64" >> $GITHUB_ENV
- name: Cache LLVM
if: env.SKIP != 'true'
id: cache-llvm
uses: actions/cache@v2
with:
repository: 'microsoft/vcpkg'
path: 'compat/vcbuild/vcpkg'
- name: download vcpkg artifacts
path: llvm-build
key: llvm-build-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}
- shell: pwsh
if: steps.cache-llvm.outputs.cache-hit != 'true' && env.SKIP != 'true'
run: |
Invoke-WebRequest -Uri "https://github.com/mstorsjo/llvm-mingw/releases/download/${{ env.LLVM_VERSION }}/llvm-mingw-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}-x86_64.zip" -OutFile "./llvm.zip"
Expand-Archive -LiteralPath './llvm.zip' -DestinationPath ./llvm-build
- name: Setup MSYS2
if: env.SKIP != 'true'
uses: git-for-windows/get-azure-pipelines-artifact@v0
uses: msys2/setup-msys2@v2
with:
repository: git/git
definitionId: 9
- name: add msbuild to PATH
msystem: MSYS
- name: Add clangarm64 server
if: env.SKIP != 'true'
uses: microsoft/setup-msbuild@v1
- name: copy dlls to root
shell: msys2 {0}
run: |
cat <<EOF >> /etc/pacman.conf
[clangarm64]
Server = https://mirror.msys2.org/mingw/clangarm64/
EOF
- name: Update package database with arm64 entries
if: env.SKIP != 'true'
shell: powershell
shell: msys2 {0}
run: pacman -Sy
- name: Install packages
if: env.SKIP != 'true'
shell: msys2 {0}
run: |
& compat\vcbuild\vcpkg_copy_dlls.bat release arm64-windows
if (!$?) { exit(1) }
- name: generate Visual Studio solution
pacman -S --noconfirm mingw-w64-clang-aarch64-openssl mingw-w64-clang-aarch64-zlib \
mingw-w64-clang-aarch64-curl mingw-w64-clang-aarch64-expat \
mingw-w64-clang-aarch64-libiconv mingw-w64-clang-aarch64-toolchain
- name: Set MSYS2 root as env variable
if: env.SKIP != 'true'
shell: bash
shell: msys2 {0}
run: echo "MSYS_ROOT=$(cygpath -m /)" >> $GITHUB_ENV
- shell: bash
if: env.SKIP != 'true'
# We need to remove mingw32-make.exe (which is arm64-native) as it clashes with cmake
run: |
cmake `pwd`/contrib/buildsystems/ -DCMAKE_PREFIX_PATH=`pwd`/compat/vcbuild/vcpkg/installed/arm64-windows \
-DNO_GETTEXT=YesPlease -DPERL_TESTS=OFF -DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON -DCMAKE_GENERATOR_PLATFORM=arm64 -DVCPKG_ARCH=arm64-windows \
-DCMAKE_INSTALL_PREFIX="`pwd`/git-arm64" -DSKIP_DASHED_BUILT_INS=ON -DHOST_CPU=arm64
- name: MSBuild
rm ${{ env.MSYS_ROOT }}clangarm64/bin/mingw32-make.exe
mkdir `pwd`/git-arm64
cmake `pwd`/contrib/buildsystems/ -DCMAKE_PREFIX_PATH=${{ env.MSYS_ROOT }}clangarm64 -DNO_GETTEXT=YesPlease \
-DPERL_TESTS=OFF -DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON \
-DCMAKE_C_COMPILER=${{ env.LLVM_PATH }}/bin/aarch64-w64-mingw32-clang.exe \
-DCMAKE_CXX_COMPILER=${{ env.LLVM_PATH }}/bin/aarch64-w64-mingw32-clang++.exe \
-DCMAKE_RC_COMPILER=${{ env.LLVM_PATH }}/bin/aarch64-w64-mingw32-windres.exe \
-DCMAKE_INSTALL_PREFIX=`pwd`/git-arm64 -DSKIP_DASHED_BUILT_INS=ON -DHOST_CPU=arm64 -DUSE_VCPKG=OFF -G "MinGW Makefiles"
- shell: pwsh
if: env.SKIP != 'true'
run: msbuild git.sln -property:Configuration=Release
- name: Link the Git executables
run: make -j2
- shell: pwsh
if: env.SKIP != 'true'
run: msbuild INSTALL.vcxproj -property:Configuration=Release
run: make install
# Workaround to get the DLLs into the installation directory
- name: Copy DLLs
if: env.SKIP != 'true'
shell: msys2 {0}
run: |
DLLS="libbrotlicommon.dll libbrotlidec.dll libcrypto-1_1.dll libcurl-4.dll libexpat-1.dll \
libiconv-2.dll libidn2-0.dll libintl-8.dll libnghttp2-14.dll libpsl-5.dll libssh2-1.dll \
libssl-1_1.dll libunistring-2.dll libwinpthread-1.dll libzstd.dll zlib1.dll"

for ITEM in ${DLLS}
do
cp /clangarm64/bin/${ITEM} `pwd`/git-arm64/bin
cp /clangarm64/bin/${ITEM} `pwd`/git-arm64/libexec/git-core
done
- name: upload build artifacts
if: env.SKIP != 'true'
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v2
with:
name: arm64-artifacts
path: ./git-arm64
Expand Down Expand Up @@ -433,7 +478,7 @@ jobs:
fi &&
openssl dgst -sha256 artifacts/${{matrix.artifact.fileprefix}}-*.${{matrix.artifact.fileextension}} | sed "s/.* //" >artifacts/sha-256.txt
- name: Copy package-versions and pdbs
if: env.SKIP != 'true' && matrix.artifact.name == 'installer'
if: env.SKIP != 'true' && matrix.artifact.name == 'installer' && 'skipThisForNow' == 'dummy'
shell: bash
run: |
cp /usr/src/build-extra/installer/package-versions.txt artifacts/ &&
Expand Down
100 changes: 100 additions & 0 deletions .github/workflows/llvm-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: LLVM build

on:
pull_request:

env:
LLVM_VERSION: 20211002
LLVM_TYPE: msvcrt
DEVELOPER: 1

jobs:
llvm-build:
runs-on: windows-latest
env:
NO_PERL: 1
GIT_CONFIG_PARAMETERS: "'user.name=CI' 'user.email=ci@git'"
strategy:
fail-fast: false
matrix:
include:
- arch: x64
compilerArch: x86_64
msysArch: clang64
- arch: arm64
compilerArch: aarch64
msysArch: clangarm64
steps:
- uses: actions/checkout@v2
- name: Set LLVM path
shell: bash
run: echo "LLVM_PATH=`pwd`/llvm-build/llvm-mingw-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}-x86_64" >> $GITHUB_ENV
- name: Cache LLVM
id: cache-llvm
uses: actions/cache@v2
with:
path: llvm-build
key: llvm-build-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}
- shell: pwsh
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
Invoke-WebRequest -Uri "https://github.com/mstorsjo/llvm-mingw/releases/download/${{ env.LLVM_VERSION }}/llvm-mingw-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}-x86_64.zip" -OutFile "./llvm.zip"
Expand-Archive -LiteralPath './llvm.zip' -DestinationPath ./llvm-build
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: MSYS
- name: Add clangarm64 server
if: matrix.msysArch == 'clangarm64'
shell: msys2 {0}
run: |
cat <<EOF >> /etc/pacman.conf
[clangarm64]
Server = https://mirror.msys2.org/mingw/clangarm64/
EOF
- name: Update package database with arm64 entries
if: matrix.msysArch == 'clangarm64'
shell: msys2 {0}
run: pacman -Sy
- name: Install packages
shell: msys2 {0}
run: |
pacman -S --noconfirm mingw-w64-clang-${{ matrix.compilerArch }}-openssl mingw-w64-clang-${{ matrix.compilerArch }}-zlib \
mingw-w64-clang-${{ matrix.compilerArch }}-curl mingw-w64-clang-${{ matrix.compilerArch }}-expat \
mingw-w64-clang-${{ matrix.compilerArch }}-libiconv mingw-w64-clang-${{ matrix.compilerArch }}-toolchain
- name: Set MSYS2 root as env variable
shell: msys2 {0}
run: echo "MSYS_ROOT=$(cygpath -m /)" >> $GITHUB_ENV
- shell: bash
# We need to remove mingw32-make.exe (which is arm64-native) as it clashes with cmake
run: |
rm ${{ env.MSYS_ROOT }}${{ matrix.msysArch }}/bin/mingw32-make.exe
mkdir `pwd`/artifacts
cmake `pwd`/contrib/buildsystems/ -DCMAKE_PREFIX_PATH=${{ env.MSYS_ROOT }}${{ matrix.msysArch }} -DNO_GETTEXT=YesPlease \
-DPERL_TESTS=OFF -DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON \
-DCMAKE_C_COMPILER=${{ env.LLVM_PATH }}/bin/${{ matrix.compilerArch }}-w64-mingw32-clang.exe \
-DCMAKE_CXX_COMPILER=${{ env.LLVM_PATH }}/bin/${{ matrix.compilerArch }}-w64-mingw32-clang++.exe \
-DCMAKE_RC_COMPILER=${{ env.LLVM_PATH }}/bin/${{ matrix.compilerArch }}-w64-mingw32-windres.exe \
-DCMAKE_INSTALL_PREFIX=`pwd`/artifacts -DSKIP_DASHED_BUILT_INS=ON -DHOST_CPU=${{ matrix.arch }} -DUSE_VCPKG=OFF -G "MinGW Makefiles"
- shell: pwsh
run: make -j2
- shell: pwsh
run: make install
# Workaround to get the DLLs into the installation directory
- name: Copy DLLs
shell: msys2 {0}
run: |
DLLS="libbrotlicommon.dll libbrotlidec.dll libcrypto-1_1.dll libcurl-4.dll libexpat-1.dll \
libiconv-2.dll libidn2-0.dll libintl-8.dll libnghttp2-14.dll libpsl-5.dll libssh2-1.dll \
libssl-1_1.dll libunistring-2.dll libwinpthread-1.dll libzstd.dll zlib1.dll"

for ITEM in ${DLLS}
do
cp /${{ matrix.msysArch }}/bin/${ITEM} `pwd`/artifacts/bin
cp /${{ matrix.msysArch }}/bin/${ITEM} `pwd`/artifacts/libexec/git-core
done
- name: upload build artifacts
uses: actions/upload-artifact@v2
with:
name: llvm-artifacts-${{ matrix.arch }}
path: artifacts
6 changes: 6 additions & 0 deletions compat/bswap.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ static inline uint64_t git_bswap64(uint64_t x)
}
#endif

/* available since Clang 12 and GCC 10, i.a. needed for ARM64/aarch64 on Windows */
#elif defined(__has_builtin) && __has_builtin(__builtin_bswap64)

#define bswap32(x) __builtin_bswap32((x))
#define bswap64(x) __builtin_bswap64((x))

#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM64))

#include <stdlib.h>
Expand Down
8 changes: 5 additions & 3 deletions compat/vcbuild/vcpkg_install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ REM ================================================================
echo "***"
EXIT /B 1 )

echo Fetching vcpkg in %cwd%vcpkg
git.exe clone https://github.com/Microsoft/vcpkg vcpkg
IF ERRORLEVEL 1 ( EXIT /B 1 )
IF NOT EXIST vcpkg (
echo Fetching vcpkg in %cwd%vcpkg
git.exe clone https://github.com/Microsoft/vcpkg vcpkg
IF ERRORLEVEL 1 ( EXIT /B 1 )
)

cd vcpkg
echo Building vcpkg
Expand Down
20 changes: 13 additions & 7 deletions contrib/buildsystems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,13 @@ endif()


if(WIN32 AND NOT MSVC)#not required for visual studio builds
find_program(WINDRES_EXE windres)
if(NOT WINDRES_EXE)
message(FATAL_ERROR "Install windres on Windows for resource files")
if(CMAKE_RC_COMPILER)
set(WINDRES_EXE ${CMAKE_RC_COMPILER})
else()
find_program(WINDRES_EXE windres)
if(NOT WINDRES_EXE)
message(FATAL_ERROR "Install windres on Windows for resource files")
endif()
endif()
endif()

Expand Down Expand Up @@ -276,20 +280,21 @@ endif()

#Platform Specific
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
# MinGW Makefiles is used by the llvm-mingw toolchain on Windows (Clang)
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR (NOT CMAKE_GENERATOR STREQUAL "MinGW Makefiles" AND CMAKE_C_COMPILER_ID STREQUAL "Clang"))
include_directories(${CMAKE_SOURCE_DIR}/compat/vcbuild/include)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
endif()
include_directories(${CMAKE_SOURCE_DIR}/compat/win32)
add_compile_definitions(HAVE_ALLOCA_H NO_POSIX_GOODIES NATIVE_CRLF NO_UNIX_SOCKETS WIN32
_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
OVERRIDE_STRDUP MMAP_PREVENTS_DELETE USE_WIN32_MMAP
UNICODE _UNICODE HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET)
list(APPEND compat_SOURCES compat/mingw.c compat/winansi.c compat/win32/path-utils.c
compat/win32/pthread.c compat/win32mmap.c compat/win32/syslog.c
compat/win32/trace2_win32_process_info.c compat/win32/dirent.c
compat/nedmalloc/nedmalloc.c compat/strdup.c compat/win32/fscache.c)
compat/strdup.c compat/win32/fscache.c)
set(NO_UNIX_SOCKETS 1)

elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
Expand Down Expand Up @@ -715,7 +720,8 @@ endif()
if(WIN32)
target_link_libraries(common-main ws2_32 ntdll ${CMAKE_BINARY_DIR}/git.res)
add_dependencies(common-main git-rc)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
# MinGW Makefiles is used by the llvm-mingw toolchain on Windows (Clang)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR (CMAKE_GENERATOR STREQUAL "MinGW Makefiles" AND CMAKE_C_COMPILER_ID STREQUAL "Clang"))
target_link_options(common-main PUBLIC -municode -Wl,--nxcompat -Wl,--dynamicbase -Wl,--pic-executable,-e,mainCRTStartup)
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
target_link_options(common-main PUBLIC -municode -Wl,-nxcompat -Wl,-dynamicbase -Wl,-entry:wmainCRTStartup -Wl,invalidcontinue.obj)
Expand Down
2 changes: 1 addition & 1 deletion git.rc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BEGIN
VALUE "InternalName", "git\0"
VALUE "OriginalFilename", "git.exe\0"
VALUE "ProductName", "Git\0"
VALUE "ProductVersion", GIT_VERSION "\0"
VALUE "ProductVersion", "DEMO\0"
END
END

Expand Down