Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 30 additions & 5 deletions make/detect_platform.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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++' }
Comment on lines +35 to +42

Choose a reason for hiding this comment

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

medium

There's some code duplication here for setting the compiler and linker flags for different architectures. You can refactor this to be more concise and easier to maintain by determining the target architecture first and then constructing the flags. This also makes it easier to update the glibc version in the future.

        elseif lm.platform == "linux-x64" or lm.platform == "linux-arm64" then
            local target_arch = (lm.platform == "linux-x64") and "x86_64" or "aarch64"
            local glibc_version = "2.17"
            local target = ("%s-linux-gnu.%s"):format(target_arch, glibc_version)
            lm.flags = { '-target', target }
            lm.ldflags = { '-target', target, '-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

Expand Down
14 changes: 14 additions & 0 deletions zig-cc-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

Choose a reason for hiding this comment

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

high

I have a couple of suggestions for this new script:

  1. Robustness: It's a good practice to add set -euo pipefail at the start of bash scripts. This makes them exit immediately on errors, on usage of unset variables, or on pipeline failures.

  2. Permissions: This script needs to be executable to work as a compiler wrapper. Please ensure you set the executable bit (e.g., chmod +x zig-cc-wrapper.sh) and commit this permission change. Without this, the build will fail on Linux/macOS systems.

Suggested change
#!/bin/bash
#!/bin/bash
set -euo pipefail

# 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[@]}"
Loading