-
Notifications
You must be signed in to change notification settings - Fork 2
Add precompiled binary gem support and modernize build system #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
71a316f
c26a27c
994102d
eaf4063
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| name: "Package and release gems with precompiled binaries" | ||
| on: | ||
| # TODO: remove this temporary trigger before merging; it exists only to | ||
| # test the workflow pre-merge (workflow_dispatch requires the file to be | ||
| # on the default branch). | ||
| push: | ||
| branches: | ||
| - claude/precompile-jq-gem-0g9x67 | ||
| workflow_dispatch: | ||
| inputs: | ||
| release: | ||
| description: "If the whole build passes on all platforms, release the gems on RubyGems.org" | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
| env: | ||
| CIBUILDGEM: 1 | ||
| jobs: | ||
| compile: | ||
| timeout-minutes: 20 | ||
| name: "Cross compile the gem on different ruby versions" | ||
| strategy: | ||
| matrix: | ||
| os: ["macos-latest", "ubuntu-22.04"] | ||
| runs-on: "${{ matrix.os }}" | ||
| steps: | ||
| - name: "Checkout code" | ||
| uses: "actions/checkout@v5" | ||
| - name: "Install autotools" | ||
| if: "${{ runner.os == 'macOS' }}" | ||
| run: brew install autoconf automake libtool | ||
| - name: "Setup Ruby" | ||
| uses: "ruby/setup-ruby@v1" | ||
| with: | ||
| ruby-version: "3.3.9" | ||
| bundler-cache: true | ||
| - name: "Run cibuildgem" | ||
| uses: "shopify/cibuildgem/.github/actions/cibuildgem@main" | ||
| with: | ||
| step: "compile" | ||
| test: | ||
| timeout-minutes: 20 | ||
| name: "Run the test suite" | ||
| needs: compile | ||
| strategy: | ||
| matrix: | ||
| os: ["macos-latest", "ubuntu-22.04"] | ||
| rubies: ["4.0", "3.4", "3.3"] | ||
| type: ["cross", "native"] | ||
| runs-on: "${{ matrix.os }}" | ||
| steps: | ||
| - name: "Checkout code" | ||
| uses: "actions/checkout@v5" | ||
| - name: "Install autotools" | ||
| if: "${{ runner.os == 'macOS' && matrix.type == 'native' }}" | ||
| run: brew install autoconf automake libtool | ||
| - name: "Setup Ruby" | ||
| uses: "ruby/setup-ruby@v1" | ||
| with: | ||
| ruby-version: "${{ matrix.rubies }}" | ||
| bundler-cache: true | ||
| - name: "Run cibuildgem" | ||
| uses: "shopify/cibuildgem/.github/actions/cibuildgem@main" | ||
| with: | ||
| step: "test_${{ matrix.type }}" | ||
| install: | ||
| timeout-minutes: 15 | ||
| name: "Verify the gem can be installed" | ||
| needs: test | ||
| strategy: | ||
| matrix: | ||
| os: ["macos-latest", "ubuntu-22.04"] | ||
| runs-on: "${{ matrix.os }}" | ||
| steps: | ||
| - name: "Install autotools" | ||
| if: "${{ runner.os == 'macOS' }}" | ||
| run: brew install autoconf automake libtool | ||
| - name: "Setup Ruby" | ||
| uses: "ruby/setup-ruby@v1" | ||
| with: | ||
| ruby-version: "4.0.0" | ||
| - name: "Run cibuildgem" | ||
| uses: "shopify/cibuildgem/.github/actions/cibuildgem@main" | ||
| with: | ||
| step: "install" | ||
| release: | ||
| environment: release | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| timeout-minutes: 5 | ||
| if: ${{ inputs.release }} | ||
| name: "Release all gems with RubyGems" | ||
| needs: install | ||
| runs-on: "ubuntu-latest" | ||
| steps: | ||
| - name: "Setup Ruby" | ||
| uses: "ruby/setup-ruby@v1" | ||
| with: | ||
| ruby-version: "4.0.0" | ||
| - name: "Run cibuildgem" | ||
| uses: "shopify/cibuildgem/.github/actions/cibuildgem@main" | ||
| with: | ||
| step: "release" |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,16 +7,33 @@ def using_system_libraries? | |
| end | ||
|
|
||
| unless using_system_libraries? | ||
| message "Buildling jq using packaged libraries.\n" | ||
| message "Building jq using packaged libraries.\n" | ||
|
|
||
| require 'rubygems' | ||
| require 'mini_portile2' | ||
|
|
||
| recipe = MiniPortile.new('jq', '1.6') | ||
| recipe.files = ['https://github.com/stedolan/jq/archive/jq-1.6.tar.gz'] | ||
| onigmo = MiniPortile.new('onigmo', '6.2.0') | ||
| onigmo.files = ['https://github.com/k-takata/Onigmo/releases/download/Onigmo-6.2.0/onigmo-6.2.0.tar.gz'] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add the expected sha256 |
||
| onigmo.configure_options = [ | ||
| '--disable-shared', | ||
| '--enable-static', | ||
| '--with-pic' | ||
| ] | ||
| onigmo.cook | ||
|
|
||
| # OpsLevel fork of jq: `env`/`$ENV` always return an empty object. | ||
| recipe = MiniPortile.new('jq', '1.6.opslevel') | ||
| recipe.files = ['https://github.com/OpsLevel/jq/archive/845f4206dd8a82355325bafffbb54a5155cf67ec.tar.gz'] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here as well |
||
| recipe.configure_options = [ | ||
| '--enable-shared', | ||
| '--disable-maintainer-mode' | ||
| '--disable-maintainer-mode', | ||
| '--disable-docs', | ||
| '--disable-shared', | ||
| '--enable-static', | ||
| '--with-pic', | ||
| "--with-oniguruma=#{onigmo.path}", | ||
| # macOS declares lgamma_r only under _REENTRANT; jq's configure detects | ||
| # the symbol via a link check, so compilation fails without this. | ||
| 'CPPFLAGS=-D_REENTRANT' | ||
| ] | ||
| class << recipe | ||
| def configure | ||
|
|
@@ -26,10 +43,18 @@ def configure | |
| end | ||
| recipe.cook | ||
| recipe.activate | ||
| $LIBPATH = ["#{recipe.path}/lib"] | $LIBPATH # rubocop:disable Style/GlobalVars | ||
| $LIBPATH = ["#{recipe.path}/lib", "#{onigmo.path}/lib"] | $LIBPATH # rubocop:disable Style/GlobalVars | ||
| $CPPFLAGS << " -I#{recipe.path}/include" # rubocop:disable Style/GlobalVars | ||
|
|
||
| abort 'libonigmo not found' unless have_library('onigmo') | ||
| end | ||
|
|
||
| abort 'libjq not found' unless have_library('jq') | ||
|
|
||
| create_makefile('jq_core') | ||
| # On ELF platforms, keep the statically linked jq/Onigmo symbols out of the | ||
| # extension's dynamic symbol table: libruby exports its own onig_* functions, | ||
| # and the flat ELF namespace would let calls bind across copies. (Mach-O uses | ||
| # two-level namespaces, and its linker lacks this flag.) | ||
| $LDFLAGS << ' -Wl,--exclude-libs,ALL' unless RUBY_PLATFORM.include?('darwin') # rubocop:disable Style/GlobalVars | ||
|
|
||
| create_makefile('jq/jq_core') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,14 @@ | |
| require 'tempfile' | ||
| require 'stringio' | ||
|
|
||
| require 'jq_core' | ||
| begin | ||
| # Load the precompiled binary matching the current Ruby, if this is a | ||
| # platform-specific gem packaged by cibuildgem. | ||
| require "jq/#{RUBY_VERSION[/\d+\.\d+/]}/jq_core" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand how this magic works
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but it is the suggested path here: https://github.com/Shopify/cibuildgem/wiki/1.-Setup-cibuildgem-on-your-project#prepare-your-gem-to-load-the-right-binary |
||
| rescue LoadError | ||
| # Fall back to the extension compiled from source at install time. | ||
| require 'jq/jq_core' | ||
| end | ||
| require 'jq/version' | ||
| require 'jq/parser' | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module JQ | ||
| VERSION = '0.2.2' | ||
| VERSION = '0.3.0' | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| $LOAD_PATH << File.dirname(__FILE__) + '/../lib' | ||
| $LOAD_PATH << "#{File.dirname(__FILE__)}/../lib" | ||
| require 'tempfile' | ||
| require 'jq' | ||
| require 'jq/extend' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or what this does