diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..962a526 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,57 @@ +name: Release + +on: + workflow_dispatch: + push: + tags: [ "v*.*.*" ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + ci-data: + runs-on: ubuntu-latest + name: CI Data + outputs: + result: ${{ steps.fetch.outputs.result }} + steps: + - name: Fetch CI Data + uses: oxidize-rb/actions/fetch-ci-data@v1 + id: fetch + with: + supported-ruby-platforms: | + exclude: [] + stable-ruby-versions: | + exclude: [head] + cross-gem: + name: Compile native gem for ${{ matrix.platform }} + runs-on: ubuntu-latest + needs: ci-data + strategy: + fail-fast: false + matrix: + platform: ${{ fromJSON(needs.ci-data.outputs.result).supported-ruby-platforms }} + ruby: + - "2.7.8" + steps: + - uses: actions/checkout@v3 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + rubygems: "3.4.14" + + - uses: oxidize-rb/actions/cross-gem@v1 + id: cross-gem + with: + platform: ${{ matrix.platform }} + ruby-versions: ${{ join(fromJSON(needs.ci-data.outputs.result).stable-ruby-versions, ',') }} + + - uses: actions/upload-artifact@v3 + with: + name: cross-gem-${{ matrix.ruby-platform }} + path: ${{ steps.cross-gem.outputs.gem-path }} + if-no-files-found: error + retention-days: 1 diff --git a/Rakefile b/Rakefile index 6b70ef3..c2ea8bb 100644 --- a/Rakefile +++ b/Rakefile @@ -19,6 +19,7 @@ gemspec = Gem::Specification.load("xml2json.gemspec") RbSys::ExtensionTask.new("xml2json", gemspec) do |ext| ext.lib_dir = "lib/xml2json" + ext.cross_compile = true end task :clippy do diff --git a/lib/xml2json.rb b/lib/xml2json.rb index f0523fc..dc6fd46 100644 --- a/lib/xml2json.rb +++ b/lib/xml2json.rb @@ -1,7 +1,11 @@ # frozen_string_literal: true require_relative "xml2json/version" -require_relative "xml2json/xml2json" +begin + require_relative "xml2json/#{RUBY_VERSION[/(\d+\.\d+)/, 1]}/xml2json" +rescue LoadError + require_relative "xml2json/xml2json" +end # @see https://docs.rs/xml2json-rs/1.0.1/xml2json_rs/index.html docs for the wrapped library module Xml2Json