Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 11 additions & 2 deletions .github/workflows/build-native-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,17 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
# This installs the C compiler for aarch64-linux
sudo apt-get install -y gcc-aarch64-linux-gnu
# GCC cross toolchain and binutils for aarch64
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu
# Mingw-w64 cross toolchain for Windows target (x86_64)
sudo apt-get install -y gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64
# Verify tools exist (helps debugging CI failures)
echo "=== cross compiler versions ==="
aarch64-linux-gnu-gcc --version || true
aarch64-linux-gnu-g++ --version || true
x86_64-w64-mingw32-gcc --version || true
which aarch64-linux-gnu-gcc || true
which x86_64-w64-mingw32-gcc || true

# The cross-compiler step for macOS is removed,
# as the built-in Clang on macOS runners can handle both Intel and ARM.
Expand Down
27 changes: 27 additions & 0 deletions spannerlib/wrappers/spannerlib-ruby/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,33 @@ namespace :compile do
"CGO_ENABLED" => "1" # Ensure CGO is enabled for c-shared
}

# Set platform-specific C toolchain environment vars so cgo invokes the correct compiler/assembler/linker.
case config[:goos]
when "linux"
if config[:goarch] == "arm64" || config[:goarch] == "arm" || arch.include?("aarch64")
# Use the aarch64 cross-compiler installed via apt (aarch64-linux-gnu-*)
env["CC"] = ENV.fetch("CC", "aarch64-linux-gnu-gcc")
env["CXX"] = ENV.fetch("CXX", "aarch64-linux-gnu-g++")
env["AR"] = ENV.fetch("AR", "aarch64-linux-gnu-ar")
env["RANLIB"] = ENV.fetch("RANLIB", "aarch64-linux-gnu-ranlib")
else
# For x86_64 linux, host gcc should work on linux runners
env["CC"] ||= ENV.fetch("CC", "gcc")
end
when "windows"
# Use mingw-w64 cross compiler binaries (installed via apt on linux)
if config[:goarch] == "amd64" || arch.include?("mingw") || arch.include?("x64")
env["CC"] = ENV.fetch("CC", "x86_64-w64-mingw32-gcc")
env["CXX"] = ENV.fetch("CXX", "x86_64-w64-mingw32-g++")
env["AR"] = ENV.fetch("AR", "x86_64-w64-mingw32-ar")
env["RANLIB"] = ENV.fetch("RANLIB", "x86_64-w64-mingw32-ranlib")
end
when "darwin"
# Note: cross-compiling darwin/arm64 on an x86 mac runner is NOT reliably supported
# unless you use osxcross or an ARM mac runner. We try nothing here; rely on runner's clang.
env["CC"] ||= ENV.fetch("CC", "clang")
end

command = [
"go", "build",
"-buildmode=c-shared",
Expand Down
Loading