Skip to content

Commit 829956c

Browse files
headiusmrkn
authored andcommitted
Stub out extension build on JRuby
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 #169
1 parent 4b8572d commit 829956c

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
33
gemspec
44

55
gem "benchmark_driver"
6-
gem "fiddle"
6+
gem "fiddle", platform: :ruby
77
gem "rake", ">= 12.3.3"
88
gem "rake-compiler", ">= 0.9"
99
gem "minitest", "< 5.0.0"

Rakefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ require "rake/extensiontask"
66
require "rake/testtask"
77

88
spec = eval(File.read('bigdecimal.gemspec'))
9-
Rake::ExtensionTask.new('bigdecimal', spec)
9+
if RUBY_ENGINE == 'jruby'
10+
# JRuby's extension is included with JRuby currently
11+
task :compile do; end
12+
else
13+
Rake::ExtensionTask.new('bigdecimal', spec)
14+
end
1015

1116
Rake::TestTask.new do |t|
1217
t.libs << 'test/lib'

bigdecimal.gemspec

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,8 @@ Gem::Specification.new do |s|
1212
s.licenses = ["Ruby", "bsd-2-clause"]
1313

1414
s.require_paths = %w[lib]
15-
s.extensions = %w[ext/bigdecimal/extconf.rb]
1615
s.files = %w[
1716
bigdecimal.gemspec
18-
ext/bigdecimal/bigdecimal.c
19-
ext/bigdecimal/bigdecimal.h
20-
ext/bigdecimal/bits.h
21-
ext/bigdecimal/feature.h
22-
ext/bigdecimal/missing.c
23-
ext/bigdecimal/missing.h
24-
ext/bigdecimal/missing/dtoa.c
25-
ext/bigdecimal/static_assert.h
2617
lib/bigdecimal.rb
2718
lib/bigdecimal/jacobian.rb
2819
lib/bigdecimal/ludcmp.rb
@@ -33,6 +24,21 @@ Gem::Specification.new do |s|
3324
sample/nlsolve.rb
3425
sample/pi.rb
3526
]
27+
if Gem::Platform === s.platform and s.platform =~ 'java' or RUBY_ENGINE == 'jruby'
28+
s.platform = 'java'
29+
else
30+
s.extensions = %w[ext/bigdecimal/extconf.rb]
31+
s.files += %w[
32+
ext/bigdecimal/bigdecimal.c
33+
ext/bigdecimal/bigdecimal.h
34+
ext/bigdecimal/bits.h
35+
ext/bigdecimal/feature.h
36+
ext/bigdecimal/missing.c
37+
ext/bigdecimal/missing.h
38+
ext/bigdecimal/missing/dtoa.c
39+
ext/bigdecimal/static_assert.h
40+
]
41+
end
3642

3743
s.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
3844
end

lib/bigdecimal.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
require 'bigdecimal.so'
1+
if RUBY_ENGINE == 'jruby'
2+
JRuby::Util.load_ext("org.jruby.ext.bigdecimal.BigDecimalLibrary")
3+
else
4+
require 'bigdecimal.so'
5+
end

0 commit comments

Comments
 (0)