Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 --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

- name: Upload artifacts
uses: actions/upload-artifact@v4
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -40,10 +43,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
Comment on lines 45 to +54
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: PATH export references non-existent binaries for zig builds.

When matrix.lto == "y", the Setup llvm step skips installing llvm@20 and lld@20, but lines 48-49 unconditionally export these paths in the Package step. This breaks zig-based LTO builds.

The PATH export must be conditional to match the conditional installation:

Apply this diff to fix the issue:

       - 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"
           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
+            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 }}
           fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- 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: Package
shell: bash
run: |
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
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
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 }}
fi
🤖 Prompt for AI Agents
In .github/workflows/macos.yml around lines 45 to 54 the Package step
unconditionally exports /opt/homebrew/opt/llvm@20 and /opt/homebrew/opt/lld@20
into PATH even when matrix.lto == "y" (zig-based LTO) which doesn't install
those packages; make the PATH export conditional to match the installation logic
by only exporting the llvm@20 and lld@20 paths when matrix.lto != "y" (or move
that export into the existing else branch), leaving SDKROOT exported
unconditionally.


- name: Upload artifacts
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Comment on lines +29 to 31
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Guard LLVM_HOST_TRIPLE insertion to avoid nil concat when Zig is used on other platforms

Switching the 21.1.4 llvm version to the llvmorg-21.1.4 tag is fine and keeps the version mapping readable.

In the Zig‑specific block, though:

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 someone ever configures the Zig toolchain on a platform other than linux or macosx, target will be nil and the concatenation will raise a runtime error. It’s safer to only append the flag when target is defined.

A minimal fix:

-        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: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
+            if target then
+                table.insert(configs, "-DLLVM_HOST_TRIPLE=" .. target)
+            end
+        end

This keeps current Linux/macOS behavior while avoiding a hard failure if Zig support is later enabled on another platform before adding the corresponding triple.

Also applies to: 132-140

🤖 Prompt for AI Agents
In xmake.lua around lines 29-31 (and similarly at lines 132-140), the
Zig-specific block unconditionally concatenates "-DLLVM_HOST_TRIPLE=" with a
local target variable that may remain nil on unsupported platforms, causing a
runtime concat error; update the code to only insert the
"-DLLVM_HOST_TRIPLE=..." config when target is non-nil (i.e., after computing
target, check if target then table.insert the flag), leaving existing behavior
for linux and macosx intact and avoiding insertion on other platforms.

add_configs("mode", {description = "Build type", default = "releasedbg", type = "string", values = {"debug", "release", "releasedbg"}})
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -129,6 +130,19 @@ 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:has_tool("cxx", "zig_cc") 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

if package:config("mode") == "debug" then
table.insert(configs, "-DLLVM_USE_SANITIZER=Address")
end
Expand All @@ -146,7 +160,6 @@ package("llvm")
table.insert(configs, "-DLLVM_ENABLE_LIBCXX=ON")
end

local opt = {}
opt.target = {
"LLVMSupport",
"LLVMFrontendOpenMP",
Expand Down
Loading