Skip to content

Commit

Permalink
Stub out extension build on JRuby
Browse files Browse the repository at this point in the history
JRuby currently ships its own internal bigdecimal extension as
part of the core libraries. In order for users to be able to add
bigdecimal to their Gemfile or gem dependencies, we need to stub
out the C extension and just load the extension shipped with
JRuby.

In the future we will try to move our BigDecimal implementation
into the gem, but for now this is the simplest way to make it
installable on JRuby.

See ruby#169
  • Loading branch information
headius committed Feb 9, 2023
1 parent 29c61c9 commit c772eef
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source 'https://rubygems.org'
gemspec

gem "benchmark_driver"
gem "fiddle"
gem "fiddle", platform: :ruby
gem "rake", ">= 12.3.3"
gem "rake-compiler", ">= 0.9"
gem "minitest", "< 5.0.0"
Expand Down
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ require "rake/extensiontask"
require "rake/testtask"

spec = eval(File.read('bigdecimal.gemspec'))
Rake::ExtensionTask.new('bigdecimal', spec)
if RUBY_ENGINE == 'jruby'
# JRuby's extension is included with JRuby currently
task :compile do; end
else
Rake::ExtensionTask.new('bigdecimal', spec)
end

Rake::TestTask.new do |t|
t.libs << 'test/lib'
Expand Down
24 changes: 15 additions & 9 deletions bigdecimal.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,8 @@ Gem::Specification.new do |s|
s.licenses = ["Ruby", "bsd-2-clause"]

s.require_paths = %w[lib]
s.extensions = %w[ext/bigdecimal/extconf.rb]
s.files = %w[
bigdecimal.gemspec
ext/bigdecimal/bigdecimal.c
ext/bigdecimal/bigdecimal.h
ext/bigdecimal/bits.h
ext/bigdecimal/feature.h
ext/bigdecimal/missing.c
ext/bigdecimal/missing.h
ext/bigdecimal/missing/dtoa.c
ext/bigdecimal/static_assert.h
lib/bigdecimal.rb
lib/bigdecimal/jacobian.rb
lib/bigdecimal/ludcmp.rb
Expand All @@ -33,6 +24,21 @@ Gem::Specification.new do |s|
sample/nlsolve.rb
sample/pi.rb
]
if Gem::Platform === s.platform and s.platform =~ 'java' or RUBY_ENGINE == 'jruby'
s.platform = 'java'
else
s.extensions = %w[ext/bigdecimal/extconf.rb]
s.files.append %w[
ext/bigdecimal/bigdecimal.c
ext/bigdecimal/bigdecimal.h
ext/bigdecimal/bits.h
ext/bigdecimal/feature.h
ext/bigdecimal/missing.c
ext/bigdecimal/missing.h
ext/bigdecimal/missing/dtoa.c
ext/bigdecimal/static_assert.h
]
end

s.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
end
6 changes: 5 additions & 1 deletion lib/bigdecimal.rb
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
require 'bigdecimal.so'
if RUBY_ENGINE == 'jruby'
JRuby::Util.load_ext("org.jruby.ext.bigdecimal.BigDecimalLibrary")
else
require 'bigdecimal.so'
end

0 comments on commit c772eef

Please sign in to comment.