Skip to content

Commit

Permalink
#17 build native extesion independent of ruby version (#18)
Browse files Browse the repository at this point in the history
* #17 build native extesion independent of ruby version

* Fix Don't know how to build task 'native:x64-mingw-ucrt' issue

* Move development gems for Gemfile

* Force ruby_cc_version to 3.0.0 for x64-mingw32

* Remove unnecessary native task & fix ruby version for x64-mingw
  • Loading branch information
CAMOBAP authored Mar 27, 2023
1 parent b023fcb commit b050fdb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 33 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
/spec/reports/
/tmp/
/Gemfile.lock
**/*.so
**/*.o

/lib/*.so
/lib/*.bundle
/ext/*.o

# remote file cache
.rubocop-*
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ source "https://rubygems.org"

# Specify your gem's dependencies in extract_ttc.gemspec
gemspec

gem "rake-compiler", "~> 1.2"
gem "rake-compiler-dock", "~> 1.2"
gem "rspec", "~> 3.0"
gem "rubocop", "~> 1.5"
gem "rubocop-performance", "~> 1.10"
gem "rubocop-rails", "~> 2.9"
38 changes: 20 additions & 18 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,26 @@ rescue LoadError
end
# -- Allow rake-compiler-dock configuration without dev. dependencies

R_CC_V = "RUBY_CC_VERSION=3.1.0:3.0.0:2.7.0".freeze
ruby_cc_version = "3.1.0"
bundler_ver = ENV["BUNDLER_VER"] || "2.3.22"

task default: :spec
task spec: :compile

spec = Gem::Specification.load("extract_ttc.gemspec")

ext_thru_rc_dock = %w[x86_64-linux aarch64-linux] +
%w[x64-mingw32 x64-mingw-ucrt x86_64-darwin arm64-darwin]

ext_thru_rc_dock = %w[
x86_64-linux
aarch64-linux
x64-mingw32
x64-mingw-ucrt
x86_64-darwin
arm64-darwin
]

# TODO automate build with:
# "rbsys/x86_64-linux-musl:latest" - for x86_64-linux-musl
# "*" - find/create image for aarch64-linux-musl
ext_thru_musl_cc = %w[x86_64-linux-musl aarch64-linux-musl]

# HACK: Prevent rake-compiler from overriding required_ruby_version,
Expand Down Expand Up @@ -60,31 +69,24 @@ namespace "gem" do
RCD
end

desc "build native gems with rake-compiler-dock"
task "native" => "cache" do
ext_thru_rc_dock.each do |plat|
RakeCompilerDock.sh <<~RCD, platform: plat
gem install bundler:#{bundler_ver} --no-document &&
bundle install --local &&
bundle exec rake native:#{plat} gem #{R_CC_V}
RCD
end
end
end

namespace "gem" do
ext_thru_rc_dock.each do |plat|
desc "Build native gems with rake-compiler-dock in parallel"
multitask "parallel" => plat

desc "Build the native gem for #{plat}"
task plat => "cache" do
ruby_cc_ver = if plat == "x64-mingw32"
"3.0.0"
else
ruby_cc_version
end

RakeCompilerDock.sh <<~RCD, platform: plat
gem install bundler:#{bundler_ver} --no-document &&
bundle install --local &&
bundle exec rake native:#{plat} \
pkg/#{exttask.gem_spec.full_name}-#{plat}.gem \
#{R_CC_V}
RUBY_CC_VERSION=#{ruby_cc_ver}
RCD
end
end
Expand Down
7 changes: 0 additions & 7 deletions extract_ttc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "bundler", "~> 2.3", ">= 2.3.22"
spec.add_runtime_dependency "ffi", "~> 1.0"
spec.add_runtime_dependency "rake", "~> 13"
spec.add_runtime_dependency "rake-compiler", "~> 1.2"
spec.add_runtime_dependency "rake-compiler-dock", "~> 1.2"

spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop", "~> 1.5"
spec.add_development_dependency "rubocop-performance", "~> 1.10"
spec.add_development_dependency "rubocop-rails", "~> 2.9"

spec.extensions << "ext/stripttc/extconf.rb"
spec.metadata["rubygems_mfa_required"] = "false"
Expand Down
7 changes: 1 addition & 6 deletions lib/extract_ttc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ class UnknownResultError < Error; end
extend FFI::Library
# NOTE: ffi doesn't support bundles out of box https://github.com/ffi/ffi/issues/42#issuecomment-750031554
# NOTE: rake-compiler doesn't support dylib generation https://github.com/rake-compiler/rake-compiler/issues/183
lib_subdir = RUBY_VERSION.split(".").first(2).join(".")
macos_binary = "stripttc.bundle"
lib_name = if File.exist?(
File.join(File.dirname(__FILE__), lib_subdir, macos_binary),
)
File.join(lib_subdir, macos_binary)
elsif File.exist?(File.join(File.dirname(__FILE__), macos_binary))
lib_name = if File.exist?(File.join(File.dirname(__FILE__), macos_binary))
macos_binary
else
"stripttc.so"
Expand Down

0 comments on commit b050fdb

Please sign in to comment.