From 1476fb24626888e71530578b778bddd8d10e3d35 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Tue, 16 Dec 2025 11:26:00 +0800 Subject: [PATCH 1/6] test zig build --- .github/workflows/build.yml | 7 +++++++ make/detect_platform.lua | 32 +++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2bacb9259..f07bb2697 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,7 +38,14 @@ jobs: - uses: actboy168/setup-luamake@master + - name: Install zig + if: matrix.target == 'linux' + run: + sudo snap install zig --classic --beta + - name: Build + env: + USE_ZIG: ${{ matrix.target == 'linux' && '1' || '0' }} run: luamake -platform ${{ matrix.platform }} - name: Setting up workflow variables diff --git a/make/detect_platform.lua b/make/detect_platform.lua index 4b62298ff..fa1bfcf8c 100644 --- a/make/detect_platform.lua +++ b/make/detect_platform.lua @@ -21,12 +21,34 @@ elseif platform.os == 'windows' then error "unknown platform" end elseif platform.os == 'linux' then - if lm.platform == nil then - elseif lm.platform == "linux-x64" then - elseif lm.platform == "linux-arm64" then - lm.cc = 'aarch64-linux-gnu-gcc' + -- Use Zig for Linux builds to ensure glibc 2.17 compatibility + local use_zig = os.getenv("USE_ZIG") + if use_zig and use_zig ~= "0" and use_zig ~= "false" then + lm.cc = 'zig cc' + lm.ar = 'zig ar' + + if lm.platform == nil then + -- Auto-detect and set target + elseif lm.platform == "linux-x64" then + -- Target glibc 2.17 for x86_64 + lm.flags = { '-target', 'x86_64-linux-gnu.2.17' } + lm.ldflags = { '-target', 'x86_64-linux-gnu.2.17' } + elseif lm.platform == "linux-arm64" then + -- Target glibc 2.17 for aarch64 + lm.flags = { '-target', 'aarch64-linux-gnu.2.17' } + lm.ldflags = { '-target', 'aarch64-linux-gnu.2.17' } + else + error "unknown platform" + end else - error "unknown platform" + -- Use default GCC + if lm.platform == nil then + elseif lm.platform == "linux-x64" then + elseif lm.platform == "linux-arm64" then + lm.cc = 'aarch64-linux-gnu-gcc' + else + error "unknown platform" + end end end From 263b1185d443b042c49516c81e4a9c8ebe87949e Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Tue, 16 Dec 2025 11:31:37 +0800 Subject: [PATCH 2/6] fix zig build --- make/detect_platform.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/make/detect_platform.lua b/make/detect_platform.lua index fa1bfcf8c..e42f9ab22 100644 --- a/make/detect_platform.lua +++ b/make/detect_platform.lua @@ -25,6 +25,7 @@ elseif platform.os == 'linux' then local use_zig = os.getenv("USE_ZIG") if use_zig and use_zig ~= "0" and use_zig ~= "false" then lm.cc = 'zig cc' + lm.cxx = 'zig c++' lm.ar = 'zig ar' if lm.platform == nil then From ceafd405041a587b84594c884ea75e8c88cf5a37 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Tue, 16 Dec 2025 11:37:14 +0800 Subject: [PATCH 3/6] fix zig --- make/detect_platform.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/make/detect_platform.lua b/make/detect_platform.lua index e42f9ab22..43b5467b4 100644 --- a/make/detect_platform.lua +++ b/make/detect_platform.lua @@ -24,8 +24,8 @@ elseif platform.os == 'linux' then -- Use Zig for Linux builds to ensure glibc 2.17 compatibility local use_zig = os.getenv("USE_ZIG") if use_zig and use_zig ~= "0" and use_zig ~= "false" then - lm.cc = 'zig cc' - lm.cxx = 'zig c++' + -- Set compiler to zig (handles both C and C++) + lm.cc = 'zig c++' lm.ar = 'zig ar' if lm.platform == nil then From c497cc23aa5e1691f7925655632fa4fa584678e1 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Tue, 16 Dec 2025 11:44:16 +0800 Subject: [PATCH 4/6] fix zig build --- make/detect_platform.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/make/detect_platform.lua b/make/detect_platform.lua index 43b5467b4..72c6d1872 100644 --- a/make/detect_platform.lua +++ b/make/detect_platform.lua @@ -33,11 +33,11 @@ elseif platform.os == 'linux' then elseif lm.platform == "linux-x64" then -- Target glibc 2.17 for x86_64 lm.flags = { '-target', 'x86_64-linux-gnu.2.17' } - lm.ldflags = { '-target', 'x86_64-linux-gnu.2.17' } + lm.ldflags = { '-target', 'x86_64-linux-gnu.2.17', '-lc++' } elseif lm.platform == "linux-arm64" then -- Target glibc 2.17 for aarch64 lm.flags = { '-target', 'aarch64-linux-gnu.2.17' } - lm.ldflags = { '-target', 'aarch64-linux-gnu.2.17' } + lm.ldflags = { '-target', 'aarch64-linux-gnu.2.17', '-lc++' } else error "unknown platform" end From 418c6969a4827c76f353b8923e85840dd6489fb8 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Tue, 16 Dec 2025 11:50:08 +0800 Subject: [PATCH 5/6] fix zig build --- make/detect_platform.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/make/detect_platform.lua b/make/detect_platform.lua index 72c6d1872..818e8d1e4 100644 --- a/make/detect_platform.lua +++ b/make/detect_platform.lua @@ -25,7 +25,8 @@ elseif platform.os == 'linux' then local use_zig = os.getenv("USE_ZIG") if use_zig and use_zig ~= "0" and use_zig ~= "false" then -- Set compiler to zig (handles both C and C++) - lm.cc = 'zig c++' + -- Use a wrapper script to filter out -lstdc++fs which doesn't work with Zig + lm.cc = 'bash -c \'exec zig c++ "${@/#-lstdc++fs/}"\' --' lm.ar = 'zig ar' if lm.platform == nil then From b58f034a84c015444521913530d9ce483bb292e2 Mon Sep 17 00:00:00 2001 From: CppCXY <812125110@qq.com> Date: Tue, 16 Dec 2025 11:53:19 +0800 Subject: [PATCH 6/6] workaround for bee --- .github/workflows/build.yml | 4 ++++ make/detect_platform.lua | 7 ++++--- zig-cc-wrapper.sh | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 zig-cc-wrapper.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f07bb2697..ebe1dd12c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,6 +43,10 @@ jobs: run: sudo snap install zig --classic --beta + - name: Prepare zig wrapper + if: matrix.target == 'linux' + run: chmod +x zig-cc-wrapper.sh + - name: Build env: USE_ZIG: ${{ matrix.target == 'linux' && '1' || '0' }} diff --git a/make/detect_platform.lua b/make/detect_platform.lua index 818e8d1e4..44724f5b7 100644 --- a/make/detect_platform.lua +++ b/make/detect_platform.lua @@ -24,9 +24,10 @@ elseif platform.os == 'linux' then -- Use Zig for Linux builds to ensure glibc 2.17 compatibility local use_zig = os.getenv("USE_ZIG") if use_zig and use_zig ~= "0" and use_zig ~= "false" then - -- Set compiler to zig (handles both C and C++) - -- Use a wrapper script to filter out -lstdc++fs which doesn't work with Zig - lm.cc = 'bash -c \'exec zig c++ "${@/#-lstdc++fs/}"\' --' + -- Set compiler to zig wrapper script that filters out -lstdc++fs + -- The wrapper is needed because bee.lua requires stdc++fs but Zig's libc++ already includes it + local wrapper = lm.workdir .. '/zig-cc-wrapper.sh' + lm.cc = wrapper lm.ar = 'zig ar' if lm.platform == nil then diff --git a/zig-cc-wrapper.sh b/zig-cc-wrapper.sh new file mode 100644 index 000000000..6b50a3f22 --- /dev/null +++ b/zig-cc-wrapper.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Wrapper script for Zig compiler to filter out -lstdc++fs +# Zig's libc++ already includes filesystem support + +# Filter out -lstdc++fs from arguments +args=() +for arg in "$@"; do + if [ "$arg" != "-lstdc++fs" ]; then + args+=("$arg") + fi +done + +# Call zig c++ with filtered arguments +exec zig c++ "${args[@]}"