Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ if RUBY_PLATFORM =~ /java/
else
require 'rake/extensiontask'
spec = Gem::Specification.load("psych.gemspec")
# Add stub/ on $LOAD_PATH only for binary gems
spec.require_paths.insert(0, *%w[stub])
Rake::ExtensionTask.new("psych", spec) do |ext|
ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
ext.cross_compile = true
Expand Down
25 changes: 13 additions & 12 deletions lib/psych.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# frozen_string_literal: true
require 'psych/versions'
case RUBY_ENGINE
when 'jruby'
require 'psych_jars'
if JRuby::Util.respond_to?(:load_ext)
JRuby::Util.load_ext('org.jruby.ext.psych.PsychLibrary')

# When required from the stub file, the C extension is already loaded
unless caller_locations(1, 1)[0].absolute_path == File.expand_path('../stub/psych.rb', __dir__)
case RUBY_ENGINE
when 'jruby'
require 'psych_jars'
if JRuby::Util.respond_to?(:load_ext)
JRuby::Util.load_ext('org.jruby.ext.psych.PsychLibrary')
else
require 'java'; require 'jruby'
org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false)
end
else
require 'java'; require 'jruby'
org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false)
end
else
begin
require "#{RUBY_VERSION[/\d+\.\d+/]}/psych.so"
rescue LoadError
require 'psych.so'
end
end

require 'psych/nodes'
require 'psych/streaming'
require 'psych/visitors'
Expand Down
3 changes: 2 additions & 1 deletion psych.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ DESCRIPTION
"lib/psych/set.rb", "lib/psych/stream.rb", "lib/psych/streaming.rb", "lib/psych/syntax_error.rb",
"lib/psych/tree_builder.rb", "lib/psych/versions.rb", "lib/psych/visitors.rb","lib/psych/visitors/depth_first.rb",
"lib/psych/visitors/emitter.rb", "lib/psych/visitors/json_tree.rb", "lib/psych/visitors/to_ruby.rb",
"lib/psych/visitors/visitor.rb", "lib/psych/visitors/yaml_tree.rb", "lib/psych/y.rb", "psych.gemspec"
"lib/psych/visitors/visitor.rb", "lib/psych/visitors/yaml_tree.rb", "lib/psych/y.rb", "psych.gemspec",
"stub/psych.rb"
]

s.rdoc_options = ["--main", "README.md"]
Expand Down
6 changes: 6 additions & 0 deletions stub/psych.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

# This file is only on $LOAD_PATH when using a binary gem

require "#{RUBY_VERSION[/\d+\.\d+/]}/psych.so"
require_relative '../lib/psych'