Skip to content

[Rust][FFI] Add native library support for Linux musl (Alpine)#412

Merged
zlata-stefanovic-db merged 3 commits into
mainfrom
ffi-musl-support
Jun 23, 2026
Merged

[Rust][FFI] Add native library support for Linux musl (Alpine)#412
zlata-stefanovic-db merged 3 commits into
mainfrom
ffi-musl-support

Conversation

@zlata-stefanovic-db

@zlata-stefanovic-db zlata-stefanovic-db commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

WHAT: Builds the C FFI library (rust/ffi) for Linux musl targets so it works on Alpine / musl-based containers:

  • Adds x86_64-unknown-linux-musl and aarch64-unknown-linux-musl matrix rows to .github/workflows/release-ffi.yml, cross-compiled with cargo-zigbuild on the existing databricks-protected-runner-group / linux-ubuntu-latest runners (no dedicated Alpine runner). Builds with RUSTFLAGS=-C target-feature=-crt-static so the libs link musl dynamically, which is correct for dynamically-linked Alpine hosts. The crate's crate-type = ["staticlib", "cdylib"] means one cargo zigbuild run emits both libzerobus_ffi.a and libzerobus_ffi.so. Artifacts upload as ffi-linux-musl-x86_64 / ffi-linux-musl-aarch64.
  • Documents the musl cross-compile in rust/ffi/README.md.
  • Adds a rust/ffi/NEXT_CHANGELOG.md entry.

WHY: The FFI library was previously built only for glibc targets, so the glibc-linked artifacts do not load or link on Alpine. This is the FFI counterpart to #324 (Java request), which was implemented for JNI in #347 but left the FFI build unchanged — so direct C/C++ consumers on Alpine were still unsupported. This PR mirrors the #347 workflow approach for FFI.

The Java side of #347 also had a runtime NativeLoader (it bundles all platforms in one JAR and selects the lib at load time). The FFI library has no runtime loader — C/C++ consumers link the linux-musl-* directory they download directly — so there is no analogous code to add here. Per scope decision, the release-go.yml / Go-on-Alpine path (which needs cgo build-tag plumbing to distinguish musl from glibc) is left to a separate change.

Fixes #411

How is this tested?

Triggered & passed - https://github.com/databricks/zerobus-sdk/actions/runs/28018404039

CI/packaging change only — no unit-testable code paths. Validated the release-ffi.yml YAML parses and that the new matrix rows reuse the existing Prepare artifacts / Upload artifact steps (keyed off matrix.artifact_dir / static_lib / dynamic_lib). The workflow is workflow_dispatch-triggered; a manual release-ffi.yml run is the end-to-end verification, mirroring how #347 was validated via a triggered release-jni.yml run.

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>
@zlata-stefanovic-db
zlata-stefanovic-db marked this pull request as ready for review June 23, 2026 09:25
Comment thread rust/ffi/NEXT_CHANGELOG.md Outdated

### New Features and Improvements

- 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think we need the last sentence.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deleted

Comment thread .github/workflows/release-ffi.yml Outdated

- name: Install Zig (musl cross-builds)
if: matrix.zigbuild
uses: mlugg/setup-zig@a67e68dc5c8281d9608136d3d7ca1b282213e4ac # v2.0.1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not the latest (v2.2.1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No good reason, it was just the one used by Teodor, changed it now in both workflows.

Signed-off-by: Zlata Stefanovic <zlata.stefanovic@databricks.com>
@zlata-stefanovic-db
zlata-stefanovic-db added this pull request to the merge queue Jun 23, 2026
Merged via the queue into main with commit 4bd2f6a Jun 23, 2026
39 checks passed
@zlata-stefanovic-db
zlata-stefanovic-db deleted the ffi-musl-support branch June 23, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Rust][FFI] Linux Alpine compatibility - Support for musl (FFI)

5 participants