8000 Add `--target-rbconfig` option to `gem install` and `gem update` commands by kateinoigakukun · Pull Request #7628 · rubygems/rubygems · GitHub
[go: up one dir, main page]

Skip to content

Add --target-rbconfig option to gem install and gem update commands #7628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kateinoigakukun
Copy link
Contributor
@kateinoigakukun kateinoigakukun commented May 4, 2024

What was the end-user or developer problem that led to this PR?

Today, CRuby runs on many platforms. But not all platforms are capable of running build tools (e.g. WebAssembly/WASI), so cross-target compilation against extensions libraries is essential for those platforms.

Currently, there is no way to cross-compile extension libraries in gems at install-time.

What is your fix for the problem, implemented in this PR?

This patch adds --target-rbconfig option to specify the rbconfig.rb file for the deployment target platform. It basically pass through it to mkmf. The underlying --target-rbconfig support in mkmf has been introduced recently https://bugs.ruby-lang.org/issues/20345

At the moment, this option is only available when the following requirements are met:

  • extconf.rb-based extensions
  • requires mkmf in the latest master branch.

But we can relax the first requirement for Cargo builder by adding a support in rb-sys later.

$ GEM_HOME=/tmp/gems-wasm32-wasi gem install nokogiri --target-rbconfig path/to/wasm32-wasi/rbconfig.rb

Make sure the following tasks are checked

@kateinoigakukun kateinoigakukun force-pushed the pr-64aa3cae6563de7b71b8cebbd2453e65e4f40278 branch 3 times, most recently from 57df8bd to 97fa3ff Compare May 4, 2024 23:22
@kateinoigakukun kateinoigakukun marked this pull request as ready for review May 5, 2024 05:10
@hsbt hsbt self-assigned this May 7, 2024
@kateinoigakukun kateinoigakukun force-pushed the pr-64aa3cae6563de7b71b8cebbd2453e65e4f40278 branch 5 times, most recently from 394788b to 7868c67 Compare May 17, 2024 07:47
@kateinoigakukun kateinoigakukun force-pushed the pr-64aa3cae6563de7b71b8cebbd2453e65e4f40278 branch 2 times, most recently from 86a8474 to 132178c Compare May 19, 2024 00:59
require "tempfile"
require "fileutils"

if target_rbconfig.path
warn "--target-rbconfig is not yet supported for Rust extensions. Ignoring"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would it take to implement this for rust?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, it should be done by replacing RbConfig reference with the corresponding value of target_rbconfig in cargo_builder.rb. Maybe we need some change in rb-sys side, but wouldn't be big.

@@ -19,6 +19,10 @@ def run
# Disable color in deployment mode
Bundler.ui.shell = Thor::Shell::Basic.new if options[:deployment]

if target_rbconfig_path = options["target-rbconfig"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if target_rbconfig_path = options["target-rbconfig"]
if target_rbconfig_path = options[:target-rbconfig]

@hsbt
Copy link
Member
hsbt commented Jun 17, 2024

After resolving https://github.com/rubygems/rubygems/pull/7628/files#r1642315631, Let's merge this.

…ands

This patch adds `--target-rbconfig` option to specify the rbconfig.rb file
for the deployment target platform. This is useful when cross-compiling
gems. At the moment, this option is only available for `extconf.rb`-based
extensions.
@kateinoigakukun kateinoigakukun force-pushed the pr-64aa3cae6563de7b71b8cebbd2453e65e4f40278 branch from 132178c to 07a5fae Compare June 17, 2024 13:46
@hsbt hsbt merged commit f0024dc into rubygems:master Jun 18, 2024
82 checks passed
@@ -19,6 +19,10 @@ def run
# Disable color in deployment mode
Bundler.ui.shell = Thor::Shell::Basic.new if options[:deployment]

if target_rbconfig_path = options[:"target-rbconfig"]
Bundler.rubygems.set_target_rbconfig(target_rbconfig_path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably fail more gracefully when the underlying RubyGems method is not available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0