Skip to content

Conversation

@star-hengxing
Copy link
Collaborator

@star-hengxing star-hengxing commented Dec 5, 2025

Summary by CodeRabbit

  • Chores

    • Upgraded build toolchain to xmake 3.0.5 across platforms
    • CI steps now run with explicit bash shell directives
  • New Features

    • Optional Zig toolchain path for LTO-enabled builds
  • Refactor

    • Added conditional CI/build flows to choose toolchains and flags based on LTO
    • Consolidated platform-specific host/target handling and build configuration tweaks

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 5, 2025

Walkthrough

CI workflows updated to xmake 3.0.5 and now branch on matrix.lto: when LTO is "y" they run xrepo env to bind Zig 0.15.2 and configure xmake with Zig + cross-target; otherwise they configure with Clang-20. xmake.lua sets LLVM version to llvmorg-21.1.4 and injects host-triple when Zig is used.

Changes

Cohort / File(s) Summary
CI workflows
.github/workflows/linux.yml, .github/workflows/macos.yml, .github/workflows/windows.yml
Bumped xmake to 3.0.5. Added shell: bash where relevant. Replaced single xmake config with conditional logic: if matrix.lto == "y" run xrepo env binding zig 0.15.2 and configure xmake with Zig toolchain + cross target; otherwise configure with clang-20. macOS now installs llvm@20/lld@20 only when matrix.lto == "n".
Build script
xmake.lua
Switched LLVM source tag to llvmorg-21.1.4. Added single opt = {} and injected LLVM_HOST_TRIPLE when Zig toolchain detected (Linux: x86_64-linux-gnu; macOS: aarch64-macos-none) and applied macOS Zig workaround opt.cxflags = "-flld". Removed redundant opt declaration.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Runner as GH Actions runner
  participant Matrix as Job matrix (lto)
  participant Step as bash step
  participant Xrepo as xrepo env
  participant Xmake as xmake config
  participant Tool as Toolchain (Zig / Clang)

  Runner->>Matrix: start job with matrix.lto
  Matrix->>Step: run Package step (shell: bash)
  alt matrix.lto == "y"
    Step->>Xrepo: xrepo env bind zig 0.15.2
    Xrepo->>Xmake: invoke xmake config (zig toolchain, cross-target, preserve mode/LTO)
    Xmake->>Tool: use Zig toolchain
  else matrix.lto != "y"
    Step->>Xmake: invoke xmake config (clang-20, preserve mode/LTO)
    Xmake->>Tool: use Clang-20 toolchain
  end
  Note right of Xmake: subsequent build/package steps use configured toolchain
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Check CI conditional logic and bash quoting for matrix.lto.
  • Validate xrepo env binding syntax and Zig 0.15.2 availability on runners.
  • Verify host-triple values and macOS -flld adjustment in xmake.lua.

Possibly related PRs

Poem

🐇
I hopped through workflows, nudged a line,
Zig on the branch when LTO doth shine.
Triples placed and versions bumped with care,
Builds hop along — carrots waiting there. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add zig support' directly and accurately summarizes the main objective of the pull request, which introduces Zig toolchain integration across multiple workflow files and the build configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch zig

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
.github/workflows/linux.yml (1)

37-41: Linux Zig/clang split for LTO looks correct; consider DRYing Zig version

  • shell: bash plus if [[ "${{ matrix.lto }}" == "y" ]] is valid and ensures Zig is only used for LTO builds.
  • Using xrepo env --bind="zig 0.15.2" to drive xmake config --toolchain=zig is consistent with the Zig‑based toolchain setup, while the non‑LTO path stays on clang-20.

For maintainability, you might factor the Zig version (0.15.2) into a reusable matrix value or env var shared with the macOS workflow so it’s easier to bump in one place later.

Also applies to: 61-68

.github/workflows/macos.yml (1)

42-51: macOS Zig/clang branching for LTO is correct; Zig version could be centralized

  • Using shell: bash with if [[ "${{ matrix.lto }}" == "y" ]] is appropriate.
  • The Zig path (xrepo env --bind="zig 0.15.2" ... --toolchain=zig) cleanly mirrors the Linux workflow, and the else branch preserves the existing clang‑based config behavior.

Similar to Linux, you might consider pulling the Zig version (0.15.2) into a shared matrix value or env var so Linux and macOS don’t drift if you upgrade Zig later.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52af132 and 7d14c35.

