Skip to content

Commit d53dfed

Browse files
authored
Update llvm build workflows (#1906)
* Add debug configurations to llvm workflows * Update build scripts to build LLVM debug config * Enable debug builds for all configurations * Export/import clang/llvm natvis files * Remove downloaded llvm archive after extracting it * Fix broken DebugOpt build on linux * Use checkout action instead of manual command * Fix incorrect configuration mapping * Fix working directory after checkout method update * Remove working directory overrides * Fix incorrect llvm package name fetching
1 parent f0b44b4 commit d53dfed

File tree

8 files changed

+64
-1556
lines changed

8 files changed

+64
-1556
lines changed

.github/workflows/llvm-win.yml

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,21 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
config:
12-
- { os: windows-2022, platform: x64, configuration : Debug, vs: "Program Files/Microsoft Visual Studio/2022" }
13-
- { os: windows-2022, platform: x64, configuration : RelWithDebInfo, vs: "Program Files/Microsoft Visual Studio/2022" }
11+
os: [windows-2022]
12+
platform: [x64]
13+
build-cfg: [Debug, DebugOpt, Release]
1414

15-
runs-on: ${{ matrix.config.os }}
15+
runs-on: ${{ matrix.os }}
1616

1717
env:
18-
CC: ${{ matrix.config.cc }}
19-
CXX: ${{ matrix.config.cxx }}
20-
VS_VERSION: ${{ matrix.config.vs }}
21-
PLATFORM: ${{ matrix.config.platform }}
22-
CONFIGURATION: ${{ matrix.config.configuration }}
18+
VS_VERSION: "Program Files/Microsoft Visual Studio/2022"
19+
PLATFORM: ${{ matrix.platform }}
20+
BUILD_CONFIGURATION: ${{ matrix.build-cfg }}
2321
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
2422

2523
steps:
26-
- name: Inject slug/short variables
27-
uses: rlespinasse/github-slug-action@v4
28-
2924
- name: Check out
30-
shell: cmd
31-
run: |
32-
git clone -b ${{ env.GITHUB_REF_SLUG }} https://github.com/mono/CppSharp.git C:\CppSharp
25+
uses: actions/checkout@v4
3326

3427
- uses: lukka/get-cmake@latest
3528

@@ -48,20 +41,17 @@ jobs:
4841
- name: Clone LLVM
4942
shell: bash
5043
run: build/build.sh clone_llvm
51-
working-directory: C:\CppSharp
5244

5345
- name: Build LLVM
5446
shell: bash
55-
run: build/build.sh build_llvm -platform $PLATFORM -configuration $CONFIGURATION
56-
working-directory: C:\CppSharp
47+
run: build/build.sh build_llvm -platform $PLATFORM -configuration $BUILD_CONFIGURATION
5748

5849
- name: Package LLVM
5950
shell: bash
60-
run: build/build.sh package_llvm -platform $PLATFORM -configuration $CONFIGURATION
61-
working-directory: C:\CppSharp
51+
run: build/build.sh package_llvm -platform $PLATFORM -configuration $BUILD_CONFIGURATION
6252

6353
- name: 'Upload Artifact'
64-
uses: actions/upload-artifact@v3
54+
uses: actions/upload-artifact@v4
6555
with:
66-
name: llvm
67-
path: C:\CppSharp\build\llvm\llvm-*-*.*
56+
name: llvm-${{ matrix.os }}-${{ matrix.platform }}-${{ matrix.build-cfg }}
57+
path: build/llvm/llvm-*-*.*

.github/workflows/llvm.yml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,25 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
config:
12-
- { os: ubuntu-22.04, platform: x64, cxx: g++-11, cc: gcc-11 }
13-
- { os: ubuntu-22.04, platform: arm64, cxx: g++-11, cc: gcc-11 }
14-
- { os: macos-11, platform: x64, cxx: clang++, cc: clang }
15-
- { os: macos-12, platform: x64, cxx: clang++, cc: clang }
16-
- { os: macos-12, platform: arm64, cxx: clang++, cc: clang }
11+
os: [ubuntu-22.04, macos-13]
12+
platform: [x64, arm64]
13+
build-cfg: [Debug, DebugOpt, Release]
1714

18-
runs-on: ${{ matrix.config.os }}
15+
runs-on: ${{ matrix.os }}
1916

2017
env:
21-
CC: ${{ matrix.config.cc }}
22-
CXX: ${{ matrix.config.cxx }}
23-
PLATFORM: ${{ matrix.config.platform }}
18+
CC: ${{ startsWith(matrix.os, 'ubuntu') && 'gcc-11' || 'clang' }}
19+
CXX: ${{ startsWith(matrix.os, 'ubuntu') && 'g++-11' || 'clang++' }}
20+
PLATFORM: ${{ matrix.platform }}
21+
BUILD_CONFIGURATION: ${{ matrix.build-cfg }}
2422
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
2523

2624
steps:
2725
- uses: actions/checkout@v4
2826
- uses: lukka/get-cmake@latest
2927

3028
- name: Install cross compilers
31-
if: startsWith(matrix.config.os, 'ubuntu') && startsWith(matrix.config.platform, 'arm64')
29+
if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.platform, 'arm64')
3230
run: sudo apt install -y g++-aarch64-linux-gnu gcc-aarch64-linux-gnu
3331

