From c6b548accbd211b69b0611b584e7673147aaea41 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Thu, 18 Jan 2024 19:45:05 -0600 Subject: [PATCH] [ruby/nkf] Add JRuby extension to the gem This pulls in the nkf extension implementation from JRuby. The build and load logic has been updated along the same lines as ruby/digest and the gem appears to build correctly for the -java platform. Fixes https://github.com/ruby/nkf/pull/13 https://github.com/ruby/nkf/commit/18f57f36ed --- ext/nkf/nkf.gemspec | 14 +++++++++++--- lib/nkf.rb | 6 ++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 lib/nkf.rb diff --git a/ext/nkf/nkf.gemspec b/ext/nkf/nkf.gemspec index 097a9485ed..7fb5cc3be0 100644 --- a/ext/nkf/nkf.gemspec +++ b/ext/nkf/nkf.gemspec @@ -11,8 +11,8 @@ end Gem::Specification.new do |spec| spec.name = "nkf" spec.version = source_version - spec.authors = ["NARUSE Yui"] - spec.email = ["naruse@airemix.jp"] + spec.authors = ["NARUSE Yui", "Charles Oliver Nutter"] + spec.email = ["naruse@airemix.jp", "headius@headius.com"] spec.summary = %q{Ruby extension for Network Kanji Filter} spec.description = %q{Ruby extension for Network Kanji Filter} @@ -28,8 +28,16 @@ Gem::Specification.new do |spec| spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } end + + if Gem::Platform === spec.platform and spec.platform =~ 'java' or RUBY_ENGINE == 'jruby' + spec.platform = 'java' + + spec.files += Dir["lib/nkf.jar"] + else + spec.extensions = ["ext/nkf/extconf.rb"] + end + spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.extensions = ["ext/nkf/extconf.rb"] end diff --git a/lib/nkf.rb b/lib/nkf.rb new file mode 100644 index 0000000000..d71717d8d8 --- /dev/null +++ b/lib/nkf.rb @@ -0,0 +1,6 @@ +if RUBY_ENGINE == "jruby" + require 'nkf.jar' + JRuby::Util.load_ext('org.jruby.ext.nkf.NKFLibrary') +else + require 'nkf.so' +end