📒 Files selected for processing (4)
  • .github/workflows/linux.yml (2 hunks)
  • .github/workflows/macos.yml (1 hunks)
  • .github/workflows/windows.yml (1 hunks)
  • xmake.lua (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: build (releasedbg, n)
  • GitHub Check: build (releasedbg, y)
  • GitHub Check: build (debug, n)
  • GitHub Check: build (releasedbg, y)
  • GitHub Check: build (releasedbg, n)
  • GitHub Check: build (debug, n)
  • GitHub Check: build (releasedbg, MD, n)
  • GitHub Check: build (releasedbg, MT, y)
🔇 Additional comments (1)
.github/workflows/windows.yml (1)

28-32: Windows xmake 3.0.5 bump is consistent with the rest of the repo

Updating xmake-version to 3.0.5 here matches the compatibility.version = "3.0" policy in xmake.lua and the other CI workflows. No issues from this change alone.

Comment on lines +29 to 31
add_versions("git:21.1.4", "llvmorg-21.1.4")
add_versions("git:20.1.5", "llvmorg-20.1.5")

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d14c35 and b87ddc4.

📒 Files selected for processing (3)
  • .github/workflows/linux.yml (2 hunks)
  • .github/workflows/macos.yml (2 hunks)
  • xmake.lua (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • xmake.lua
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: build (debug, n)
  • GitHub Check: build (releasedbg, y)
  • GitHub Check: build (releasedbg, y)
  • GitHub Check: build (debug, n)
  • GitHub Check: build (releasedbg, n)
  • GitHub Check: build (releasedbg, n)
  • GitHub Check: build (releasedbg, MT, y)
  • GitHub Check: build (releasedbg, MD, n)
🔇 Additional comments (3)
.github/workflows/linux.yml (2)

40-40: xmake version bump is straightforward.

The version update from 2.9.9 to 3.0.5 is a valid upgrade. Verify that this version supports the new --cross and conditional toolchain parameters introduced in the build steps below.


62-68: Verify cross-target glibc version compatibility.

The --cross=x86_64-linux-gnu.2.17 parameter targets glibc 2.17, which is significantly older than Ubuntu 22.04's 2.35. This may restrict binary compatibility or cause runtime failures on newer systems.

Verify whether:

  • This glibc version is intentional for broader compatibility guarantees
  • zig 0.15.2's cross-compilation toolchain requires or recommends this specific version
  • The build artifacts are tested on systems with glibc 2.17 and newer

If broader compatibility is not a requirement, consider updating to a more recent glibc version (e.g., 2.29 or 2.35) to align with the runner environment.

.github/workflows/macos.yml (1)

25-30: Conditional llvm installation is logically sound.

The setup correctly installs llvm@20 and lld@20 only when using the clang toolchain (lto == "n"). However, ensure the PATH export in the Package step accounts for this conditional installation (see next comment).

Comment on lines 45 to +54
- 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
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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
xmake.lua (1)

133-144: Guard LLVM_HOST_TRIPLE insertion to avoid concat with nil on non-linux/macos Zig platforms

In this Zig-specific block:

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
        opt.cxflags = "-flld"
    end
    table.insert(configs, "-DLLVM_HOST_TRIPLE=" .. target)
end

if someone enables the Zig toolchain on a non-windows platform that is neither linux nor macosx, target stays nil and the concatenation will raise a runtime error.

Only append -DLLVM_HOST_TRIPLE=... when target was actually computed:

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

This preserves current Linux/macOS behavior and avoids a hard failure if Zig is later enabled on another platform before adding the corresponding triple.

🧹 Nitpick comments (1)
xmake.lua (1)

76-187: Local opt for CMake is fine; consider avoiding two different opt locals

Defining local opt = {} here and using it for opt.target and (conditionally) opt.cxflags passed into cmake.install is correct. However, there is another local opt = {} later around line 231 for archive options, which shadows this name and may confuse future readers.

If you want to tighten things up, consider renaming one of them (e.g., cmake_opt vs archive_opt) or reusing a single opt table for both call sites.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b87ddc4 and 02c5f7d.

📒 Files selected for processing (1)
  • xmake.lua (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: build (debug, n)
  • GitHub Check: build (releasedbg, n)
  • GitHub Check: build (releasedbg, y)
  • GitHub Check: build (releasedbg, y)
  • GitHub Check: build (debug, n)
  • GitHub Check: build (releasedbg, n)
  • GitHub Check: build (releasedbg, MT, y)
  • GitHub Check: build (releasedbg, MD, n)
🔇 Additional comments (1)
xmake.lua (1)

29-31: LLVM 21.1.4 git tag mapping looks good

Using add_versions("git:21.1.4", "llvmorg-21.1.4") aligns the git version with the upstream LLVM tag naming; no issues here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants