Skip to content

Commit a64ba42

Browse files
16bit-ykikoclaude
andcommitted
feat: add arch field to LLVM manifest for cross-compile support
Add architecture (x64/arm64) field to manifest entries so that pick_artifact can correctly select the right artifact when multiple architectures exist for the same platform. Update setup-llvm.py with --target-arch argument and cmake/llvm.cmake to pass it from CLICE_TARGET_TRIPLE. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 97cda26 commit a64ba42

File tree

4 files changed

+198
-6
lines changed

4 files changed

+198
-6
lines changed

cmake/llvm.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ function(setup_llvm LLVM_VERSION)
3333
elseif(CLICE_TARGET_TRIPLE MATCHES "windows")
3434
list(APPEND LLVM_SETUP_ARGS "--target-platform" "Windows")
3535
endif()
36+
37+
if(CLICE_TARGET_TRIPLE MATCHES "^aarch64")
38+
list(APPEND LLVM_SETUP_ARGS "--target-arch" "arm64")
39+
elseif(CLICE_TARGET_TRIPLE MATCHES "^x86_64")
40+
list(APPEND LLVM_SETUP_ARGS "--target-arch" "x64")
41+
endif()
3642
endif()
3743

3844
execute_process(

config/llvm-manifest.json

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,142 @@
1-
[]
1+
[
2+
{
3+
"version": "21.1.8",
4+
"filename": "aarch64-linux-gnu-releasedbg-lto.tar.xz",
5+
"sha256": "41519a1e238afa67eb7bf75181265c816bbd51c5bd9b8bbd88ae889403efd128",
6+
"lto": true,
7+
"asan": false,
8+
"platform": "linux",
9+
"build_type": "RelWithDebInfo",
10+
"arch": "arm64"
11+
},
12+
{
13+
"version": "21.1.8",
14+
"filename": "aarch64-linux-gnu-releasedbg.tar.xz",
15+
"sha256": "dd22285b87570b8e83bb5119d319827b51ef82aab166f348aacc7e25c4479889",
16+
"lto": false,
17+
"asan": false,
18+
"platform": "linux",
19+
"build_type": "RelWithDebInfo",
20+
"arch": "arm64"
21+
},
22+
{
23+
"version": "21.1.8",
24+
"filename": "aarch64-windows-msvc-releasedbg-lto.tar.xz",
25+
"sha256": "1cf598277354efdd839ee6cd826824ef2afb26e334fb32bbc8e48c49c6acb742",
26+
"lto": true,
27+
"asan": false,
28+
"platform": "windows",
29+
"build_type": "RelWithDebInfo",
30+
"arch": "arm64"
31+
},
32+
{
33+
"version": "21.1.8",
34+
"filename": "aarch64-windows-msvc-releasedbg.tar.xz",
35+
"sha256": "8f91b0a2a2895654feaebb7c9b24a6624662552ea51c6bb5eeb658dbaa0ff5a1",
36+
"lto": false,
37+
"asan": false,
38+
"platform": "windows",
39+
"build_type": "RelWithDebInfo",
40+
"arch": "arm64"
41+
},
42+
{
43+
"version": "21.1.8",
44+
"filename": "arm64-macos-clang-debug-asan.tar.xz",
45+
"sha256": "c6b70f141f0fc21eaf20ccbeb5ae101c08f8c19749e3d11e239af80d2c9e83ff",
46+
"lto": false,
47+
"asan": true,
48+
"platform": "macosx",
49+
"build_type": "Debug",
50+
"arch": "arm64"
51+
},
52+
{
53+
"version": "21.1.8",
54+
"filename": "arm64-macos-clang-releasedbg-lto.tar.xz",
55+
"sha256": "48cab8a3842dde154f271ad4cd782b02cda237cc84b87b261395eea810d6dbde",
56+
"lto": true,
57+
"asan": false,
58+
"platform": "macosx",
59+
"build_type": "RelWithDebInfo",
60+
"arch": "arm64"
61+
},
62+
{
63+
"version": "21.1.8",
64+
"filename": "arm64-macos-clang-releasedbg.tar.xz",
65+
"sha256": "1c640714dc7d4ef8a34d6786d50d3149d4458802af32ccbcf64ec1ea53e83ed0",
66+
"lto": false,
67+
"asan": false,
68+
"platform": "macosx",
69+
"build_type": "RelWithDebInfo",
70+
"arch": "arm64"
71+
},
72+
{
73+
"version": "21.1.8",
74+
"filename": "x64-linux-gnu-debug-asan.tar.xz",
75+
"sha256": "64ebfc3ecf4117b6fdd467d5f9bcd5a2030bb408c70415ed40bf99f35311a6b0",
76+
"lto": false,
77+
"asan": true,
78+
"platform": "linux",
79+
"build_type": "Debug",
80+
"arch": "x64"
81+
},
82+
{
83+
"version": "21.1.8",
84+
"filename": "x64-linux-gnu-releasedbg-lto.tar.xz",
85+
"sha256": "af8f97fbb57999aedd37a5e7c20d89499bf6518c6a0b5e83e18e6677a075fe71",
86+
"lto": true,
87+
"asan": false,
88+
"platform": "linux",
89+
"build_type": "RelWithDebInfo",
90+
"arch": "x64"
91+
},
92+
{
93+
"version": "21.1.8",
94+
"filename": "x64-linux-gnu-releasedbg.tar.xz",
95+
"sha256": "cdcd5312c6eba9295a05a68cd09559c4616ae0456550f7a64ed8fa15d283285b",
96+
"lto": false,
97+
"asan": false,
98+
"platform": "linux",
99+
"build_type": "RelWithDebInfo",
100+
"arch": "x64"
101+
},
102+
{
103+
"version": "21.1.8",
104+
"filename": "x64-macos-clang-releasedbg-lto.tar.xz",
105+
"sha256": "543db4d7fcd81d127c8f9ad33e359ecba442549da6d63d80e564710049ae2f08",
106+
"lto": true,
107+
"asan": false,
108+
"platform": "macosx",
109+
"build_type": "RelWithDebInfo",
110+
"arch": "x64"
111+
},
112+
{
113+
"version": "21.1.8",
114+
"filename": "x64-macos-clang-releasedbg.tar.xz",
115+
"sha256": "2193ade0b1e123f835b782488f31262a2f9ef541cf0f0f0125b190e08b721a29",
116+
"lto": false,
117+
"asan": false,
118+
"platform": "macosx",
119+
"build_type": "RelWithDebInfo",
120+
"arch": "x64"
121+
},
122+
{
123+
"version": "21.1.8",
124+
"filename": "x64-windows-msvc-releasedbg-lto.tar.xz",
125+
"sha256": "bf131c12c1ae87ffe3b7f87c424d7c2e628e63f591cb3505e901cf4c5ba0474b",
126+
"lto": true,
127+
"asan": false,
128+
"platform": "windows",
129+
"build_type": "RelWithDebInfo",
130+
"arch": "x64"
131+
},
132+
{
133+
"version": "21.1.8",
134+
"filename": "x64-windows-msvc-releasedbg.tar.xz",
135+
"sha256": "6dddec41a7960c9409516a46ca9d48d30f85adf948362e61ff37dd55ecf17568",
136+
"lto": false,
137+
"asan": false,
138+
"platform": "windows",
139+
"build_type": "RelWithDebInfo",
140+
"arch": "x64"
141+
}
142+
]

scripts/setup-llvm.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,41 @@ def detect_platform() -> str:
4040
raise RuntimeError(f"Unsupported platform: {plat}")
4141

4242

43+
def detect_arch() -> str:
44+
import platform
45+
46+
machine = platform.machine().lower()
47+
if machine in ("x86_64", "amd64"):
48+
return "x64"
49+
if machine in ("aarch64", "arm64"):
50+
return "arm64"
51+
raise RuntimeError(f"Unsupported architecture: {machine}")
52+
53+
4354
def pick_artifact(
44-
manifest: list[dict], version: str, build_type: str, is_lto: bool, platform: str
55+
manifest: list[dict],
56+
version: str,
57+
build_type: str,
58+
is_lto: bool,
59+
platform: str,
60+
arch: str,
4561
) -> dict:
4662
base_version = version.split("+", 1)[0]
4763
for entry in manifest:
4864
if entry.get("version") != version:
4965
continue
5066
if entry.get("platform") != platform.lower():
5167
continue
68+
if entry.get("arch") != arch:
69+
continue
5270
if entry.get("build_type") != build_type:
5371
continue
5472
if bool(entry.get("lto")) != is_lto:
5573
continue
5674
return entry
5775
raise RuntimeError(
5876
f"No matching LLVM artifact in manifest for version={base_version}, platform={platform}, "
59-
f"build_type={build_type}, lto={is_lto}"
77+
f"arch={arch}, build_type={build_type}, lto={is_lto}"
6078
)
6179

6280

@@ -268,6 +286,10 @@ def main() -> None:
268286
"--target-platform",
269287
help="Override platform for cross-compilation (e.g. macosx, linux, windows)",
270288
)
289+
parser.add_argument(
290+
"--target-arch",
291+
help="Override architecture for cross-compilation (e.g. x64, arm64)",
292+
)
271293
parser.add_argument("--output", required=True)
272294
args = parser.parse_args()
273295

