Skip to content

Commit c928de7

Browse files
committed
fix: improve cross-compilation setup in build script for better macOS support
1 parent d822795 commit c928de7

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

scripts/build.sh

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,32 @@ echo " Version: $BUILD_VERSION"
3131
echo " Commit: $BUILD_COMMIT"
3232
echo " Build Time: $BUILD_TIME"
3333

34-
# Set up cross-compilation with Zig if ZIG_TARGET is set
35-
if [ -n "$ZIG_TARGET" ]; then
36-
echo " Cross-compiling with Zig target: $ZIG_TARGET"
34+
# Determine if we need cross-compilation setup
35+
CURRENT_OS=$(go env GOOS)
36+
CURRENT_ARCH=$(go env GOARCH)
37+
38+
if [ "$TARGET_OS" != "$CURRENT_OS" ] || [ "$TARGET_ARCH" != "$CURRENT_ARCH" ]; then
39+
echo " Cross-compiling from $CURRENT_OS/$CURRENT_ARCH to $TARGET_OS/$TARGET_ARCH"
3740
export CGO_ENABLED=1
38-
export CC="zig cc -target $ZIG_TARGET"
39-
export CXX="zig c++ -target $ZIG_TARGET"
41+
42+
# Use Zig for Linux cross-compilation if ZIG_TARGET is set
43+
if [ -n "$ZIG_TARGET" ]; then
44+
echo " Using Zig target: $ZIG_TARGET"
45+
export CC="zig cc -target $ZIG_TARGET"
46+
export CXX="zig c++ -target $ZIG_TARGET"
47+
fi
48+
49+
# macOS can cross-compile between arm64/amd64 with native clang
50+
if [ "$TARGET_OS" = "darwin" ] && [ "$CURRENT_OS" = "darwin" ]; then
51+
echo " Using native clang for macOS cross-compilation"
52+
if [ "$TARGET_ARCH" = "arm64" ]; then
53+
export CC="clang -arch arm64"
54+
export CXX="clang++ -arch arm64"
55+
elif [ "$TARGET_ARCH" = "amd64" ]; then
56+
export CC="clang -arch x86_64"
57+
export CXX="clang++ -arch x86_64"
58+
fi
59+
fi
4060
fi
4161

4262
GOOS=$TARGET_OS GOARCH=$TARGET_ARCH go build -ldflags="$LDFLAGS" -o "$BINARY_NAME" .

0 commit comments

Comments
 (0)