Skip to content

Commit b354ade

Browse files
authored
chore(ruby): Resolve CI failure during aarch64-linux native build (googleapis#591)
* chore(ruby): Resolve CI failure during aarch64-linux native build
1 parent e5b32a1 commit b354ade

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

.github/workflows/build-native-binaries.yml renamed to .github/workflows/release-ruby-wrapper.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: Build and Publish Native Gem
1+
name: Build and Publish Native Ruby Gem
22

33
on:
44
workflow_dispatch:
55

66
jobs:
7-
build:
7+
build-shared-library-binaries:
88
strategy:
99
matrix:
1010
os: [ubuntu-latest, macos-13, windows-latest]
@@ -50,8 +50,16 @@ jobs:
5050
if: matrix.os == 'ubuntu-latest'
5151
run: |
5252
sudo apt-get update
53-
# This installs the C compiler for aarch64-linux
54-
sudo apt-get install -y gcc-aarch64-linux-gnu
53+
# GCC cross toolchain and binutils for aarch64
54+
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu
55+
# Mingw-w64 cross toolchain for Windows target (x86_64)
56+
sudo apt-get install -y gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64
57+
echo "=== cross compiler versions ==="
58+
aarch64-linux-gnu-gcc --version || true
59+
aarch64-linux-gnu-g++ --version || true
60+
x86_64-w64-mingw32-gcc --version || true
61+
which aarch64-linux-gnu-gcc || true
62+
which x86_64-w64-mingw32-gcc || true
5563
5664
# The cross-compiler step for macOS is removed,
5765
# as the built-in Clang on macOS runners can handle both Intel and ARM.

spannerlib/wrappers/spannerlib-ruby/Rakefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,33 @@ namespace :compile do
7171
"CGO_ENABLED" => "1" # Ensure CGO is enabled for c-shared
7272
}
7373

74+
# Set platform-specific C toolchain environment vars so cgo invokes the correct compiler/assembler/linker.
75+
case config[:goos]
76+
when "linux"
77+
if config[:goarch] == "arm64" || config[:goarch] == "arm" || arch.include?("aarch64")
78+
# Use the aarch64 cross-compiler installed via apt (aarch64-linux-gnu-*)
79+
env["CC"] = ENV.fetch("CC", "aarch64-linux-gnu-gcc")
80+
env["CXX"] = ENV.fetch("CXX", "aarch64-linux-gnu-g++")
81+
env["AR"] = ENV.fetch("AR", "aarch64-linux-gnu-ar")
82+
env["RANLIB"] = ENV.fetch("RANLIB", "aarch64-linux-gnu-ranlib")
83+
else
84+
# For x86_64 linux, host gcc should work on linux runners
85+
env["CC"] ||= ENV.fetch("CC", "gcc")
86+
end
87+
when "windows"
88+
# Use mingw-w64 cross compiler binaries (installed via apt on linux)
89+
if config[:goarch] == "amd64" || arch.include?("mingw") || arch.include?("x64")
90+
env["CC"] = ENV.fetch("CC", "x86_64-w64-mingw32-gcc")
91+
env["CXX"] = ENV.fetch("CXX", "x86_64-w64-mingw32-g++")
92+
env["AR"] = ENV.fetch("AR", "x86_64-w64-mingw32-ar")
93+
env["RANLIB"] = ENV.fetch("RANLIB", "x86_64-w64-mingw32-ranlib")
94+
end
95+
when "darwin"
96+
# Note: cross-compiling darwin/arm64 on an x86 mac runner is NOT reliably supported
97+
# unless you use osxcross or an ARM mac runner. We try nothing here; rely on runner's clang.
98+
env["CC"] ||= ENV.fetch("CC", "clang")
99+
end
100+
74101
command = [
75102
"go", "build",
76103
"-buildmode=c-shared",

spannerlib/wrappers/spannerlib-ruby/lib/spannerlib/ruby/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module Spannerlib
44
module Ruby
5-
VERSION = "0.1.0"
5+
VERSION = "0.1.0.alpha1"
66
end
77
end

0 commit comments

Comments
 (0)