Skip to content

Commit

Permalink
Use Thermite to build/integrate the Rust+Ruby code
Browse files Browse the repository at this point in the history
  • Loading branch information
malept authored and Mark Lee committed Mar 1, 2017
1 parent 31fa441 commit e1125ee
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ mkmf.log
**/*.gem
.idea
/rubyspec_temp/
*.dll
*.dylib
*.so
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ matrix:
before_install:
- gem install bundler -v 1.12.5
- curl -sSf https://static.rust-lang.org/rustup.sh | sudo sh -s -- --channel=nightly
- bundle && bundle exec rake build_src && rake clean_src
- bundle && bundle exec rake build_lib
script: bundle exec rake test
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ repository = "https://github.com/danielpclark/faster_path"
license = "MIT OR Apache-2.0"
readme = "README.md"

[package.metadata.thermite]
github_releases = true

[lib]
name = "faster_path"
crate-type = ["dylib"]
Expand Down
26 changes: 4 additions & 22 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'fileutils'
require 'thermite/tasks'

desc 'Build Rust extension'
task :build_src do
puts 'Building extension...'
sh 'cargo build --release'
end

desc 'Clean up Rust build'
task :clean_src do
puts 'Cleaning up build...'
# Remove all but library file
FileUtils.
rm_rf(
Dir.
glob('target/release/*').
keep_if do |f|
!f[/\.(?:so|dll|dylib|deps)\z/]
end
)
end
thermite = Thermite::Tasks.new

desc 'Build + clean up Rust extension'
task build_lib: [:build_src, :clean_src] do
puts 'Completed build!'
task build_lib: 'thermite:build' do
thermite.run_cargo 'clean'
end

desc 'Code Quality Check'
Expand Down
7 changes: 7 additions & 0 deletions ext/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'thermite/tasks'

project_toplevel_dir = File.dirname(File.dirname(__FILE__))
Thermite::Tasks.new(cargo_project_path: project_toplevel_dir,
ruby_project_path: project_toplevel_dir)

task default: 'thermite:build'
19 changes: 0 additions & 19 deletions ext/faster_path/extconf.rb

This file was deleted.

3 changes: 2 additions & 1 deletion faster_path.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ Gem::Specification.new do |spec|
spec.files += Dir['lib/**/*']
spec.files += Dir['src/**/*']

spec.extensions << "ext/faster_path/extconf.rb"
spec.extensions = ["ext/Rakefile"]
spec.require_paths = ["lib"]

spec.add_dependency "bundler", "~> 1.12"
spec.add_dependency "rake", "~> 12.0"
spec.add_dependency "ffi", "~> 1.9"
spec.add_dependency "thermite", "~> 0.11.0"
spec.add_development_dependency "method_source", "~> 0.8.2"
spec.add_development_dependency "minitest", "~> 5.10"
spec.add_development_dependency "minitest-reporters", "~> 1.1"
Expand Down
11 changes: 7 additions & 4 deletions lib/faster_path.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require "faster_path/version"
require 'faster_path/version'
require 'ffi'
require 'pathname'
require "ffi"
require 'faster_path/asset_resolution'
require 'thermite/config'

module FasterPath
def self.rust_arch_bits
Expand Down Expand Up @@ -73,8 +74,10 @@ def self.entries(pth)
module Rust
extend FFI::Library
ffi_lib begin
prefix = Gem.win_platform? ? "" : "lib"
"#{File.expand_path("../target/release/", __dir__)}/#{prefix}faster_path.#{FFI::Platform::LIBSUFFIX}"
toplevel_dir = File.dirname(File.dirname(__FILE__))
config = Thermite::Config.new(cargo_project_path: toplevel_dir,
ruby_project_path: toplevel_dir)
config.ruby_extension_path
end

class FromRustArray < FFI::Struct
Expand Down
8 changes: 5 additions & 3 deletions test/faster_path_test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require 'test_helper'
require 'ffi'
require 'thermite/config'

class FasterPathTest < Minitest::Test
def test_it_build_linked_library
assert File.exist? begin
prefix = Gem.win_platform? ? "" : "lib"
"#{File.expand_path("../target/release/", File.dirname(__FILE__))}/#{prefix}faster_path.#{FFI::Platform::LIBSUFFIX}"
toplevel_dir = File.dirname(File.dirname(__FILE__))
config = Thermite::Config.new(cargo_project_path: toplevel_dir,
ruby_project_path: toplevel_dir)
config.ruby_extension_path
end
end
end

0 comments on commit e1125ee

Please sign in to comment.