diff options
Diffstat (limited to 'lib/rubygems/ext/cargo_builder.rb')
-rw-r--r-- | lib/rubygems/ext/cargo_builder.rb | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/lib/rubygems/ext/cargo_builder.rb b/lib/rubygems/ext/cargo_builder.rb index fcead1577b..81b28c3c77 100644 --- a/lib/rubygems/ext/cargo_builder.rb +++ b/lib/rubygems/ext/cargo_builder.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative "../shellwords" + # This class is used by rubygems to build Rust extensions. It is a thin-wrapper # over the `cargo rustc` command which takes care of building Rust code in a way # that Ruby can use. @@ -14,10 +16,15 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder @profile = :release end - def build(extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd) + def build(extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd, + target_rbconfig=Gem.target_rbconfig) require "tempfile" require "fileutils" + if target_rbconfig.path + warn "--target-rbconfig is not yet supported for Rust extensions. Ignoring" + end + # Where's the Cargo.toml of the crate we're building cargo_toml = File.join(cargo_dir, "Cargo.toml") # What's the crate's name @@ -45,7 +52,6 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder nesting = extension_nesting(extension) - # TODO: remove in RubyGems 4 if Gem.install_extension_in_lib && lib_dir nested_lib_dir = File.join(lib_dir, nesting) FileUtils.mkdir_p nested_lib_dir @@ -73,8 +79,6 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder end def cargo_command(cargo_toml, dest_path, args = [], crate_name = nil) - require "shellwords" - cmd = [] cmd += [cargo, "rustc"] cmd += ["--crate-type", "cdylib"] @@ -185,6 +189,7 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder end def cargo_dylib_path(dest_path, crate_name) + so_ext = RbConfig::CONFIG["SOEXT"] prefix = so_ext == "dll" ? "" : "lib" path_parts = [dest_path] path_parts << ENV["CARGO_BUILD_TARGET"] if ENV["CARGO_BUILD_TARGET"] @@ -198,7 +203,7 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder output, status = begin - Open3.capture2e(cargo, "metadata", "--no-deps", "--format-version", "1", :chdir => cargo_dir) + Open3.capture2e(cargo, "metadata", "--no-deps", "--format-version", "1", chdir: cargo_dir) rescue StandardError => error raise Gem::InstallError, "cargo metadata failed #{error.message}" end @@ -293,7 +298,7 @@ EOF case var_name # On windows, it is assumed that mkmf has setup an exports file for the - # extension, so we have to to create one ourselves. + # extension, so we have to create one ourselves. when "DEFFILE" write_deffile(dest_dir, crate_name) else @@ -313,22 +318,6 @@ EOF deffile_path end - # We have to basically reimplement RbConfig::CONFIG['SOEXT'] here to support - # Ruby < 2.5 - # - # @see https://github.com/ruby/ruby/blob/c87c027f18c005460746a74c07cd80ee355b16e4/configure.ac#L3185 - def so_ext - return RbConfig::CONFIG["SOEXT"] if RbConfig::CONFIG.key?("SOEXT") - - if win_target? - "dll" - elsif darwin_target? - "dylib" - else - "so" - end - end - # Corresponds to $(LIBPATH) in mkmf def mkmf_libpath ["-L", "native=#{makefile_config("libdir")}"] |