Skip to content

Commit 2c29240

Browse files
Fix Gemfile.lock issue
1 parent 7f9b270 commit 2c29240

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

lib/ruby_wasm/cli.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@ def self.bundled_patches_path
310310

311311
def derive_packager(options)
312312
__skip__ = definition = nil
313-
__skip__ = if defined?(Bundler) && !options[:disable_gems]
313+
features = RubyWasm::FeatureSet.derive_from_env
314+
# The head ruby & dynamic linking uses "bundle" command to build gems instead of in-process integration.
315+
use_in_process_gem_building = !(options[:ruby_version] == "head" && features.support_dynamic_linking?)
316+
__skip__ = if defined?(Bundler) && !options[:disable_gems] && use_in_process_gem_building
314317
begin
315318
# Silence Bundler UI if --print-ruby-cache-key is specified not to bother the JSON output.
316319
level = options[:print_ruby_cache_key] ? :silent : Bundler.ui.level
@@ -324,7 +327,7 @@ def derive_packager(options)
324327
RubyWasm.logger.info "Using Gemfile: #{definition.gemfiles.map(&:to_s).join(", ")}" if definition
325328
RubyWasm::Packager.new(
326329
root, build_config(options), definition,
327-
features: RubyWasm::FeatureSet.derive_from_env
330+
features: features,
328331
)
329332
end
330333

lib/ruby_wasm/packager/core.rb

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def build(executor, options)
1919
def build_strategy
2020
@build_strategy ||=
2121
begin
22-
has_exts = @packager.specs.any? { |spec| spec.extensions.any? }
2322
if @packager.features.support_dynamic_linking?
2423
DynamicLinking.new(@packager)
2524
else
@@ -59,14 +58,6 @@ def specs_with_extensions
5958
end
6059
end
6160

62-
def wasi_exec_model
63-
# TODO: Detect WASI exec-model from binary exports (_start or _initialize)
64-
use_js_gem = @packager.specs.any? do |spec|
65-
spec.name == "js"
66-
end
67-
use_js_gem ? "reactor" : "command"
68-
end
69-
7061
def with_unbundled_env(&block)
7162
__skip__ = if defined?(Bundler)
7263
Bundler.with_unbundled_env(&block)
@@ -138,12 +129,16 @@ def _link_gem_exts(executor, build, ruby_root, gem_home, module_bytes)
138129
wasi_sdk_path = toolchain.wasi_sdk_path
139130
libraries << File.join(wasi_sdk_path, "share/wasi-sysroot/lib/wasm32-wasi", lib)
140131
end
141-
wasi_adapter = RubyWasm::Packager::ComponentAdapter.wasi_snapshot_preview1(wasi_exec_model)
142-
adapters = [wasi_adapter]
143132
dl_openable_libs = []
144133
dl_openable_libs << [File.dirname(ruby_root), Dir.glob(File.join(ruby_root, "lib", "ruby", "**", "*.so"))]
145134
dl_openable_libs << [gem_home, Dir.glob(File.join(gem_home, "**", "*.so"))]
146135

136+
has_js_so = dl_openable_libs.any? do |root, libs|
137+
libs.any? { |lib| lib.end_with?("/js.so") }
138+
end
139+
wasi_adapter = RubyWasm::Packager::ComponentAdapter.wasi_snapshot_preview1(has_js_so ? "reactor" : "command")
140+
adapters = [wasi_adapter]
141+
147142
linker = RubyWasmExt::ComponentLink.new
148143
linker.use_built_in_libdl(true)
149144
linker.stub_missing_functions(false)
@@ -198,6 +193,8 @@ def _build_gem_exts(executor, build, gem_home)
198193
"BUNDLE_APP_CONFIG" => File.join(".bundle", target_triplet),
199194
"BUNDLE_PATH" => local_path,
200195
"BUNDLE_WITHOUT" => "build",
196+
# Do not auto-switch bundler version by Gemfile.lock
197+
"BUNDLE_VERSION" => "system",
201198
# FIXME: BUNDLE_PATH is set as a installation destination here, but
202199
# it is also used as a source of gems to be loaded by RubyGems itself.
203200
# RubyGems loads "psych" gem and if Gemfile includes "psych" gem,
@@ -347,6 +344,14 @@ def build_gem_exts(executor, gem_home)
347344
# No-op because we already built extensions as part of the Ruby build
348345
end
349346

347+
def wasi_exec_model
348+
# TODO: Detect WASI exec-model from binary exports (_start or _initialize)
349+
use_js_gem = @packager.specs.any? do |spec|
350+
spec.name == "js"
351+
end
352+
use_js_gem ? "reactor" : "command"
353+
end
354+
350355
def link_gem_exts(executor, ruby_root, gem_home, module_bytes)
351356
return module_bytes unless @packager.features.support_component_model?
352357

0 commit comments

Comments
 (0)