Add rb-sys-cross crate for Docker-free cross-compilation via Zig#711
Open
Add rb-sys-cross crate for Docker-free cross-compilation via Zig#711
Conversation
Introduces a new CLI tool that cross-compiles Ruby native extensions using cargo-zigbuild and Zig as the C compiler, eliminating the need for Docker containers during cross-compilation. Key design decisions: - Typed cargo metadata structs instead of raw serde_json::Value - RbConfig newtype for type-safe rbconfig.json handling - Profile enum replacing string-based profile matching - CrossCompileEnv struct for typed cross-compilation environment - GemPackOptions struct to avoid 7-parameter function signatures - OnceLock for regex compilation in rbconfig.rb parsing - Utility module for shared helpers (gz_compress, hex_sha256, etc.) - Associated functions on Platform for find/all/list operations - clap Args derive on BuildOpts to eliminate CLI field duplication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Situation
Cross-compiling Ruby native extensions today means Docker via
rake-compiler-dock— slow to set up, painful to debug, and a heavy dependency for something that's fundamentally a C compiler problem. Zig ships a hermetic cross-compiler for every major platform, making Docker unnecessary for this workflow.Execution
New
rb-sys-crossCLI crate that runs the full cross-compilation pipeline usingcargo-zigbuild:rbconfig.jsonper platform/version (built from source withzig cc, or pulled from GitHub releases)RBCONFIG_*env vars sorb-sys-buildskips shelling out to Ruby entirelycargo zigbuild --target <target> --release --lib.gemwith versioned.sofiles, a version-aware extension loader, and a gemspec derived fromCargo.tomlSupports 8 platforms (aarch64-linux, x86_64-linux, arm-linux, x86-linux, {aarch64,x86_64}-linux-musl, x64-mingw-ucrt, x64-mingw32). No Ruby install required — gem name, version, authors, and license are all pulled from
cargo metadata.```bash
rb-sys-cross build
--platform aarch64-linux --platform x86_64-linux
--ruby-version 3.3 --ruby-version 3.4
→ pkg/my_gem-1.0.0-aarch64-linux.gem, pkg/my_gem-1.0.0-x86_64-linux.gem
```