Skip to content

Commit d86323d

Browse files
authored
CI: Refactor LLVM setup steps and use cache (microsoft#1242)
1 parent da5579c commit d86323d

3 files changed

Lines changed: 105 additions & 42 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: 'Set up llvm-mingw toolchain'
2+
description: 'Set up llvm-mingw toolchain'
3+
inputs:
4+
llvm-mingw-version:
5+
description: 'llvm-mingw version'
6+
required: true
7+
default: '20220906'
8+
host-arch:
9+
description: 'llvm-mingw toolchain host architecture (e.g. i686, x86_64)'
10+
required: true
11+
default: 'x86_64'
12+
outputs:
13+
llvm-path:
14+
description: "The path in which llvm-mingw is installed to"
15+
value: ${{ steps.setup-llvm.outputs.llvm-path }}
16+
runs:
17+
using: "composite"
18+
steps:
19+
- name: Cache llvm-mingw
20+
id: cache-llvm
21+
uses: actions/cache@v3
22+
with:
23+
path: .llvm-mingw
24+
key: llvm-mingw-${{ runner.os }}-${{ inputs.llvm-mingw-version }}-${{ inputs.host-arch }}
25+
26+
- name: Install llvm-mingw ${{ inputs.llvm-mingw-version }} (${{ inputs.host-arch }})
27+
if: steps.cache-llvm.outputs.cache-hit != 'true'
28+
shell: pwsh
29+
run: |
30+
$llvm_mingw_version = "${{ inputs.llvm-mingw-version }}"
31+
$llvm_arch = "${{ inputs.host-arch }}"
32+
Invoke-WebRequest "https://github.com/mstorsjo/llvm-mingw/releases/download/${llvm_mingw_version}/llvm-mingw-${llvm_mingw_version}-ucrt-${llvm_arch}.zip" -OutFile llvm-mingw.zip
33+
7z x llvm-mingw.zip -o"$pwd\.llvm-mingw"
34+
rm llvm-mingw.zip
35+
36+
- name: Set up llvm-mingw
37+
id: setup-llvm
38+
shell: pwsh
39+
run: |
40+
$llvm_mingw_version = "${{ inputs.llvm-mingw-version }}"
41+
$llvm_arch = "${{ inputs.host-arch }}"
42+
if (!(Test-Path "$pwd\.llvm-mingw\llvm-mingw-${llvm_mingw_version}-ucrt-${llvm_arch}\bin\clang++.exe")) { return 1 }
43+
Add-Content $env:GITHUB_OUTPUT "llvm-path=$pwd\.llvm-mingw\llvm-mingw-${llvm_mingw_version}-ucrt-${llvm_arch}"
44+
Add-Content $env:GITHUB_PATH "$pwd\.llvm-mingw\llvm-mingw-${llvm_mingw_version}-ucrt-${llvm_arch}\bin"
45+
# for the ASAN runtime DLL:
46+
Add-Content $env:GITHUB_PATH "$pwd\.llvm-mingw\llvm-mingw-${llvm_mingw_version}-ucrt-${llvm_arch}\${llvm_arch}-w64-mingw32\bin"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'Set up LLVM for MSVC'
2+
description: 'Set up upstream LLVM for targeting MSVC ABI'
3+
inputs:
4+
llvm-version:
5+
description: 'LLVM version'
6+
required: true
7+
default: '15.0.5'
8+
outputs:
9+
llvm-path:
10+
description: "The path in which LLVM is installed to"
11+
value: ${{ steps.setup-llvm.outputs.llvm-path }}
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Cache LLVM and tools
16+
id: cache-llvm
17+
uses: actions/cache@v3
18+
with:
19+
path: |
20+
.LLVM
21+
.llvm-utils
22+
key: llvm-msvc-${{ runner.os }}-${{ inputs.llvm-version }}
23+
24+
- name: Install LLVM ${{ inputs.llvm-version }}
25+
if: steps.cache-llvm.outputs.cache-hit != 'true'
26+
shell: pwsh
27+
run: |
28+
Invoke-WebRequest "https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ inputs.llvm-version }}/LLVM-${{ inputs.llvm-version }}-win64.exe" -OutFile LLVM-installer.exe
29+
.\LLVM-installer.exe /S "/D=$pwd\.LLVM" | Out-Null
30+
rm LLVM-installer.exe
31+
32+
# Not using the LLVM tools that comes with MSVC.
33+
- name: Download LLVM build tools for msbuild
34+
if: steps.cache-llvm.outputs.cache-hit != 'true'
35+
shell: pwsh
36+
run: |
37+
Invoke-WebRequest "https://github.com/zufuliu/llvm-utils/releases/download/v22.09/LLVM_VS2017.zip" -OutFile LLVM_VS2017.zip
38+
7z x -y "LLVM_VS2017.zip" -o"$pwd\.llvm-utils\"
39+
rm LLVM_VS2017.zip
40+
41+
- name: Set up LLVM build tools for msbuild
42+
id: setup-llvm
43+
shell: pwsh
44+
run: |
45+
if (!(Test-Path "$pwd\.LLVM\bin\clang-cl.exe")) { exit 1 }
46+
Add-Content $env:GITHUB_PATH "$pwd\.LLVM\bin"
47+
Add-Content $env:GITHUB_OUTPUT "llvm-path=$pwd\.LLVM"
48+
cmd /c ".llvm-utils\LLVM_VS2017\install.bat" 1

.github/workflows/ci.yml

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,10 @@ jobs:
2424
steps:
2525
- uses: actions/checkout@v3
2626

27-
- name: Install LLVM 15
27+
- id: setup-llvm
28+
name: Set up LLVM (MSVC)
29+
uses: ./.github/actions/setup-llvm-msvc
2830
if: matrix.compiler == 'clang-cl'
29-
run: |
30-
Invoke-WebRequest "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.2/LLVM-15.0.2-win64.exe" -OutFile LLVM-installer.exe
31-
.\LLVM-installer.exe /S "/D=$pwd\LLVM" | Out-Null
32-
rm LLVM-installer.exe
33-
if (!(Test-Path "$pwd\LLVM\bin\clang-cl.exe")) { exit 1 }
34-
Add-Content $env:GITHUB_PATH "$pwd\LLVM\bin"
35-
36-
- name: Set up LLVM build tools for msbuild
37-
if: matrix.compiler == 'clang-cl'
38-
# Not using the LLVM tools that comes with MSVC.
39-
run: |
40-
Invoke-WebRequest "https://github.com/zufuliu/llvm-utils/releases/download/v22.09/LLVM_VS2017.zip" -OutFile LLVM_VS2017.zip
41-
7z x -y "LLVM_VS2017.zip" | Out-Null
42-
cmd /c "LLVM_VS2017\install.bat" 1
4331

4432
- name: Download nuget
4533
run: |
@@ -60,7 +48,7 @@ jobs:
6048
$target_version = "1.2.3.4"
6149
$props = "Configuration=$target_configuration,Platform=$target_platform,CppWinRTBuildVersion=$target_version"
6250
if ("${{ matrix.compiler }}" -eq "clang-cl") {
63-
$props += ",Clang=1,PlatformToolset=LLVM_v143,LLVMInstallDir=$pwd\LLVM"
51+
$props += ",Clang=1,PlatformToolset=LLVM_v143,LLVMInstallDir=${{ steps.setup-llvm.outputs.llvm-path }}"
6452
}
6553
Add-Content $env:GITHUB_ENV "msbuild_config_props=/p:$props"
6654
@@ -120,22 +108,10 @@ jobs:
120108
steps:
121109
- uses: actions/checkout@v3
122110

123-
- name: Install LLVM 15
111+
- id: setup-llvm
112+
name: Set up LLVM (MSVC)
113+
uses: ./.github/actions/setup-llvm-msvc
124114
if: matrix.compiler == 'clang-cl'
125-
run: |
126-
Invoke-WebRequest "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.2/LLVM-15.0.2-win64.exe" -OutFile LLVM-installer.exe
127-
.\LLVM-installer.exe /S "/D=$pwd\LLVM" | Out-Null
128-
rm LLVM-installer.exe
129-
if (!(Test-Path "$pwd\LLVM\bin\clang-cl.exe")) { exit 1 }
130-
Add-Content $env:GITHUB_PATH "$pwd\LLVM\bin"
131-
132-
- name: Set up LLVM build tools for msbuild
133-
if: matrix.compiler == 'clang-cl'
134-
run: |
135-
# Not using the LLVM tools that comes with MSVC.
136-
Invoke-WebRequest "https://github.com/zufuliu/llvm-utils/releases/download/v22.09/LLVM_VS2017.zip" -OutFile LLVM_VS2017.zip
137-
7z x -y "LLVM_VS2017.zip" | Out-Null
138-
cmd /c "LLVM_VS2017\install.bat" 1
139115

140116
- name: Fetch cppwinrt executables
141117
if: matrix.arch != 'arm64'
@@ -170,7 +146,7 @@ jobs:
170146
$target_version = "1.2.3.4"
171147
$props = "Configuration=$target_configuration,Platform=$target_platform,CppWinRTBuildVersion=$target_version"
172148
if ("${{ matrix.compiler }}" -eq "clang-cl") {
173-
$props += ",Clang=1,PlatformToolset=LLVM_v143,LLVMInstallDir=$pwd\LLVM"
149+
$props += ",Clang=1,PlatformToolset=LLVM_v143,LLVMInstallDir=${{ steps.setup-llvm.outputs.llvm-path }}"
174150
}
175151
Add-Content $env:GITHUB_ENV "msbuild_config_props=/p:$props"
176152
@@ -283,16 +259,9 @@ jobs:
283259
steps:
284260
- uses: actions/checkout@v3
285261

286-
- name: Install llvm-mingw toolchain
287-
run: |
288-
$llvm_mingw_version = "20220906"
289-
Invoke-WebRequest "https://github.com/mstorsjo/llvm-mingw/releases/download/${llvm_mingw_version}/llvm-mingw-${llvm_mingw_version}-ucrt-${{ matrix.arch }}.zip" -OutFile llvm-mingw.zip
290-
7z x llvm-mingw.zip
291-
rm llvm-mingw.zip
292-
if (!(Test-Path "$pwd\llvm-mingw-${llvm_mingw_version}-ucrt-${{ matrix.arch }}\bin\clang++.exe")) { return 1 }
293-
Add-Content $env:GITHUB_PATH "$pwd\llvm-mingw-${llvm_mingw_version}-ucrt-${{ matrix.arch }}\bin"
294-
# for the ASAN runtime DLL:
295-
Add-Content $env:GITHUB_PATH "$pwd\llvm-mingw-${llvm_mingw_version}-ucrt-${{ matrix.arch }}\${{ matrix.arch }}-w64-mingw32\bin"
262+
- id: setup-llvm
263+
name: Set up llvm-mingw
264+
uses: ./.github/actions/setup-llvm-mingw
296265

297266
- name: Build cppwinrt
298267
run: |

0 commit comments

Comments
 (0)