Skip to content

Commit 16fbfc7

Browse files
[Rust][FFI] Build FFI library for Linux musl targets
Add x86_64-unknown-linux-musl and aarch64-unknown-linux-musl matrix rows to release-ffi.yml, cross-compiled with cargo-zigbuild on the existing linux-ubuntu-latest runners. Uses RUSTFLAGS=-C target-feature=-crt-static so the libs link musl dynamically, correct for Alpine hosts. Document the musl cross-compile in the FFI README. Mirrors the JNI musl support from #347. Fixes #411 Signed-off-by: Zlata Stefanovic <zlata.stefanovic@databricks.com>
1 parent 43a2a93 commit 16fbfc7

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

.github/workflows/release-ffi.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ jobs:
2222
dynamic_lib: libzerobus_ffi.so
2323
artifact_dir: linux-aarch64
2424
cross: true
25+
- runner: { group: databricks-protected-runner-group, labels: linux-ubuntu-latest }
26+
target: x86_64-unknown-linux-musl
27+
static_lib: libzerobus_ffi.a
28+
dynamic_lib: libzerobus_ffi.so
29+
artifact_dir: linux-musl-x86_64
30+
cross: false
31+
zigbuild: true
32+
- runner: { group: databricks-protected-runner-group, labels: linux-ubuntu-latest }
33+
target: aarch64-unknown-linux-musl
34+
static_lib: libzerobus_ffi.a
35+
dynamic_lib: libzerobus_ffi.so
36+
artifact_dir: linux-musl-aarch64
37+
cross: false
38+
zigbuild: true
2539
- runner: { group: databricks-protected-runner-group, labels: windows-server-latest }
2640
target: x86_64-pc-windows-msvc
2741
static_lib: zerobus_ffi.lib
@@ -69,9 +83,26 @@ jobs:
6983
with:
7084
targets: ${{ matrix.target }}
7185

86+
- name: Install Zig (musl cross-builds)
87+
if: matrix.zigbuild
88+
uses: mlugg/setup-zig@a67e68dc5c8281d9608136d3d7ca1b282213e4ac # v2.0.1
89+
with:
90+
version: 0.13.0
91+
92+
- name: Install cargo-zigbuild (musl cross-builds)
93+
if: matrix.zigbuild
94+
run: cargo install cargo-zigbuild --locked --version 0.19.8
95+
7296
- name: Build FFI library
97+
if: '!matrix.zigbuild'
7398
run: cargo build --release -p zerobus-ffi --target ${{ matrix.target }}
7499

100+
- name: Build FFI library (zigbuild)
101+
if: matrix.zigbuild
102+
env:
103+
RUSTFLAGS: -C target-feature=-crt-static
104+
run: cargo zigbuild --release -p zerobus-ffi --target ${{ matrix.target }}
105+
75106
- name: Prepare artifacts
76107
shell: bash
77108
run: |

rust/ffi/NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### New Features and Improvements
88

9+
- Build the FFI library for Linux musl targets (`x86_64-unknown-linux-musl`, `aarch64-unknown-linux-musl`), enabling C/C++ and Go-on-Alpine consumers to link `libzerobus_ffi.a` / `libzerobus_ffi.so` on musl-based (Alpine) containers. Artifacts ship in the `linux-musl-x86_64` / `linux-musl-aarch64` directories. Mirrors the JNI musl support added in #347.
10+
911
### Bug Fixes
1012

1113
### Documentation

rust/ffi/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ cargo build -p zerobus-ffi --release
2222
rustup target add aarch64-unknown-linux-gnu
2323
cargo build -p zerobus-ffi --release --target aarch64-unknown-linux-gnu
2424

25+
# Linux musl (Alpine), x86_64 and ARM64 — cross-compiled with cargo-zigbuild.
26+
# Built with -C target-feature=-crt-static so the libs link musl dynamically,
27+
# which is correct for dynamically-linked Alpine hosts.
28+
cargo install cargo-zigbuild
29+
rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl
30+
RUSTFLAGS="-C target-feature=-crt-static" \
31+
cargo zigbuild -p zerobus-ffi --release --target x86_64-unknown-linux-musl
32+
RUSTFLAGS="-C target-feature=-crt-static" \
33+
cargo zigbuild -p zerobus-ffi --release --target aarch64-unknown-linux-musl
34+
2535
# macOS ARM64 (Apple Silicon)
2636
rustup target add aarch64-apple-darwin
2737
cargo build -p zerobus-ffi --release --target aarch64-apple-darwin

0 commit comments

Comments
 (0)