Skip to content

Commit

Permalink
Merge pull request #3223 from eregon/find-libprism-from-rbconfig
Browse files Browse the repository at this point in the history
Use RbConfig to locate libprism and headers when it is a default gem
  • Loading branch information
eileencodes authored Nov 12, 2024
2 parents e4ec598 + 5d16473 commit 7366114
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/prism/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ module LibRubyParser # :nodoc:

# Define the library that we will be pulling functions from. Note that this
# must align with the build shared library from make/rake.
ffi_lib File.expand_path("../../build/libprism.#{RbConfig::CONFIG["SOEXT"]}", __dir__)
libprism_in_build = File.expand_path("../../build/libprism.#{RbConfig::CONFIG["SOEXT"]}", __dir__)
libprism_in_libdir = "#{RbConfig::CONFIG["libdir"]}/prism/libprism.#{RbConfig::CONFIG["SOEXT"]}"
if File.exist? libprism_in_build
INCLUDE_DIR = File.expand_path("../../include", __dir__)
ffi_lib libprism_in_build
else
INCLUDE_DIR = "#{RbConfig::CONFIG["libdir"]}/prism/include"
ffi_lib libprism_in_libdir
end

# Convert a native C type declaration into a symbol that FFI understands.
# For example:
Expand All @@ -38,7 +46,7 @@ def self.resolve_type(type, callbacks)
# given functions. For each one, define a function with the same name and
# signature as the C function.
def self.load_exported_functions_from(header, *functions, callbacks)
File.foreach(File.expand_path("../../include/#{header}", __dir__)) do |line|
File.foreach("#{INCLUDE_DIR}/#{header}") do |line|
# We only want to attempt to load exported functions.
next unless line.start_with?("PRISM_EXPORTED_FUNCTION ")

Expand Down

0 comments on commit 7366114

Please sign in to comment.