3432
- name: Clone LLVM
@@ -37,14 +35,15 @@ jobs:
3735

3836
- name: Build LLVM
3937
shell: bash
40-
run: build/build.sh build_llvm -platform $PLATFORM
38+
run: build/build.sh build_llvm -platform $PLATFORM -configuration $BUILD_CONFIGURATION
4139

4240
- name: Package LLVM
4341
shell: bash
44-
run: build/build.sh package_llvm -platform $PLATFORM
42+
run: build/build.sh package_llvm -platform $PLATFORM -configuration $BUILD_CONFIGURATION
4543

4644
- name: 'Upload Artifact'
47-
uses: actions/upload-artifact@v3
45+
uses: actions/upload-artifact@v4
4846
with:
49-
name: llvm
47+
name: llvm-${{ matrix.os }}-${{ matrix.platform }}-${{ matrix.build-cfg }}
48+
overwrite: true
5049
path: build/llvm/llvm-*-*.*

.github/workflows/main.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on: [push, pull_request, workflow_dispatch]
44

55
# Cancel any previous workflows if the pull request was updated
66
concurrency:
@@ -15,8 +15,7 @@ jobs:
1515
matrix:
1616
os: [ubuntu-22.04, windows-2022]
1717
platform: [x64]
18-
build-cfg: [DebugOpt, Release]
19-
#build-cfg: [Debug, DebugOpt, Release] # our local copy of clang isn't build for debug on linux/macos currently
18+
build-cfg: [Debug, DebugOpt, Release]
2019
include:
2120
- os: windows-2022
2221
platform: x64

build/LLVM.lua

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ LLVMRootDir = builddir .. "/llvm/llvm-project"
55
local LLVMDirPerConfiguration = false
66

77
local LLVMRootDirDebug = ""
8+
local LLVMRootDirRelWithDebInfo = ""
89
local LLVMRootDirRelease = ""
910

1011
require "llvm/LLVM"
1112

1213
function SearchLLVM()
1314
LLVMRootDirDebug = builddir .. "/llvm/" .. get_llvm_package_name(nil, "Debug")
14-
LLVMRootDirRelease = builddir .. "/llvm/" .. get_llvm_package_name()
15+
LLVMRootDirRelWithDebInfo = builddir .. "/llvm/" .. get_llvm_package_name(nil, "RelWithDebInfo")
16+
LLVMRootDirRelease = builddir .. "/llvm/" .. get_llvm_package_name(nil, "Release")
1517

16-
if os.isdir(LLVMRootDirDebug) or os.isdir(LLVMRootDirRelease) then
18+
if os.isdir(LLVMRootDirDebug) or os.isdir(LLVMRootDirRelWithDebInfo) or os.isdir(LLVMRootDirRelease) then
1719
LLVMDirPerConfiguration = true
18-
print("Using debug LLVM build: " .. LLVMRootDirDebug)
19-
print("Using release LLVM build: " .. LLVMRootDirRelease)
20+
print("Using cached LLVM 'Debug' build: " .. LLVMRootDirDebug)
21+
print("Using cached LLVM 'RelWithDebInfo' build: " .. LLVMRootDirRelWithDebInfo)
22+
print("Using cached LLVM 'Release' build: " .. LLVMRootDirRelease)
2023
elseif os.isdir(LLVMRootDir) then
2124
print("Using LLVM build: " .. LLVMRootDir)
2225
else
@@ -41,13 +44,13 @@ function SetupLLVMIncludes()
4144
filter { "configurations:DebugOpt" }
4245
includedirs
4346
{
44-
path.join(LLVMRootDirRelease, "include"),
45-
path.join(LLVMRootDirRelease, "llvm/include"),
46-
path.join(LLVMRootDirRelease, "lld/include"),
47-
path.join(LLVMRootDirRelease, "clang/include"),
48-
path.join(LLVMRootDirRelease, "clang/lib"),
49-
path.join(LLVMRootDirRelease, "build/include"),
50-
path.join(LLVMRootDirRelease, "build/clang/include"),
47+
path.join(LLVMRootDirRelWithDebInfo, "include"),
48+
path.join(LLVMRootDirRelWithDebInfo, "llvm/include"),
49+
path.join(LLVMRootDirRelWithDebInfo, "lld/include"),
50+
path.join(LLVMRootDirRelWithDebInfo, "clang/include"),
51+
path.join(LLVMRootDirRelWithDebInfo, "clang/lib"),
52+
path.join(LLVMRootDirRelWithDebInfo, "build/include"),
53+
path.join(LLVMRootDirRelWithDebInfo, "build/clang/include"),
5154
}
5255

