Skip to content

Commit

Permalink
Allow building Git for Windows with LLVM
Browse files Browse the repository at this point in the history
This is a work in progress. Will provide a proper commit message later.

Signed-off-by: Dennis Ameling <dennis@dennisameling.com>
  • Loading branch information
dennisameling committed Oct 23, 2021
1 parent 3f28c5f commit 9ca3275
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 6 deletions.
127 changes: 127 additions & 0 deletions .github/workflows/llvm-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: LLVM build

on:
pull_request:

env:
LLVM_VERSION: 20210423
LLVM_TYPE: msvcrt
VCPKG_VERSION_FOR_CACHE: 1
DEVELOPER: 1

jobs:
vcpkg:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
arch: [arm64, x64]
steps:
- uses: actions/checkout@v2
- shell: cmd
run: where windres
- 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: initialize vcpkg
uses: actions/checkout@v2
with:
repository: 'dennisameling/vcpkg'
ref: 'llvm-mingw-clang'
path: 'compat/vcbuild/vcpkg'
- name: Cache vcpkg artifacts
id: cache-vcpkg
uses: actions/cache@v2
with:
path: compat/vcbuild/vcpkg/installed
key: vcpkg-cache-${{ env.VCPKG_VERSION_FOR_CACHE }}-${{ matrix.arch }}-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}
- name: build packages
if: steps.cache-vcpkg.outputs.cache-hit != 'true'
shell: pwsh
run: .\compat\vcbuild\vcpkg_install.bat ${{ matrix.arch }}-windows-llvm-mingw
env:
# Temp workaround to get the paths to work
LLVM_PATH: D:/a/git/git/llvm-build/llvm-mingw-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}-x86_64
VCPKG_ROOT: D:/a/git/git/compat/vcbuild/vcpkg
VCPKG_KEEP_ENV_VARS: "LLVM_PATH;VCPKG_ROOT"
- name: upload vcpkg artifacts
uses: actions/upload-artifact@v2
with:
name: vcpkg-artifacts-${{ matrix.arch }}
path: compat/vcbuild/vcpkg/installed

llvm-build:
needs: vcpkg
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
- arch: arm64
compilerArch: aarch64
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: initialize vcpkg
uses: actions/checkout@v2
with:
repository: 'microsoft/vcpkg'
path: 'compat/vcbuild/vcpkg'
- name: download vcpkg artifacts
uses: actions/download-artifact@v2
with:
name: vcpkg-artifacts-${{ matrix.arch }}
path: compat/vcbuild/vcpkg/installed
- name: copy dlls to root
shell: cmd
run: compat\vcbuild\vcpkg_copy_dlls.bat release ${{ matrix.arch }}-windows-llvm-mingw
- shell: bash
run: |
mkdir `pwd`/artifacts
cmake `pwd`/contrib/buildsystems/ -DCMAKE_PREFIX_PATH=`pwd`/compat/vcbuild/vcpkg/installed/${{ matrix.arch }}-windows-llvm-mingw -DVCPKG_ARCH=${{ matrix.arch }}-windows-llvm-mingw \
-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_INSTALL_PREFIX=`pwd`/artifacts -G "MinGW Makefiles"
- shell: pwsh
run: make -j2
- shell: pwsh
run: make install
- name: Copy DLLs
shell: bash
# Workaround to get the DLLs into the installation directory
run: |
cp `pwd`/compat/vcbuild/vcpkg/installed/${{ matrix.arch }}-windows-llvm-mingw/bin/*.dll `pwd`/artifacts/bin
cp `pwd`/compat/vcbuild/vcpkg/installed/${{ matrix.arch }}-windows-llvm-mingw/bin/*.dll `pwd`/artifacts/libexec/git-core
- name: upload build artifacts
uses: actions/upload-artifact@v2
with:
name: llvm-artifacts-${{ matrix.arch }}
path: artifacts
9 changes: 5 additions & 4 deletions compat/vcbuild/vcpkg_install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +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
powershell -exec bypass scripts\bootstrap.ps1
Expand Down
5 changes: 3 additions & 2 deletions contrib/buildsystems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ endif()

#Platform Specific
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "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()
Expand Down Expand Up @@ -715,7 +715,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

0 comments on commit 9ca3275

Please sign in to comment.