Skip to content

Commit 0a24800

Browse files
authored
Merge pull request #3316 from CppCXY/master
Support zig build lock glibc2.17
2 parents 0b067fd + b58f034 commit 0a24800

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,18 @@ jobs:
3838

3939
- uses: actboy168/setup-luamake@master
4040

41+
- name: Install zig
42+
if: matrix.target == 'linux'
43+
run:
44+
sudo snap install zig --classic --beta
45+
46+
- name: Prepare zig wrapper
47+
if: matrix.target == 'linux'
48+
run: chmod +x zig-cc-wrapper.sh
49+
4150
- name: Build
51+
env:
52+
USE_ZIG: ${{ matrix.target == 'linux' && '1' || '0' }}
4253
run: luamake -platform ${{ matrix.platform }}
4354

4455
- name: Setting up workflow variables

make/detect_platform.lua

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,37 @@ elseif platform.os == 'windows' then
2121
error "unknown platform"
2222
end
2323
elseif platform.os == 'linux' then
24-
if lm.platform == nil then
25-
elseif lm.platform == "linux-x64" then
26-
elseif lm.platform == "linux-arm64" then
27-
lm.cc = 'aarch64-linux-gnu-gcc'
24+
-- Use Zig for Linux builds to ensure glibc 2.17 compatibility
25+
local use_zig = os.getenv("USE_ZIG")
26+
if use_zig and use_zig ~= "0" and use_zig ~= "false" then
27+
-- Set compiler to zig wrapper script that filters out -lstdc++fs
28+
-- The wrapper is needed because bee.lua requires stdc++fs but Zig's libc++ already includes it
29+
local wrapper = lm.workdir .. '/zig-cc-wrapper.sh'
30+
lm.cc = wrapper
31+
lm.ar = 'zig ar'
32+
33+
if lm.platform == nil then
34+
-- Auto-detect and set target
35+
elseif lm.platform == "linux-x64" then
36+
-- Target glibc 2.17 for x86_64
37+
lm.flags = { '-target', 'x86_64-linux-gnu.2.17' }
38+
lm.ldflags = { '-target', 'x86_64-linux-gnu.2.17', '-lc++' }
39+
elseif lm.platform == "linux-arm64" then
40+
-- Target glibc 2.17 for aarch64
41+
lm.flags = { '-target', 'aarch64-linux-gnu.2.17' }
42+
lm.ldflags = { '-target', 'aarch64-linux-gnu.2.17', '-lc++' }
43+
else
44+
error "unknown platform"
45+
end
2846
else
29-
error "unknown platform"
47+
-- Use default GCC
48+
if lm.platform == nil then
49+
elseif lm.platform == "linux-x64" then
50+
elseif lm.platform == "linux-arm64" then
51+
lm.cc = 'aarch64-linux-gnu-gcc'
52+
else
53+
error "unknown platform"
54+
end
3055
end
3156
end
3257

zig-cc-wrapper.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# Wrapper script for Zig compiler to filter out -lstdc++fs
3+
# Zig's libc++ already includes filesystem support
4+
5+
# Filter out -lstdc++fs from arguments
6+
args=()
7+
for arg in "$@"; do
8+
if [ "$arg" != "-lstdc++fs" ]; then
9+
args+=("$arg")
10+
fi
11+
done
12+
13+
# Call zig c++ with filtered arguments
14+
exec zig c++ "${args[@]}"

0 commit comments

Comments
 (0)