diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2bacb9259..ebe1dd12c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,7 +38,18 @@ jobs: - uses: actboy168/setup-luamake@master + - name: Install zig + if: matrix.target == 'linux' + 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' }} run: luamake -platform ${{ matrix.platform }} - name: Setting up workflow variables diff --git a/make/detect_platform.lua b/make/detect_platform.lua index 4b62298ff..44724f5b7 100644 --- a/make/detect_platform.lua +++ b/make/detect_platform.lua @@ -21,12 +21,37 @@ 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 + -- 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 + -- 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', '-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', '-lc++' } + 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 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[@]}"