@@ -280,7 +302,10 @@ def main() -> None:
280302
token = os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN")
281303
build_type = args.build_type
282304
platform_name = args.target_platform if args.target_platform else detect_platform()
283-
log(f"Platform: {platform_name}, normalized build type: {build_type}")
305+
arch_name = args.target_arch if args.target_arch else detect_arch()
306+
log(
307+
f"Platform: {platform_name}, arch: {arch_name}, normalized build type: {build_type}"
308+
)
284309
manifest = read_manifest(Path(args.manifest))
285310

286311
binary_dir = Path(args.binary_dir).resolve()
@@ -308,7 +333,12 @@ def main() -> None:
308333
if install_path is None:
309334
needs_install = True
310335
artifact = pick_artifact(
311-
manifest, args.version, build_type, args.enable_lto, platform_name
336+
manifest,
337+
args.version,
338+
build_type,
339+
args.enable_lto,
340+
platform_name,
341+
arch_name,
312342
)
313343
log(f"Selected artifact: {artifact.get('filename')} for download")
314344
filename = artifact["filename"]
@@ -321,7 +351,12 @@ def main() -> None:
321351
install_path = install_root
322352
elif needs_install:
323353
artifact = pick_artifact(
324-
manifest, args.version, build_type, args.enable_lto, platform_name
354+
manifest,
355+
args.version,
356+
build_type,
357+
args.enable_lto,
358+
platform_name,
359+
arch_name,
325360
)
326361
log(f"Selected artifact: {artifact.get('filename')} for download")
327362
filename = artifact["filename"]

scripts/upload-llvm.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ def parse_platform(name: str) -> str:
2727
raise ValueError(f"Unable to determine platform from filename: {name}")
2828

2929

30+
def parse_arch(name: str) -> str:
31+
lowered = name.lower()
32+
if lowered.startswith("aarch64-") or lowered.startswith("arm64-"):
33+
return "arm64"
34+
if lowered.startswith("x64-") or lowered.startswith("x86_64-"):
35+
return "x64"
36+
raise ValueError(f"Unable to determine arch from filename: {name}")
37+
38+
3039
def parse_build_type(name: str) -> str:
3140
lowered = name.lower()
3241
if "debug" in lowered:
@@ -43,6 +52,7 @@ def build_metadata_entry(path: Path, version: str) -> dict:
4352
"lto": "-lto" in filename.lower(),
4453
"asan": "-asan" in filename.lower(),
4554
"platform": parse_platform(filename),
55+
"arch": parse_arch(filename),
4656
"build_type": parse_build_type(filename),
4757
}
4858

0 commit comments

Comments
 (0)