From 7d14c3518f1b86d9a39e90fc9fda0a9b25b8a537 Mon Sep 17 00:00:00 2001 From: star9029 Date: Fri, 5 Dec 2025 22:34:12 +0800 Subject: [PATCH 1/4] Add zig support --- .github/workflows/linux.yml | 9 +++++++-- .github/workflows/macos.yml | 7 ++++++- .github/workflows/windows.yml | 2 +- xmake.lua | 12 +++++++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index f0fe54b..7d54a2f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -37,7 +37,7 @@ jobs: - name: Setup xmake uses: xmake-io/github-action-setup-xmake@v1 with: - xmake-version: "2.9.9" + xmake-version: "3.0.5" actions-cache-folder: ".xmake-cache" - name: Increase Swap Space @@ -59,8 +59,13 @@ jobs: df -h - name: Package + shell: bash run: | - xmake config --yes --verbose --toolchain=clang-20 --mode=${{ matrix.build_type }} --policies=build.optimization.lto:${{ matrix.lto }} + if [[ "${{ matrix.lto }}" == "y" ]]; then + xrepo env --verbose --yes --bind="zig 0.15.2" xmake config --yes --verbose --toolchain=zig --mode=${{ matrix.build_type }} --policies=build.optimization.lto:${{ matrix.lto }} + else + xmake config --yes --verbose --toolchain=clang-20 --mode=${{ matrix.build_type }} --policies=build.optimization.lto:${{ matrix.lto }} + fi - name: Upload artifacts uses: actions/upload-artifact@v4 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index c8587a6..2132d98 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -40,10 +40,15 @@ jobs: brew install xmake - name: Package + shell: bash run: | export SDKROOT=$(xcrun --sdk macosx --show-sdk-path) export PATH="/opt/homebrew/opt/llvm@20/bin:/opt/homebrew/opt/lld@20/bin:$PATH" - xmake config --yes --verbose --toolchain=clang --mode=${{ matrix.build_type }} --policies=build.optimization.lto:${{ matrix.lto }} + if [[ "${{ matrix.lto }}" == "y" ]]; then + xrepo env --verbose --yes --bind="zig 0.15.2" xmake config --yes --verbose --toolchain=zig --mode=${{ matrix.build_type }} --policies=build.optimization.lto:${{ matrix.lto }} + else + xmake config --yes --verbose --toolchain=clang --mode=${{ matrix.build_type }} --policies=build.optimization.lto:${{ matrix.lto }} + fi - name: Upload artifacts uses: actions/upload-artifact@v4 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index deb3710..02298c0 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -28,7 +28,7 @@ jobs: - name: Setup xmake uses: xmake-io/github-action-setup-xmake@v1 with: - xmake-version: "2.9.9" + xmake-version: "3.0.5" actions-cache-folder: ".xmake-cache" - name: Package diff --git a/xmake.lua b/xmake.lua index 04fa855..3e62e81 100644 --- a/xmake.lua +++ b/xmake.lua @@ -26,7 +26,7 @@ local sparse_checkout_list = { package("llvm") add_urls("https://github.com/llvm/llvm-project.git", {alias = "git", includes = sparse_checkout_list}) - add_versions("git:21.1.4", "222fc11f2b8f25f6a0f4976272ef1bb7bf49521d") + add_versions("git:21.1.4", "llvmorg-21.1.4") add_versions("git:20.1.5", "llvmorg-20.1.5") add_configs("mode", {description = "Build type", default = "releasedbg", type = "string", values = {"debug", "release", "releasedbg"}}) @@ -129,6 +129,16 @@ package("llvm") table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) table.insert(configs, "-DLLVM_ENABLE_LTO=" .. (package:config("lto") and "ON" or "OFF")) + if package:toolchain("zig") then + local target + if package:is_plat("linux") then + target = "x86_64-linux-gnu" + elseif package:is_plat("macosx") then + target = "aarch64-macos-none" + end + table.insert(configs, "-DLLVM_HOST_TRIPLE=" .. target) + end + if package:config("mode") == "debug" then table.insert(configs, "-DLLVM_USE_SANITIZER=Address") end From b87ddc4df35658c7148a7e620314e59ea190e0e8 Mon Sep 17 00:00:00 2001 From: star9029 Date: Fri, 5 Dec 2025 23:24:43 +0800 Subject: [PATCH 2/4] fix mac --- .github/workflows/linux.yml | 2 +- .github/workflows/macos.yml | 5 ++++- xmake.lua | 7 +++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 7d54a2f..74c9d8a 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -62,7 +62,7 @@ jobs: shell: bash run: | if [[ "${{ matrix.lto }}" == "y" ]]; then - xrepo env --verbose --yes --bind="zig 0.15.2" xmake config --yes --verbose --toolchain=zig --mode=${{ matrix.build_type }} --policies=build.optimization.lto:${{ matrix.lto }} + xrepo env --verbose --yes --bind="zig 0.15.2" xmake config --yes --verbose --toolchain=zig --cross=x86_64-linux-gnu.2.17 --mode=${{ matrix.build_type }} --policies=build.optimization.lto:${{ matrix.lto }} else xmake config --yes --verbose --toolchain=clang-20 --mode=${{ matrix.build_type }} --policies=build.optimization.lto:${{ matrix.lto }} fi diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 2132d98..e898134 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -23,8 +23,11 @@ jobs: steps: - name: Setup llvm + shell: bash run: | - brew install llvm@20 lld@20 + if [[ "${{ matrix.lto }}" == "n" ]]; then + brew install llvm@20 lld@20 + fi - name: Setup python run: | diff --git a/xmake.lua b/xmake.lua index 3e62e81..449584b 100644 --- a/xmake.lua +++ b/xmake.lua @@ -73,6 +73,7 @@ package("llvm") io.replace("llvm/tools/CMakeLists.txt", "add_llvm_tool_subdirectory(lto)", "", {plain = true}) io.replace("llvm/tools/CMakeLists.txt", "add_llvm_implicit_projects()", "", {plain = true}) + local opt = {} local configs = { "-DLLVM_ENABLE_ZLIB=OFF", "-DLLVM_ENABLE_ZSTD=OFF", @@ -129,12 +130,15 @@ package("llvm") table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) table.insert(configs, "-DLLVM_ENABLE_LTO=" .. (package:config("lto") and "ON" or "OFF")) - if package:toolchain("zig") then + if not package:is_plat("windows") and package:toolchain("zig") then local target if package:is_plat("linux") then target = "x86_64-linux-gnu" elseif package:is_plat("macosx") then target = "aarch64-macos-none" + -- workaround + -- @see https://github.com/ziglang/zig/issues/18357#issuecomment-1869102870 + opt.cxflags = "-flld" end table.insert(configs, "-DLLVM_HOST_TRIPLE=" .. target) end @@ -156,7 +160,6 @@ package("llvm") table.insert(configs, "-DLLVM_ENABLE_LIBCXX=ON") end - local opt = {} opt.target = { "LLVMSupport", "LLVMFrontendOpenMP", From 02c5f7d8689690b2a7fcb485c0e77fe6b2c1340b Mon Sep 17 00:00:00 2001 From: star9029 Date: Fri, 5 Dec 2025 23:46:04 +0800 Subject: [PATCH 3/4] fix xmake zig --- xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake.lua b/xmake.lua index 449584b..e81881c 100644 --- a/xmake.lua +++ b/xmake.lua @@ -130,7 +130,7 @@ package("llvm") table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) table.insert(configs, "-DLLVM_ENABLE_LTO=" .. (package:config("lto") and "ON" or "OFF")) - if not package:is_plat("windows") and package:toolchain("zig") then + if not package:is_plat("windows") and package:has_tool("cxx", "zig_cc") then local target if package:is_plat("linux") then target = "x86_64-linux-gnu" From b596ada469cd74d2acad4eeb2517174a25ba44d9 Mon Sep 17 00:00:00 2001 From: star9029 Date: Mon, 8 Dec 2025 22:51:58 +0800 Subject: [PATCH 4/4] fix mac --- xmake.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/xmake.lua b/xmake.lua index e81881c..5817c09 100644 --- a/xmake.lua +++ b/xmake.lua @@ -133,12 +133,13 @@ package("llvm") if not package:is_plat("windows") and package:has_tool("cxx", "zig_cc") then local target if package:is_plat("linux") then - target = "x86_64-linux-gnu" + target = "x86_64-linux-gnu" elseif package:is_plat("macosx") then - target = "aarch64-macos-none" - -- workaround - -- @see https://github.com/ziglang/zig/issues/18357#issuecomment-1869102870 - opt.cxflags = "-flld" + target = "aarch64-macos-none" + if package:config("lto") then + opt.cxflags = "-Xclang -flto=thin" -- workaround + table.insert(configs, "-DLLVM_ENABLE_LTO=OFF") -- don't pass -flto + end end table.insert(configs, "-DLLVM_HOST_TRIPLE=" .. target) end