Skip to content

Ship precompiled gems for linux, musl and darwin - #157

Open
ThomasSevestre wants to merge 1 commit into
SpringMT:mainfrom
ThomasSevestre:precompiled-gems
Open

ThomasSevestre wants to merge 1 commit into
SpringMT:mainfrom
ThomasSevestre:precompiled-gems

Conversation

@ThomasSevestre

Copy link
Copy Markdown

Installing zstd-ruby currently means compiling the bundled libzstd, which needs a toolchain and takes a while on every install. Cross-compile the extension with rake-compiler-dock instead and publish platform gems for x86_64/aarch64 linux (glibc and musl) and x86_64/arm64 darwin, each carrying binaries for Ruby 3.1 through 4.0.

Anything outside that set - other platforms, Ruby 2.7 and 3.0, future Rubies - still installs the source gem and compiles as before.

rake-compiler puts fat-gem binaries under lib/zstd-ruby/<X.Y>/ and generates no loader, so lib/zstd-ruby.rb now tries the ABI directory first and falls back to the flat path used by source installs.

The native gems drop ext/ via the cross_compiling callback: the binaries are already there and the extension is cleared, so libzstd's sources are 2.2MB of dead weight. The gemspec also stops listing the "zstd" submodule gitlink, which is not a file.

Six platforms times five ABIs is too heavy for every PR, so the workflow runs on version tags, on manual dispatch, and on PRs that touch the build files. Each gem is smoke-tested on a matching target - native runners for x86_64-linux and both macOS, QEMU arm64 containers for aarch64, Alpine for musl - before the tag build pushes it with trusted publishing. The source gem keeps going out through rake release, which is also what creates the tag.

Verified by building the x86_64-linux and x86_64-darwin gems locally: the full spec suite passes against both when installed from the .gem, each Ruby loads its own ABI directory, and the darwin binary still exports only _Init_zstdruby, so the symbol isolation from #104 survives cross-compilation.

You may need to register here to be able to publish pre compiled gems. https://rubygems.org/gems/zstd-ruby/trusted_publishers

Installing zstd-ruby currently means compiling the bundled libzstd, which
needs a toolchain and takes a while on every install. Cross-compile the
extension with rake-compiler-dock instead and publish platform gems for
x86_64/aarch64 linux (glibc and musl) and x86_64/arm64 darwin, each
carrying binaries for Ruby 3.1 through 4.0.

Anything outside that set - other platforms, Ruby 2.7 and 3.0, future
Rubies - still installs the source gem and compiles as before.

rake-compiler puts fat-gem binaries under lib/zstd-ruby/<X.Y>/ and
generates no loader, so lib/zstd-ruby.rb now tries the ABI directory
first and falls back to the flat path used by source installs.

The native gems drop ext/ via the cross_compiling callback: the binaries
are already there and the extension is cleared, so libzstd's sources are
2.2MB of dead weight. The gemspec also stops listing the "zstd" submodule
gitlink, which is not a file.

Six platforms times five ABIs is too heavy for every PR, so the workflow
runs on version tags, on manual dispatch, and on PRs that touch the build
files. Each gem is smoke-tested on a matching target - native runners for
x86_64-linux and both macOS, QEMU arm64 containers for aarch64, Alpine
for musl - before the tag build pushes it with trusted publishing. The
source gem keeps going out through `rake release`, which is also what
creates the tag.

Verified by building the x86_64-linux and x86_64-darwin gems locally: the
full spec suite passes against both when installed from the .gem, each
Ruby loads its own ABI directory, and the darwin binary still exports
only _Init_zstdruby, so the symbol isolation from SpringMT#104 survives
cross-compilation.
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.

1 participant