Skip to content

Commit 51a37ee

Browse files
build: Remove --gemfile option from rbwasm command line
This option was used to specify the path to the `Gemfile` by overriding gemfile path after launching rbwasm command through Bundler. But it does not work because Bundler caches a lot of information and cannot invalidate all of them in-process. So we should cd to the directory containing the Gemfile and run the command there to avoid the need to switch the Gemfile path. This issue was revealed when trying to install remote gems, which was reuired to work around installation issue around bundled power_assert gem in the Ruby build system.
1 parent 792d3b2 commit 51a37ee

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

lib/ruby_wasm/cli.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ def build(args)
116116
options[:format] = format
117117
end
118118

119-
opts.on("--gemfile GEMFILE", "Gemfile") do |gemfile|
120-
options[:gemfile] = gemfile
121-
end
122-
123119
opts.on("--print-ruby-cache-key", "Print Ruby cache key") do
124120
options[:print_ruby_cache_key] = true
125121
end
@@ -289,12 +285,7 @@ def derive_packager(options)
289285
level = options[:print_ruby_cache_key] ? :silent : Bundler.ui.level
290286
old_level = Bundler.ui.level
291287
Bundler.ui.level = level
292-
if options[:gemfile]
293-
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", options[:gemfile]
294-
definition = Bundler.definition(true) # unlock=true to re-evaluate "BUNDLE_GEMFILE"
295-
else
296-
definition = Bundler.definition
297-
end
288+
definition = Bundler.definition
298289
ensure
299290
Bundler.ui.level = old_level
300291
end

rakelib/packaging.rake

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ namespace :npm do
5151
# Share ./build and ./rubies in the same workspace
5252
"RUBY_WASM_ROOT" => base_dir
5353
}
54+
cwd = nil
5455
if gemfile_path = pkg[:gemfile]
55-
build_command.push "--gemfile", gemfile_path
56+
cwd = File.dirname(gemfile_path)
5657
else
5758
# Explicitly disable rubygems integration since Bundler finds
5859
# Gemfile in the repo root directory.
@@ -61,15 +62,17 @@ namespace :npm do
6162
dist_dir = File.join(pkg_dir, "dist")
6263
mkdir_p dist_dir
6364
if pkg[:target] == "wasm32-unknown-wasi"
64-
sh env,
65-
*build_command,
66-
"--no-stdlib",
67-
"-o",
68-
File.join(dist_dir, "ruby.wasm")
69-
sh env,
70-
*build_command,
71-
"-o",
72-
File.join(dist_dir, "ruby.debug+stdlib.wasm")
65+
Dir.chdir(cwd || base_dir) do
66+
sh env,
67+
*build_command,
68+
"--no-stdlib",
69+
"-o",
70+
File.join(dist_dir, "ruby.wasm")
71+
sh env,
72+
*build_command,
73+
"-o",
74+
File.join(dist_dir, "ruby.debug+stdlib.wasm")
75+
end
7376
sh wasi_sdk.wasm_opt,
7477
"--strip-debug",
7578
File.join(dist_dir, "ruby.wasm"),
@@ -81,7 +84,9 @@ namespace :npm do
8184
"-o",
8285
File.join(dist_dir, "ruby+stdlib.wasm")
8386
elsif pkg[:target] == "wasm32-unknown-emscripten"
84-
sh env, *build_command, "-o", "/dev/null"
87+
Dir.chdir(cwd || base_dir) do
88+
sh env, *build_command, "-o", "/dev/null"
89+
end
8590
end
8691
end
8792

0 commit comments

Comments
 (0)