Skip to content

Commit

Permalink
Fix Gemfile.lock issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Jul 4, 2024
1 parent 99535c5 commit ef73ba1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
7 changes: 5 additions & 2 deletions lib/ruby_wasm/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ def self.bundled_patches_path

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

Expand Down
27 changes: 16 additions & 11 deletions lib/ruby_wasm/packager/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def build(executor, options)
def build_strategy
@build_strategy ||=
begin
has_exts = @packager.specs.any? { |spec| spec.extensions.any? }
if @packager.features.support_dynamic_linking?
DynamicLinking.new(@packager)
else
Expand Down Expand Up @@ -59,14 +58,6 @@ def specs_with_extensions
end
end

def wasi_exec_model
# TODO: Detect WASI exec-model from binary exports (_start or _initialize)
use_js_gem = @packager.specs.any? do |spec|
spec.name == "js"
end
use_js_gem ? "reactor" : "command"
end

def with_unbundled_env(&block)
__skip__ = if defined?(Bundler)
Bundler.with_unbundled_env(&block)
Expand Down Expand Up @@ -138,12 +129,16 @@ def _link_gem_exts(executor, build, ruby_root, gem_home, module_bytes)
wasi_sdk_path = toolchain.wasi_sdk_path
libraries << File.join(wasi_sdk_path, "share/wasi-sysroot/lib/wasm32-wasi", lib)
end
wasi_adapter = RubyWasm::Packager::ComponentAdapter.wasi_snapshot_preview1(wasi_exec_model)
adapters = [wasi_adapter]
dl_openable_libs = []
dl_openable_libs << [File.dirname(ruby_root), Dir.glob(File.join(ruby_root, "lib", "ruby", "**", "*.so"))]
dl_openable_libs << [gem_home, Dir.glob(File.join(gem_home, "**", "*.so"))]

has_js_so = dl_openable_libs.any? do |root, libs|
libs.any? { |lib| lib.end_with?("/js.so") }
end
wasi_adapter = RubyWasm::Packager::ComponentAdapter.wasi_snapshot_preview1(has_js_so ? "reactor" : "command")
adapters = [wasi_adapter]

linker = RubyWasmExt::ComponentLink.new
linker.use_built_in_libdl(true)
linker.stub_missing_functions(false)
Expand Down Expand Up @@ -198,6 +193,8 @@ def _build_gem_exts(executor, build, gem_home)
"BUNDLE_APP_CONFIG" => File.join(".bundle", target_triplet),
"BUNDLE_PATH" => local_path,
"BUNDLE_WITHOUT" => "build",
# Do not auto-switch bundler version by Gemfile.lock
"BUNDLE_VERSION" => "system",
# FIXME: BUNDLE_PATH is set as a installation destination here, but
# it is also used as a source of gems to be loaded by RubyGems itself.
# RubyGems loads "psych" gem and if Gemfile includes "psych" gem,
Expand Down Expand Up @@ -347,6 +344,14 @@ def build_gem_exts(executor, gem_home)
# No-op because we already built extensions as part of the Ruby build
end

def wasi_exec_model
# TODO: Detect WASI exec-model from binary exports (_start or _initialize)
use_js_gem = @packager.specs.any? do |spec|
spec.name == "js"
end
use_js_gem ? "reactor" : "command"
end

def link_gem_exts(executor, ruby_root, gem_home, module_bytes)
return module_bytes unless @packager.features.support_component_model?

Expand Down

0 comments on commit ef73ba1

Please sign in to comment.