From c8402800de5ee01b559a0f5a3dbf6f8f29ba1225 Mon Sep 17 00:00:00 2001 From: Arthur Vasseur Date: Tue, 14 Apr 2026 22:05:45 +0200 Subject: [PATCH 1/5] Add support for LLVM version 21.1.0 and corresponding architecture-specific versions --- packages/l/libllvm/xmake.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/l/libllvm/xmake.lua b/packages/l/libllvm/xmake.lua index 6ea65354996..c74d1023077 100644 --- a/packages/l/libllvm/xmake.lua +++ b/packages/l/libllvm/xmake.lua @@ -21,9 +21,15 @@ package("libllvm") if is_plat("windows") then -- pre-built + + local arch = is_arch("x64") and "64" or "32" + add_urls("https://github.com/xmake-mirror/llvm-windows/releases/download/$(version)/clang+llvm-$(version)-win" .. arch .. ".zip") if is_arch("x64") then - add_urls("https://github.com/xmake-mirror/llvm-windows/releases/download/$(version)/clang+llvm-$(version)-win64.zip") add_versions("19.1.7", "c6e058c6012f499811caa1ec037cc1b5c2fd2f8c20cc3315cae602cbd6c81a5e") + add_versions("21.1.0", "130d0067de849be36c0ec84c6d515bd310cab324a4cc95d8cc71a1d3c6c730f4") + elseif is_arch("x86") then + add_versions("19.1.7", "8fded42dfa7fede876057e3a857073a5df15649df62a6f1c352588f65569d940") + add_versions("21.1.0", "36b9a55e237b2db404aa621aacb8538b56dabc6f49b8927dc1109e8123524d5f") end -- The LLVM shared library cannot be built under windows. @@ -39,6 +45,9 @@ package("libllvm") add_versions("tarball:19.1.7", "82401fea7b79d0078043f7598b835284d6650a75b93e64b6f761ea7b63097501") add_versions("git:19.1.7", "llvmorg-19.1.7") + add_versions("tarball:21.1.0", "1672e3efb4c2affd62dbbe12ea898b28a451416c7d95c1bd0190c26cbe878825") + add_versions("git:21.1.0", "llvmorg-21.1.0") + add_deps("ninja") add_deps("zlib", "zstd", {optional = true}) set_policy("package.cmake_generator.ninja", true) @@ -90,6 +99,14 @@ package("libllvm") package:add("links", "LLVM-C") end + -- LLVM 21+ introduces new split libraries that must be linked explicitly + if package:version() and package:version():ge("21.0") then + package:add("links", "LLVMFrontendDirective") + package:add("links", "LLVMFrontendAtomic") + package:add("links", "LLVMDebugInfoDWARFLowLevel") + package:add("links", "LLVMDWARFCFIChecker") + end + end) on_install("windows|x64", function (package) From aa9ef1b73163821d5f5babc0face94cbd6362ae0 Mon Sep 17 00:00:00 2001 From: Arthur Vasseur Date: Wed, 15 Apr 2026 21:26:49 +0200 Subject: [PATCH 2/5] Add support for LLVM targets and experimental targets in libllvm package --- packages/l/libllvm/constants.lua | 41 ++++++++++++++++++++++ packages/l/libllvm/xmake.lua | 58 ++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/packages/l/libllvm/constants.lua b/packages/l/libllvm/constants.lua index 7e31e3a80c1..b17cf7fe58b 100644 --- a/packages/l/libllvm/constants.lua +++ b/packages/l/libllvm/constants.lua @@ -27,6 +27,47 @@ function get_llvm_known_projects() return table.join(get_llvm_all_projects(), get_llvm_extra_projects()) end +function get_llvm_all_targets() + -- @see llvm/CMakeLists.txt: LLVM_ALL_TARGETS + return { + "AArch64", + "AMDGPU", + "ARM", + "AVR", + "BPF", + "Hexagon", + "Lanai", + "LoongArch", + "Mips", + "MSP430", + "NVPTX", + "PowerPC", + "RISCV", + "Sparc", + "SPIRV", + "SystemZ", + "VE", + "WebAssembly", + "X86", + "XCore" + } +end + +function get_llvm_experimental_targets() + -- @see llvm/CMakeLists.txt: LLVM_ALL_EXPERIMENTAL_TARGETS + return { + "ARC", + "CSKY", + "DirectX", + "M68k", + "Xtensa" + } +end + +function get_llvm_known_targets() + return table.join(get_llvm_all_targets(), get_llvm_experimental_targets()) +end + function get_llvm_all_runtimes() return { "libc", diff --git a/packages/l/libllvm/xmake.lua b/packages/l/libllvm/xmake.lua index c74d1023077..57189c217ab 100644 --- a/packages/l/libllvm/xmake.lua +++ b/packages/l/libllvm/xmake.lua @@ -19,6 +19,13 @@ package("libllvm") add_configs(runtime:gsub("-", "_"), {description = "Build " .. runtime .. " runtime.", default = false, type = "boolean"}) end + for _, target in ipairs(get_llvm_all_targets()) do + add_configs("target_" .. target:lower(), {description = "Build " .. target .. " target backend.", default = false, type = "boolean"}) + end + for _, target in ipairs(get_llvm_experimental_targets()) do + add_configs("target_" .. target:lower(), {description = "Build " .. target .. " experimental target backend.", default = false, type = "boolean"}) + end + if is_plat("windows") then -- pre-built @@ -107,6 +114,34 @@ package("libllvm") package:add("links", "LLVMDWARFCFIChecker") end + -- automatically enable the target matching the host architecture + local arch = package:arch() + local target_mapping = { + ["x86"] = "X86", + ["x64"] = "X86", + ["x86_64"] = "X86", + ["i386"] = "X86", + ["arm64"] = "AArch64", + ["arm64-v8a"] = "AArch64", + ["aarch64"] = "AArch64", + ["arm"] = "ARM", + ["armv7a"] = "ARM", + ["armv7"] = "ARM", + ["armeabi-v7a"] = "ARM", + ["riscv64"] = "RISCV", + ["riscv32"] = "RISCV", + ["loong64"] = "LoongArch", + ["mips"] = "Mips", + ["mips64"] = "Mips", + ["ppc64"] = "PowerPC", + ["ppc64le"] = "PowerPC", + ["wasm"] = "WebAssembly" + } + local host_target = target_mapping[arch] + if host_target then + package:config_set("target_" .. host_target:lower(), true) + end + end) on_install("windows|x64", function (package) @@ -118,6 +153,8 @@ package("libllvm") local projects_enabled = {} local runtimes_enabled = {} + local targets_enabled = {} + local experimental_targets_enabled = {} for _, project in ipairs(constants.get_llvm_known_projects()) do if package:config(project:gsub("-", "_")) then table.insert(projects_enabled, project) @@ -128,12 +165,23 @@ package("libllvm") table.insert(runtimes_enabled, runtime) end end + for _, target in ipairs(constants.get_llvm_all_targets()) do + if package:config("target_" .. target:lower()) then + table.insert(targets_enabled, target) + end + end + for _, target in ipairs(constants.get_llvm_experimental_targets()) do + if package:config("target_" .. target:lower()) then + table.insert(experimental_targets_enabled, target) + end + end local configs = { "-DBUILD_SHARED_LIBS=OFF", -- llvm "-DLLVM_BUILD_UTILS=OFF", + "-DLLVM_BUILD_EXAMPLES=OFF", "-DLLVM_INCLUDE_DOCS=OFF", "-DLLVM_INCLUDE_EXAMPLES=OFF", "-DLLVM_INCLUDE_TESTS=OFF", @@ -150,7 +198,17 @@ package("libllvm") "-DFLANG_BUILD_TOOLS=OFF", "-DLLD_BUILD_TOOLS=OFF" } + if #targets_enabled > 0 then + table.insert(configs, "-DLLVM_TARGETS_TO_BUILD=" .. table.concat(targets_enabled, ";")) + end + if #experimental_targets_enabled > 0 then + table.insert(configs, "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=" .. table.concat(experimental_targets_enabled, ";")) + end table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) + -- ARM64 uses gold linker to avoid relocation truncation errors with large binaries + if package:is_arch("arm64.*", "aarch64") then + table.insert(configs, "-DLLVM_USE_LINKER=lld") + end table.insert(configs, "-DLLVM_BUILD_LLVM_DYLIB=" .. (package:config("shared") and "ON" or "OFF")) table.insert(configs, "-DLLVM_ENABLE_EH=" .. (package:config("exception") and "ON" or "OFF")) table.insert(configs, "-DLLVM_ENABLE_RTTI=" .. (package:config("rtti") and "ON" or "OFF")) From c453efec8778c41fae66964e4b46b1120e5eca9f Mon Sep 17 00:00:00 2001 From: Arthur Vasseur Date: Thu, 16 Apr 2026 14:45:43 +0200 Subject: [PATCH 3/5] Limit ci jobs --- .github/workflows/iphoneos.yml | 2 +- .github/workflows/ubuntu_arm64.yml | 2 +- packages/l/libllvm/xmake.lua | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/iphoneos.yml b/.github/workflows/iphoneos.yml index bf193f193a2..f645ccfabef 100644 --- a/.github/workflows/iphoneos.yml +++ b/.github/workflows/iphoneos.yml @@ -25,4 +25,4 @@ jobs: - name: Tests run: | - xmake l ./scripts/test.lua -D -p iphoneos + xmake l ./scripts/test.lua -j1 -D -p iphoneos diff --git a/.github/workflows/ubuntu_arm64.yml b/.github/workflows/ubuntu_arm64.yml index d0b67e6264b..5369f8a881d 100644 --- a/.github/workflows/ubuntu_arm64.yml +++ b/.github/workflows/ubuntu_arm64.yml @@ -30,7 +30,7 @@ jobs: run: | # TODO we will remove it later sudo apt-get update - sudo apt-get install -y libgl1-mesa-dev libglu1-mesa-dev p7zip gobjc gcc g++ + sudo apt-get install -y libgl1-mesa-dev libglu1-mesa-dev p7zip gobjc gcc g++ lld - name: Tests run: | diff --git a/packages/l/libllvm/xmake.lua b/packages/l/libllvm/xmake.lua index 57189c217ab..2ea2cf8bb68 100644 --- a/packages/l/libllvm/xmake.lua +++ b/packages/l/libllvm/xmake.lua @@ -205,10 +205,20 @@ package("libllvm") table.insert(configs, "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=" .. table.concat(experimental_targets_enabled, ";")) end table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) - -- ARM64 uses gold linker to avoid relocation truncation errors with large binaries - if package:is_arch("arm64.*", "aarch64") then - table.insert(configs, "-DLLVM_USE_LINKER=lld") + table.insert(configs, "-DLLVM_PARALLEL_COMPILE_JOBS=2") + table.insert(configs, "-DLLVM_PARALLEL_LINK_JOBS=1") + + -- Native Linux ARM64 needs lld to avoid R_AARCH64_CALL26 relocation overflow + -- on large (debug/shared) binaries. Skip when cross-compiling (cross toolchains + -- like arm-gnu-toolchain don't bundle ld.lld) and skip when lld isn't installed + -- so CMake's CXX_SUPPORTS_CUSTOM_LINKER probe doesn't fail the configure step. + if package:is_arch("arm64.*", "aarch64") and is_host("linux") and (os.arch() == "arm64" or os.arch() == "aarch64") then + local find_tool = import("lib.detect.find_tool") + if find_tool("ld.lld") or find_tool("lld") then + table.insert(configs, "-DLLVM_USE_LINKER=lld") + end end + table.insert(configs, "-DLLVM_BUILD_LLVM_DYLIB=" .. (package:config("shared") and "ON" or "OFF")) table.insert(configs, "-DLLVM_ENABLE_EH=" .. (package:config("exception") and "ON" or "OFF")) table.insert(configs, "-DLLVM_ENABLE_RTTI=" .. (package:config("rtti") and "ON" or "OFF")) From abf8e1a62182bc317f1289907c88b56c4c0ecc12 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 24 Apr 2026 23:24:46 +0800 Subject: [PATCH 4/5] Update test command in iphoneos.yml Removed the '-j1' option from the xmake test command. --- .github/workflows/iphoneos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/iphoneos.yml b/.github/workflows/iphoneos.yml index f645ccfabef..bf193f193a2 100644 --- a/.github/workflows/iphoneos.yml +++ b/.github/workflows/iphoneos.yml @@ -25,4 +25,4 @@ jobs: - name: Tests run: | - xmake l ./scripts/test.lua -j1 -D -p iphoneos + xmake l ./scripts/test.lua -D -p iphoneos From 0bb72d1c8c73b7df3be8ca8994b0275b8cfecb9f Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 24 Apr 2026 23:30:00 +0800 Subject: [PATCH 5/5] Update xmake.lua --- packages/l/libllvm/xmake.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/l/libllvm/xmake.lua b/packages/l/libllvm/xmake.lua index 2ea2cf8bb68..6f5940efff2 100644 --- a/packages/l/libllvm/xmake.lua +++ b/packages/l/libllvm/xmake.lua @@ -149,7 +149,9 @@ package("libllvm") end) on_install("linux", "macosx", "bsd", "android", "iphoneos", "cross", function (package) - local constants = import('constants') + import("lib.detect.find_tool") + import('constants') + import("utils.ci.is_running", {alias = "ci_is_running"}) local projects_enabled = {} local runtimes_enabled = {} @@ -213,7 +215,6 @@ package("libllvm") -- like arm-gnu-toolchain don't bundle ld.lld) and skip when lld isn't installed -- so CMake's CXX_SUPPORTS_CUSTOM_LINKER probe doesn't fail the configure step. if package:is_arch("arm64.*", "aarch64") and is_host("linux") and (os.arch() == "arm64" or os.arch() == "aarch64") then - local find_tool = import("lib.detect.find_tool") if find_tool("ld.lld") or find_tool("lld") then table.insert(configs, "-DLLVM_USE_LINKER=lld") end @@ -296,8 +297,12 @@ package("libllvm") tryadd_dep("zlib", "ZLIB") tryadd_dep("zstd") + local opt = {} + if ci_is_running() then + opt.jobs = "1" + end os.cd("llvm") - import("package.tools.cmake").install(package, configs) + import("package.tools.cmake").install(package, configs, opt) end) on_test(function (package)