diff options
author | Mat Sadler <mat@sourcetagsandcodes.com> | 2023-01-22 21:16:12 -0800 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-01-30 17:39:47 +0000 |
commit | ca951f671920b64c8275ffccdc680848f60cbede (patch) | |
tree | cab2758553a2b5f1749021c9c7a911658529af55 /test/rubygems | |
parent | 00e1ee4a7eb9f1703ddaf15158fefe0f7b594839 (diff) | |
download | ruby-ca951f671920b64c8275ffccdc680848f60cbede.tar.gz |
[rubygems/rubygems] use cargo to get crate name
the final copying of the extension into place has been slimmed
down, reflecting that it only needs to copy a single file, rather
than replicating the more involved process used for a C ext
this also refactors #build so that #cargo_crate_name only needs
to be called once, and hopefully the build flow is easier to
understand
https://github.com/rubygems/rubygems/commit/5a0d7f2e6c
Diffstat (limited to 'test/rubygems')
4 files changed, 14 insertions, 28 deletions
diff --git a/test/rubygems/test_gem_ext_cargo_builder.rb b/test/rubygems/test_gem_ext_cargo_builder.rb index 9c1ee2ae31..5ffe5f0b6f 100644 --- a/test/rubygems/test_gem_ext_cargo_builder.rb +++ b/test/rubygems/test_gem_ext_cargo_builder.rb @@ -31,13 +31,12 @@ class TestGemExtCargoBuilder < Gem::TestCase Dir.chdir @ext do ENV.update(@rust_envs) - spec = Gem::Specification.new "rust_ruby_example", "0.1.0" - builder = Gem::Ext::CargoBuilder.new(spec) + builder = Gem::Ext::CargoBuilder.new builder.build nil, @dest_path, output end output = output.join "\n" - bundle = File.join(@dest_path, "release/rust_ruby_example.#{RbConfig::CONFIG['DLEXT']}") + bundle = File.join(@dest_path, "rust_ruby_example.#{RbConfig::CONFIG['DLEXT']}") assert_match(/Finished/, output) assert_match(/release/, output) @@ -58,13 +57,12 @@ class TestGemExtCargoBuilder < Gem::TestCase Dir.chdir @ext do ENV.update(@rust_envs) - spec = Gem::Specification.new "rust_ruby_example", "0.1.0" - builder = Gem::Ext::CargoBuilder.new(spec) + builder = Gem::Ext::CargoBuilder.new builder.build nil, @dest_path, output end output = output.join "\n" - bundle = File.join(@dest_path, "release/rust_ruby_example.#{RbConfig::CONFIG['DLEXT']}") + bundle = File.join(@dest_path, "rust_ruby_example.#{RbConfig::CONFIG['DLEXT']}") assert_ffi_handle bundle, "hello_from_rubygems" assert_ffi_handle bundle, "hello_from_rubygems_version" @@ -79,22 +77,17 @@ class TestGemExtCargoBuilder < Gem::TestCase skip_unsupported_platforms! setup_rust_gem "rust_ruby_example" - output = [] - FileUtils.rm(File.join(@ext, "src/lib.rs")) error = assert_raise(Gem::InstallError) do Dir.chdir @ext do ENV.update(@rust_envs) - spec = Gem::Specification.new "rust_ruby_example", "0.1.0" - builder = Gem::Ext::CargoBuilder.new(spec) - builder.build nil, @dest_path, output + builder = Gem::Ext::CargoBuilder.new + builder.build nil, @dest_path, [] end end - output = output.join "\n" - - assert_match "cargo failed", error.message + assert_match /cargo\s.*\sfailed/, error.message end def test_full_integration @@ -137,7 +130,7 @@ class TestGemExtCargoBuilder < Gem::TestCase Open3.capture2e(*gem, "install", "--verbose", "--local", built_gem, *ARGV) end - stdout_and_stderr_str, status = Open3.capture2e(env_for_subprocess, *ruby_with_rubygems_in_load_path, "-rcustom_name", "-e", "puts 'Result: ' + CustomName.say_hello") + stdout_and_stderr_str, status = Open3.capture2e(env_for_subprocess, *ruby_with_rubygems_in_load_path, "-rcustom_name_ext", "-e", "puts 'Result: ' + CustomName.say_hello") assert status.success?, stdout_and_stderr_str assert_match "Result: Hello world!", stdout_and_stderr_str diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec b/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec index 1f8e270e96..95332ec84f 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec +++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec @@ -5,6 +5,4 @@ Gem::Specification.new do |s| s.extensions = ["Cargo.toml"] s.authors = ["Ian Ker-Seymer"] s.files = ["Cargo.toml", "Cargo.lock", "src/lib.rs"] - - s.metadata["cargo_crate_name"] = "custom-name-ext" end diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/src/lib.rs b/test/rubygems/test_gem_ext_cargo_builder/custom_name/src/lib.rs index 543ad4a70e..28ba3be564 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/src/lib.rs +++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/src/lib.rs @@ -12,7 +12,7 @@ unsafe extern "C" fn say_hello(_klass: VALUE) -> VALUE { #[allow(non_snake_case)] #[no_mangle] -pub extern "C" fn Init_custom_name() { +pub extern "C" fn Init_custom_name_ext() { let name = CString::new("CustomName").unwrap(); let function_name = CString::new("say_hello").unwrap(); // bindgen does not properly detect the arity of the ruby callback function, so we have to transmute diff --git a/test/rubygems/test_gem_ext_cargo_builder_unit.rb b/test/rubygems/test_gem_ext_cargo_builder_unit.rb index dc9350bb3a..0ca8306842 100644 --- a/test/rubygems/test_gem_ext_cargo_builder_unit.rb +++ b/test/rubygems/test_gem_ext_cargo_builder_unit.rb @@ -6,8 +6,7 @@ require "rubygems/ext" class TestGemExtCargoBuilderUnit < Gem::TestCase def test_cargo_command_passes_args skip_unsupported_platforms! - spec = Gem::Specification.new "rust_ruby_example", "0.1.0" - builder = Gem::Ext::CargoBuilder.new(spec) + builder = Gem::Ext::CargoBuilder.new command = builder.cargo_command(Dir.pwd, @tempdir, ["--all-features"]) assert_includes command, "--all-features" @@ -15,8 +14,7 @@ class TestGemExtCargoBuilderUnit < Gem::TestCase def test_cargo_command_locks_in_release_profile skip_unsupported_platforms! - spec = Gem::Specification.new "rust_ruby_example", "0.1.0" - builder = Gem::Ext::CargoBuilder.new(spec) + builder = Gem::Ext::CargoBuilder.new builder.profile = :release command = builder.cargo_command(Dir.pwd, @tempdir) @@ -27,8 +25,7 @@ class TestGemExtCargoBuilderUnit < Gem::TestCase skip_unsupported_platforms! old_cargo = ENV["CARGO"] ENV["CARGO"] = "mycargo" - spec = Gem::Specification.new "rust_ruby_example", "0.1.0" - builder = Gem::Ext::CargoBuilder.new(spec) + builder = Gem::Ext::CargoBuilder.new command = builder.cargo_command(Dir.pwd, @tempdir) assert_includes command, "mycargo" @@ -38,8 +35,7 @@ class TestGemExtCargoBuilderUnit < Gem::TestCase def test_build_env_includes_rbconfig skip_unsupported_platforms! - spec = Gem::Specification.new "rust_ruby_example", "0.1.0" - builder = Gem::Ext::CargoBuilder.new(spec) + builder = Gem::Ext::CargoBuilder.new env = builder.build_env assert_equal env.fetch("RBCONFIG_RUBY_SO_NAME"), RbConfig::CONFIG["RUBY_SO_NAME"] @@ -49,8 +45,7 @@ class TestGemExtCargoBuilderUnit < Gem::TestCase skip_unsupported_platforms! old_cargo = ENV["CARGO_BUILD_TARGET"] ENV["CARGO_BUILD_TARGET"] = "x86_64-unknown-linux-gnu" - spec = Gem::Specification.new "rust_ruby_example", "0.1.0" - builder = Gem::Ext::CargoBuilder.new(spec) + builder = Gem::Ext::CargoBuilder.new command = builder.cargo_command(Dir.pwd, @tempdir, ["--locked"]) assert_includes command, "--target" |