5356
filter { "configurations:Debug" }
@@ -95,12 +98,17 @@ function CopyClangIncludes()
9598

9699
if LLVMDirPerConfiguration then
97100
local clangBuiltinDebug = path.join(LLVMRootDirDebug, "lib")
101+
local clangBuiltinRelWithDebInfo = path.join(LLVMRootDirRelWithDebInfo, "lib")
98102
local clangBuiltinRelease = path.join(LLVMRootDirRelease, "lib")
99103

100104
if os.isdir(path.join(clangBuiltinDebug, "clang")) then
101105
clangBuiltinIncludeDir = clangBuiltinDebug
102106
end
103107

108+
if os.isdir(path.join(clangBuiltinRelWithDebInfo, "clang")) then
109+
clangBuiltinIncludeDir = clangBuiltinRelWithDebInfo
110+
end
111+
104112
if os.isdir(path.join(clangBuiltinRelease, "clang")) then
105113
clangBuiltinIncludeDir = clangBuiltinRelease
106114
end
@@ -134,7 +142,7 @@ function SetupLLVMLibs()
134142

135143
if LLVMDirPerConfiguration then
136144
filter { "configurations:DebugOpt" }
137-
libdirs { path.join(LLVMRootDirRelease, "build/lib") }
145+
libdirs { path.join(LLVMRootDirRelWithDebInfo, "build/lib") }
138146

139147
filter { "configurations:Debug" }
140148
libdirs { path.join(LLVMRootDirDebug, "build/lib") }
@@ -150,9 +158,6 @@ function SetupLLVMLibs()
150158

151159
filter { "configurations:Debug", "toolset:msc*" }
152160
libdirs { path.join(LLVMBuildDir, "Debug/lib") }
153-
154-
filter { "configurations:Release", "toolset:msc*" }
155-
libdirs { path.join(LLVMBuildDir, "RelWithDebInfo/lib") }
156161
end
157162

158163
filter {}

build/llvm/LLVM.lua

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ function clone_llvm()
4949

5050
extract(archive, '.')
5151
os.rename('llvm-project-'..llvm_release, llvm)
52+
53+
-- delete the extracted archive
54+
print("Cleaning up downloaded artifacts...")
55+
os.remove(archive)
5256
end
5357

5458
function get_vs_version()
@@ -138,12 +142,12 @@ end
138142

139143
function get_llvm_configuration_name(debug)
140144
if string.find(_OPTIONS["configuration"], "DebugOpt") then
141-
return os.istarget("windows") and "RelWithDebInfo" or "Release"
145+
return "RelWithDebInfo"
142146
end
143147
if string.find(_OPTIONS["configuration"], "Debug") then
144148
return "Debug"
145149
end
146-
return os.istarget("windows") and "RelWithDebInfo" or "Release"
150+
return "Release"
147151
end
148152

149153
function get_7z_path()
@@ -219,6 +223,10 @@ function download_llvm()
219223
else
220224
extract_tar_xz(archive, pkg_name)
221225
end
226+
227+
-- delete the extracted archive
228+
print("Cleaning up downloaded artifacts...")
229+
os.remove(archive)
222230
end
223231

224232
function cmake(gen, conf, builddir, options)
@@ -511,6 +519,10 @@ function package_llvm(conf, llvm_base, llvm_build)
511519
os.copydir(llvm_build_libdir, out .. "/build/lib", "*.a")
512520
end
513521

522+
-- Copy natvis visualizers for a better debugging experience
523+
os.copyfile(llvm_base .. "/clang/utils/ClangVisualizers/clang.natvis", out .. "/utils/clang.natvis")
524+
os.copyfile(llvm_base .. "/llvm/utils/LLVMVisualizers/llvm.natvis", out .. "/utils/llvm.natvis")
525+
514526
os.copydir(llvm_base .. "/clang/include", out .. "/clang/include")
515527
os.copydir(llvm_build .. "/tools/clang/include", out .. "/build/clang/include")
516528

build/premake5.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ workspace "CppSharp"
4444
workspacefiles(path.join(builddir, "premake5.lua"))
4545
workspacefiles(path.join(builddir, "*.sh"))
4646
workspacefiles(path.join(rootdir, ".github/workflows/*.yml"))
47-
workspacefiles(path.join(rootdir, "*.natvis"))
47+
workspacefiles(path.join(path.join(get_llvm_build_dir(), "/utils/"), "*.natvis"))
4848
workspacefiles(path.join(testsdir, "Test*.props"))
4949

5050
group "Libraries"

0 commit comments

Comments
 (0)