Skip to content

Commit 0837a06

Browse files
committed
Allow to ship this gem with precompiled binaries
TL;DR I'd like to propose releasing the json gem with precompiled binaries built for different platforms and different ABI version (fat gem). I'm currently working on a tool to help the Ruby community ship gems with precompiled binaries with the intent to make `bundle install` much faster for everyone. The main bottleneck when installing gems in a project is the compilation of native extensions. [cibuildgem](https://github.com/Shopify/cibuildgem) modestly tries to follow the same approach as what the python community did with [cibuildwheel](https://cibuildwheel.pypa.io/en/stable/). It works with a native compilation using CI runners (GitHub it the only supported vendor for now) and tries to be as easy to setup as possible. This gem already relies on Rake Compiler for development purposes, and because cibuildgem piggyback on top of Rake Compiler, there is no extra configuration required. The CI workflow in this commit was generated with the cibuildgem CLI which reads the gemspec and determine what ruby versions needs to be compiled and tested agains. The tool is very new and I did many tests internally to make sure that it create binaries that can be ported to other environment. For instance, I used it to precompile almost all gems that a new Rails application depends on and pushed them under a "namespaced" name on my [RubyGems](https://rubygems.org/profiles/edouardchin), I then confirmed that the rails application was bootable using all those gems (I'm on MacOS).
1 parent f36707c commit 0837a06

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed

.github/workflows/cibuildgem.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: "Package and release gems with precompiled binaries"
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
release:
6+
description: "If the whole build passes on all platforms, release the gems on RubyGems.org"
7+
required: false
8+
type: boolean
9+
default: false
10+
jobs:
11+
compile:
12+
timeout-minutes: 20
13+
name: "Cross compile the gem on different ruby versions"
14+
strategy:
15+
matrix:
16+
os: ["macos-latest", "ubuntu-22.04"]
17+
runs-on: "${{ matrix.os }}"
18+
steps:
19+
- name: "Checkout code"
20+
uses: "actions/checkout@v5"
21+
- name: "Setup Ruby"
22+
uses: "ruby/setup-ruby@v1"
23+
with:
24+
ruby-version: "3.1.7"
25+
bundler-cache: true
26+
- name: "Run cibuildgem"
27+
uses: "shopify/cibuildgem/.github/actions/cibuildgem@main"
28+
with:
29+
step: "compile"
30+
test:
31+
timeout-minutes: 20
32+
name: "Run the test suite"
33+
needs: compile
34+
strategy:
35+
matrix:
36+
os: ["macos-latest", "ubuntu-22.04"]
37+
rubies: ["3.1", "3.2", "3.3", "3.4"]
38+
type: ["cross", "native"]
39+
runs-on: "${{ matrix.os }}"
40+
steps:
41+
- name: "Checkout code"
42+
uses: "actions/checkout@v5"
43+
- name: "Setup Ruby"
44+
uses: "ruby/setup-ruby@v1"
45+
with:
46+
ruby-version: "${{ matrix.rubies }}"
47+
bundler-cache: true
48+
- name: "Run cibuildgem"
49+
uses: "shopify/cibuildgem/.github/actions/cibuildgem@main"
50+
with:
51+
step: "test_${{ matrix.type }}"
52+
install:
53+
timeout-minutes: 5
54+
name: "Verify the gem can be installed"
55+
needs: test
56+
strategy:
57+
matrix:
58+
os: ["macos-latest", "ubuntu-22.04"]
59+
runs-on: "${{ matrix.os }}"
60+
steps:
61+
- name: "Setup Ruby"
62+
uses: "ruby/setup-ruby@v1"
63+
with:
64+
ruby-version: "3.4.7"
65+
- name: "Run cibuildgem"
66+
uses: "shopify/cibuildgem/.github/actions/cibuildgem@main"
67+
with:
68+
step: "install"
69+
release:
70+
permissions:
71+
id-token: write
72+
contents: read
73+
timeout-minutes: 5
74+
if: ${{ inputs.release }}
75+
name: "Release all gems with RubyGems"
76+
needs: install
77+
runs-on: "ubuntu-latest"
78+
steps:
79+
- name: "Setup Ruby"
80+
uses: "ruby/setup-ruby@v1"
81+
with:
82+
ruby-version: "3.4.7"
83+
- name: "Run cibuildgem"
84+
uses: "shopify/cibuildgem/.github/actions/cibuildgem@main"
85+
with:
86+
step: "release"

lib/stack_frames.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# frozen_string_literal: true
22

33
require 'stack_frames/version'
4-
require 'stack_frames/stack_frames'
4+
5+
begin
6+
ruby_version = /(\d+\.\d+)/.match(RUBY_VERSION)
7+
require "stack_frames/#{ruby_version}/stack_frames"
8+
rescue LoadError
9+
require "stack_frames/stack_frames"
10+
end
511

612
StackFrames::Frame.singleton_class.class_eval do
713
private(:new)

0 commit comments

Comments
 (0)