Skip to content

Commit 9ca3275

Browse files
committed
Allow building Git for Windows with LLVM
This is a work in progress. Will provide a proper commit message later. Signed-off-by: Dennis Ameling <[email protected]>
1 parent 3f28c5f commit 9ca3275

File tree

3 files changed

+135
-6
lines changed

3 files changed

+135
-6
lines changed

.github/workflows/llvm-build.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: LLVM build
2+
3+
on:
4+
pull_request:
5+
6+
env:
7+
LLVM_VERSION: 20210423
8+
LLVM_TYPE: msvcrt
9+
VCPKG_VERSION_FOR_CACHE: 1
10+
DEVELOPER: 1
11+
12+
jobs:
13+
vcpkg:
14+
runs-on: windows-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
arch: [arm64, x64]
19+
steps:
20+
- uses: actions/checkout@v2
21+
- shell: cmd
22+
run: where windres
23+
- name: Set LLVM path
24+
shell: bash
25+
run: echo "LLVM_PATH=`pwd`/llvm-build/llvm-mingw-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}-x86_64" >> $GITHUB_ENV
26+
- name: Cache LLVM
27+
id: cache-llvm
28+
uses: actions/cache@v2
29+
with:
30+
path: llvm-build
31+
key: llvm-build-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}
32+
- shell: pwsh
33+
if: steps.cache-llvm.outputs.cache-hit != 'true'
34+
run: |
35+
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"
36+
Expand-Archive -LiteralPath './llvm.zip' -DestinationPath ./llvm-build
37+
- name: initialize vcpkg
38+
uses: actions/checkout@v2
39+
with:
40+
repository: 'dennisameling/vcpkg'
41+
ref: 'llvm-mingw-clang'
42+
path: 'compat/vcbuild/vcpkg'
43+
- name: Cache vcpkg artifacts
44+
id: cache-vcpkg
45+
uses: actions/cache@v2
46+
with:
47+
path: compat/vcbuild/vcpkg/installed
48+
key: vcpkg-cache-${{ env.VCPKG_VERSION_FOR_CACHE }}-${{ matrix.arch }}-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}
49+
- name: build packages
50+
if: steps.cache-vcpkg.outputs.cache-hit != 'true'
51+
shell: pwsh
52+
run: .\compat\vcbuild\vcpkg_install.bat ${{ matrix.arch }}-windows-llvm-mingw
53+
env:
54+
# Temp workaround to get the paths to work
55+
LLVM_PATH: D:/a/git/git/llvm-build/llvm-mingw-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}-x86_64
56+
VCPKG_ROOT: D:/a/git/git/compat/vcbuild/vcpkg
57+
VCPKG_KEEP_ENV_VARS: "LLVM_PATH;VCPKG_ROOT"
58+
- name: upload vcpkg artifacts
59+
uses: actions/upload-artifact@v2
60+
with:
61+
name: vcpkg-artifacts-${{ matrix.arch }}
62+
path: compat/vcbuild/vcpkg/installed
63+
64+
llvm-build:
65+
needs: vcpkg
66+
runs-on: windows-latest
67+
env:
68+
NO_PERL: 1
69+
GIT_CONFIG_PARAMETERS: "'user.name=CI' 'user.email=ci@git'"
70+
strategy:
71+
fail-fast: false
72+
matrix:
73+
include:
74+
- arch: x64
75+
compilerArch: x86_64
76+
- arch: arm64
77+
compilerArch: aarch64
78+
steps:
79+
- uses: actions/checkout@v2
80+
- name: Set LLVM path
81+
shell: bash
82+
run: echo "LLVM_PATH=`pwd`/llvm-build/llvm-mingw-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}-x86_64" >> $GITHUB_ENV
83+
- name: Cache LLVM
84+
id: cache-llvm
85+
uses: actions/cache@v2
86+
with:
87+
path: llvm-build
88+
key: llvm-build-${{ env.LLVM_VERSION }}-${{ env.LLVM_TYPE }}
89+
- shell: pwsh
90+
if: steps.cache-llvm.outputs.cache-hit != 'true'
91+
run: |
92+
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"
93+
Expand-Archive -LiteralPath './llvm.zip' -DestinationPath ./llvm-build
94+
- name: initialize vcpkg
95+
uses: actions/checkout@v2
96+
with:
97+
repository: 'microsoft/vcpkg'
98+
path: 'compat/vcbuild/vcpkg'
99+
- name: download vcpkg artifacts
100+
uses: actions/download-artifact@v2
101+
with:
102+
name: vcpkg-artifacts-${{ matrix.arch }}
103+
path: compat/vcbuild/vcpkg/installed
104+
- name: copy dlls to root
105+
shell: cmd
106+
run: compat\vcbuild\vcpkg_copy_dlls.bat release ${{ matrix.arch }}-windows-llvm-mingw
107+
- shell: bash
108+
run: |
109+
mkdir `pwd`/artifacts
110+
cmake `pwd`/contrib/buildsystems/ -DCMAKE_PREFIX_PATH=`pwd`/compat/vcbuild/vcpkg/installed/${{ matrix.arch }}-windows-llvm-mingw -DVCPKG_ARCH=${{ matrix.arch }}-windows-llvm-mingw \
111+
-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 \
112+
-DCMAKE_CXX_COMPILER=${{ env.LLVM_PATH }}/bin/${{ matrix.compilerArch }}-w64-mingw32-clang++.exe -DCMAKE_INSTALL_PREFIX=`pwd`/artifacts -G "MinGW Makefiles"
113+
- shell: pwsh
114+
run: make -j2
115+
- shell: pwsh
116+
run: make install
117+
- name: Copy DLLs
118+
shell: bash
119+
# Workaround to get the DLLs into the installation directory
120+
run: |
121+
cp `pwd`/compat/vcbuild/vcpkg/installed/${{ matrix.arch }}-windows-llvm-mingw/bin/*.dll `pwd`/artifacts/bin
122+
cp `pwd`/compat/vcbuild/vcpkg/installed/${{ matrix.arch }}-windows-llvm-mingw/bin/*.dll `pwd`/artifacts/libexec/git-core
123+
- name: upload build artifacts
124+
uses: actions/upload-artifact@v2
125+
with:
126+
name: llvm-artifacts-${{ matrix.arch }}
127+
path: artifacts

compat/vcbuild/vcpkg_install.bat

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ REM ================================================================
4949
echo "***"
5050
EXIT /B 1 )
5151

52-
echo Fetching vcpkg in %cwd%vcpkg
53-
git.exe clone https://github.com/Microsoft/vcpkg vcpkg
54-
IF ERRORLEVEL 1 ( EXIT /B 1 )
55-
52+
IF NOT EXIST vcpkg (
53+
echo Fetching vcpkg in %cwd%vcpkg
54+
git.exe clone https://github.com/Microsoft/vcpkg vcpkg
55+
IF ERRORLEVEL 1 ( EXIT /B 1 )
56+
)
5657
cd vcpkg
5758
echo Building vcpkg
5859
powershell -exec bypass scripts\bootstrap.ps1

contrib/buildsystems/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ endif()
276276

277277
#Platform Specific
278278
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
279-
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
279+
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR (NOT CMAKE_GENERATOR STREQUAL "MinGW Makefiles" AND CMAKE_C_COMPILER_ID STREQUAL "Clang"))
280280
include_directories(${CMAKE_SOURCE_DIR}/compat/vcbuild/include)
281281
add_compile_definitions(_CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
282282
endif()
@@ -715,7 +715,8 @@ endif()
715715
if(WIN32)
716716
target_link_libraries(common-main ws2_32 ntdll ${CMAKE_BINARY_DIR}/git.res)
717717
add_dependencies(common-main git-rc)
718-
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
718+
# MinGW Makefiles is used by the llvm-mingw toolchain on Windows (Clang)
719+
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR (CMAKE_GENERATOR STREQUAL "MinGW Makefiles" AND CMAKE_C_COMPILER_ID STREQUAL "Clang"))
719720
target_link_options(common-main PUBLIC -municode -Wl,--nxcompat -Wl,--dynamicbase -Wl,--pic-executable,-e,mainCRTStartup)
720721
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
721722
target_link_options(common-main PUBLIC -municode -Wl,-nxcompat -Wl,-dynamicbase -Wl,-entry:wmainCRTStartup -Wl,invalidcontinue.obj)

0 commit comments

Comments
 (0)