-
Notifications
You must be signed in to change notification settings - Fork 2
Add zig support #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add zig support #11
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard Switching the 21.1.4 llvm version to the 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)
endIf someone ever configures the Zig toolchain on a platform other than 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
+ endThis 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 |
||
| add_configs("mode", {description = "Build type", default = "releasedbg", type = "string", values = {"debug", "release", "releasedbg"}}) | ||
|
|
@@ -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,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 | ||
|
|
@@ -146,7 +160,6 @@ package("llvm") | |
| table.insert(configs, "-DLLVM_ENABLE_LIBCXX=ON") | ||
| end | ||
|
|
||
| local opt = {} | ||
| opt.target = { | ||
| "LLVMSupport", | ||
| "LLVMFrontendOpenMP", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
🤖 Prompt for AI Agents