From b7f3e9756f3c45527be27bc38840d5a1ba690436 Mon Sep 17 00:00:00 2001 From: Jason Lunn Date: Fri, 14 Jul 2023 10:16:17 -0400 Subject: [PATCH] Implement a workaround for FFI --- ruby/private/bundle/create_bundle_build_file.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ruby/private/bundle/create_bundle_build_file.rb b/ruby/private/bundle/create_bundle_build_file.rb index 52626cf..ee981ec 100755 --- a/ruby/private/bundle/create_bundle_build_file.rb +++ b/ruby/private/bundle/create_bundle_build_file.rb @@ -84,6 +84,8 @@ Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/specifications/#{gem_name}-#{gem_version}*.gemspec").first end +HERE = File.absolute_path '.' + require 'bundler' require 'json' require 'stringio' @@ -261,7 +263,14 @@ def register_gem(spec, template_out, bundle_lib_paths, bundle_binaries) # Usually, registering the directory paths listed in the `require_paths` of gemspecs is sufficient, but # some gems also require additional paths to be included in the load paths. require_paths += include_array(spec.name) - gem_lib_paths = require_paths.map { |require_path| File.join(gem_path, require_path) } + gem_lib_paths = require_paths.map do |require_path| + # Gems with native extensions (like ffi) will sometimes have elements of + # require_paths that are absolute rather than gem-path relative paths. + # It is incorrect to prepend those paths with the gem_path and Bazel will + # only allow relative paths as inputs to its glob() function. + pathname = Pathname.new(require_path) + pathname.absolute? ? pathname.relative_path_from(HERE).to_s : File.join(gem_path, require_path) + end bundle_lib_paths.push(*gem_lib_paths) # paths to search for executables