Skip to content

Commit 29ed0a8

Browse files
authored
Implement a workaround for FFI (#17)
1 parent 8fca842 commit 29ed0a8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ruby/private/bundle/create_bundle_build_file.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/specifications/#{gem_name}-#{gem_version}*.gemspec").first
8585
end
8686

87+
HERE = File.absolute_path '.'
88+
8789
require 'bundler'
8890
require 'json'
8991
require 'stringio'
@@ -261,7 +263,14 @@ def register_gem(spec, template_out, bundle_lib_paths, bundle_binaries)
261263
# Usually, registering the directory paths listed in the `require_paths` of gemspecs is sufficient, but
262264
# some gems also require additional paths to be included in the load paths.
263265
require_paths += include_array(spec.name)
264-
gem_lib_paths = require_paths.map { |require_path| File.join(gem_path, require_path) }
266+
gem_lib_paths = require_paths.map do |require_path|
267+
# Gems with native extensions (like ffi) will sometimes have elements of
268+
# require_paths that are absolute rather than gem-path relative paths.
269+
# It is incorrect to prepend those paths with the gem_path and Bazel will
270+
# only allow relative paths as inputs to its glob() function.
271+
pathname = Pathname.new(require_path)
272+
pathname.absolute? ? pathname.relative_path_from(HERE).to_s : File.join(gem_path, require_path)
273+
end
265274
bundle_lib_paths.push(*gem_lib_paths)
266275

267276
# paths to search for executables

0 commit comments

Comments
 (0)