Skip to content

Commit

Permalink
Merge pull request #5 from driv3r/bundle-extensions-together
Browse files Browse the repository at this point in the history
Bring back multi bundle
  • Loading branch information
driv3r authored Jan 7, 2021
2 parents 5781aba + f197ed1 commit 94ab462
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 25 deletions.
36 changes: 28 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ jobs:
bundle install
- name: Build shared library
run: bundle exec rake thermite:build
run: |
bundle exec rake build
ls -l ext/
- name: Rust test
uses: actions-rs/cargo@v1
Expand All @@ -99,21 +101,39 @@ jobs:
- name: Tests
run: bundle exec rspec

- name: Package binary extension
run: bundle exec rake thermite:tarball
- uses: actions/upload-artifact@v2
with:
name: rusty_json_schema-${{ matrix.os }}
path: ext/*.default

build:
needs: [cross_compile]

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1

- uses: actions/download-artifact@v2

- name: Unpack prebuild libraries
run: |
mv rusty_json_schema-macos-latest/*.default ext/
mv rusty_json_schema-ubuntu-latest/*.default ext/
mv rusty_json_schema-windows-latest/*.default ext/
- name: Build gem
env:
PER_PLATFORM_BUILD: true
run: gem build *.gemspec

- uses: actions/upload-artifact@v2
with:
name: rusty_json_schema-${{ matrix.os }}
name: rusty_json_schema.gem
path: '*.gem'

integration_test:
needs: [cross_compile]
needs: [build]

strategy:
matrix:
Expand All @@ -139,7 +159,7 @@ jobs:

- uses: actions/download-artifact@v2
with:
name: rusty_json_schema-${{ (startsWith(matrix.os, 'ubuntu') && 'ubuntu-latest') || matrix.os }}
name: rusty_json_schema.gem

- name: Install gem
run: gem install *.gem
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.1]
### Changed
- Package pre-build binaries together

## [0.3.0]
### Added
- Compile gem during installation when rustc is available
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rusty_json_schema (0.3.0)
rusty_json_schema (0.3.1)
ffi (~> 1.14)
json (>= 1.0)
thermite (~> 0)
Expand Down
20 changes: 10 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new
thermite = Thermite::Tasks.new

namespace :thermite do
desc "Make existing extension default one"
task :default do
next unless File.exist?(thermite.config.ruby_extension_path)

FileUtils.mv(thermite.config.ruby_extension_path,
"#{thermite.config.ruby_extension_path}.default")
desc "Make existing extension default one"
task build: ["thermite:build"] do
unless File.exist?(thermite.config.ruby_extension_path)
puts "File doesn't exist: #{thermite.config.ruby_extension_path.inspect}"
next
end
end

Rake::Task["thermite:build"].enhance(["thermite:default"])
puts "Make #{thermite.config.ruby_extension_path} a #{Gem::Platform.local} default implementation"
FileUtils.cp(thermite.config.ruby_extension_path,
"#{thermite.config.ruby_extension_path}.#{Gem::Platform.local}.default")
end

task default: %i[thermite:build thermite:test spec rubocop]
task default: %i[build thermite:test spec rubocop]
12 changes: 9 additions & 3 deletions ext/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@ thermite = Thermite::Tasks.new(cargo_project_path: project_dir,
namespace :thermite do
desc "Try to build extension if cargo is available or setup default lib"
task :build_or_default do
default_ext_path = "#{thermite.config.ruby_extension_path}.#{Gem::Platform.local}.default"

if thermite.cargo
profile = ENV.fetch("CARGO_PROFILE", "release")
thermite.run_cargo_rustc(profile)

FileUtils.cp(thermite.config.cargo_target_path(profile, thermite.config.cargo_shared_library),
thermite.config.ruby_extension_path)
else
puts "NOTE: Defaults to pre-build binary => your mileage may vary."
elsif File.exist?(default_ext_path)
puts "NOTE: Defaults to pre-build binary #{default_ext_path.inspect} => your mileage may vary."

FileUtils.mv("#{thermite.config.ruby_extension_path}.default",
FileUtils.mv(default_ext_path,
thermite.config.ruby_extension_path)

thermite.inform_user_about_cargo
else
# Prebuild binary is not available for a given platform, install cargo to
# compile the gem
raise thermite.cargo_required_msg
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rusty_json_schema/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module RustyJSONSchema

VERSION = "0.3.0"
VERSION = "0.3.1"

end
3 changes: 1 addition & 2 deletions rusty_json_schema.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
Currently during heavy development.
STR

spec.platform = Gem::Platform::CURRENT if ENV.key?("PER_PLATFORM_BUILD")
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")

spec.metadata["allowed_push_host"] = "https://rubygems.org"
Expand All @@ -32,7 +31,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
"LICENSE",
"README.md",
"ext/Rakefile",
"ext/json_schema.so.default"
"ext/*.default"
]

spec.require_paths = ["lib"]
Expand Down

0 comments on commit 94ab462

Please sign in to comment.