Skip to content

Commit 808f493

Browse files
committed
Package compiler-rt for linux. Fix LLVM version.
1 parent 2130b36 commit 808f493

File tree

4 files changed

+51
-13
lines changed

4 files changed

+51
-13
lines changed

.github/workflows/build-toolchain.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,18 @@ jobs:
135135
uses: actions/download-artifact@v4
136136
with:
137137
pattern: gcc-*
138+
- name: Extract gcc
139+
run: find . -name "gcc-*.tar" -exec tar -xf {} \;
138140
- name: Build llvm
139-
run: |
140-
find . -name "gcc-*.tar" -exec tar -xf {} \;
141-
cd toolchain && bazel build //${{ matrix.target.type }}:llvm-package
141+
run: cd toolchain && bazel build //${{ matrix.target.type }}:llvm-package
142+
- name: Build compiler-rt
143+
run: cd toolchain && bazel build //${{ matrix.target.type }}:compiler-rt-package
144+
if: ${{ contains(matrix.target.name, 'linux') }}
142145
- name: Upload built llvm
143146
uses: actions/upload-artifact@v4
144147
with:
145148
name: llvm-${{ matrix.target.name }}
146-
path: toolchain/bazel-bin/${{ matrix.target.type }}/llvm-*.tar.xz
149+
path: toolchain/bazel-bin/${{ matrix.target.type }}/*.tar.xz
147150
if-no-files-found: error
148151

149152
test-bazel-rules:

toolchain/MODULE.bazel

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ http_archive(
1313
name = "llvm-project",
1414
build_file_content = 'filegroup(name = "llvm-project", srcs = glob(["**/*"]), visibility = ["//visibility:public"])',
1515
integrity = "sha256-gkAf6nt50AeAQ/dZi4NShNZlCnW5PmS292Hqe2MJdQE=",
16-
# integrity = "sha256-WKiBjGDmYnBk8xLb9GwC2ZSZVlWDQJOLcc9zGti8CBM=",
1716
patch_args = ["-p1"],
1817
patches = [
1918
"//:patches/50611.patch",
2019
],
2120
strip_prefix = "llvm-project-19.1.7.src",
2221
url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.7/llvm-project-19.1.7.src.tar.xz",
23-
# strip_prefix = "llvm-project-17.0.6.src",
24-
# url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/llvm-project-17.0.6.src.tar.xz",
2522
)
2623

2724
http_archive(
@@ -33,3 +30,7 @@ http_archive(
3330
)
3431

3532
rules_foreign_cc_toolchains = use_extension("rules_foreign_cc.bzl", "rules_foreign_cc_toolchains")
33+
34+
llvm_version = use_repo_rule("//:llvm_version.bzl", "llvm_version")
35+
36+
llvm_version(name = "llvm_version")

toolchain/linux/BUILD

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
22
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
3+
load("@llvm_version//:llvm_version.bzl", "LLVM_VERSION")
34
load("//:cmake.bzl", "cmake")
45
load("//:config.bzl", "LINUX_TARGETS")
56
load("//:host.bzl", "HOST_TARGET")
67
load("//:tar.bzl", "tar_package")
78

89
package(default_visibility = ["//visibility:public"])
910

10-
LLVM_VERSION = "17.0.6"
11-
1211
# The following targets are built for each target
1312
[
1413
(
@@ -114,23 +113,41 @@ cmake(
114113
lib_source = "@zlib",
115114
)
116115

116+
ALL_COMPILER_RT_SRCS = ["compiler-rt-{}".format(target) for target in LINUX_TARGETS]
117+
118+
COMPILER_RT_PREFIX = {
119+
"**/compiler-rt-*": "lib/clang/" + LLVM_VERSION.split(".")[0],
120+
}
121+
117122
# Add compiler-rt to LLVM installation
118123
copy_to_directory(
119124
name = "llvm",
120-
srcs = ["//:llvm"] + ["compiler-rt-{}".format(target) for target in LINUX_TARGETS],
125+
srcs = ["//:llvm"] + ALL_COMPILER_RT_SRCS,
121126
allow_overwrites = True,
122-
replace_prefixes = {
123-
"**/compiler-rt-*": "lib/clang/" + LLVM_VERSION.split(".")[0],
124-
},
127+
replace_prefixes = COMPILER_RT_PREFIX,
125128
root_paths = [
126129
"llvm",
127130
".",
128131
],
129132
)
130133

134+
# Make standalone compiler-rt for macOS hosts
135+
copy_to_directory(
136+
name = "compiler-rt",
137+
srcs = ALL_COMPILER_RT_SRCS,
138+
allow_overwrites = True,
139+
replace_prefixes = COMPILER_RT_PREFIX,
140+
)
141+
131142
# Package the compiler into a tar
132143
tar_package(
133144
"llvm-package",
134145
"llvm-{}".format(HOST_TARGET),
135146
"llvm",
136147
)
148+
149+
tar_package(
150+
"compiler-rt-package",
151+
"compiler-rt-linux",
152+
"compiler-rt",
153+
)

toolchain/llvm_version.bzl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def _llvm_version(rctx):
2+
config = rctx.read(Label("@llvm-project//:libcxx/include/__config"))
3+
prefix = "define _LIBCPP_VERSION"
4+
version = None
5+
for line in config.splitlines():
6+
if prefix in line:
7+
version = line.split(prefix)[1].strip()
8+
9+
if version == None:
10+
fail("couldn't identify LLVM version")
11+
12+
rctx.file("llvm_version.bzl", 'LLVM_VERSION = "{}.{}.{}"'.format(version[0:2], version[2:4].removeprefix("0"), version[4:6].removeprefix("0")))
13+
rctx.file("BUILD", 'exports_files(["llvm_version.bzl"])')
14+
15+
llvm_version = repository_rule(
16+
implementation = _llvm_version,
17+
)

0 commit comments

Comments
 (0)