From 84289083157b119f22fada91e32951ad0e12de36 Mon Sep 17 00:00:00 2001 From: graial Date: Fri, 4 Sep 2026 01:58:28 +0800 Subject: [PATCH 1/2] extract predicate bugfix --- lib/ruby_wasm/build/product/crossruby.rb | 8 +++++--- lib/ruby_wasm/build/product/openssl.rb | 2 +- lib/ruby_wasm/build/toolchain.rb | 10 ++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/ruby_wasm/build/product/crossruby.rb b/lib/ruby_wasm/build/product/crossruby.rb index 4ed9f2f9a..511f0b7a4 100644 --- a/lib/ruby_wasm/build/product/crossruby.rb +++ b/lib/ruby_wasm/build/product/crossruby.rb @@ -344,8 +344,7 @@ def configure_args(build_triple, toolchain) # target-side wasm dump_ast while generating .rbinc files. args << %Q(--with-dump-ast=#{dump_ast_path}) - case target - when /^wasm32-unknown-wasi/ + if @toolchain.wasi_sysroot? xldflags << @wasi_vfs.lib_wasi_vfs_a if @wasi_vfs # TODO: Find a way to force cast or update API # @type var wasi_sdk_path: untyped @@ -363,6 +362,9 @@ def configure_args(build_triple, toolchain) # it broke Kernel#require on @bjorn3/browser_wasi_shim setup for some # reason. So we disable it for now. args << %Q(ac_cv_func_realpath=no) + end + + case target when "wasm32-unknown-emscripten" ldflags.concat(%w[-s MODULARIZE=1]) env_emcc_ldflags = ENV["RUBY_WASM_EMCC_LDFLAGS"] || "" @@ -370,7 +372,7 @@ def configure_args(build_triple, toolchain) ldflags << env_emcc_ldflags end else - raise "unknown target: #{target}" + raise "unknown target: #{target}" unless @toolchain.wasi_sysroot? end args.concat(self.tools_args) diff --git a/lib/ruby_wasm/build/product/openssl.rb b/lib/ruby_wasm/build/product/openssl.rb index 5ce127dce..330883506 100644 --- a/lib/ruby_wasm/build/product/openssl.rb +++ b/lib/ruby_wasm/build/product/openssl.rb @@ -42,7 +42,7 @@ def configure_args --libdir=lib -Wl,--allow-undefined ] - if @target.triple.start_with?("wasm32-unknown-wasi") + if @toolchain.wasi_sysroot? args.concat %w[ -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS diff --git a/lib/ruby_wasm/build/toolchain.rb b/lib/ruby_wasm/build/toolchain.rb index 67fa201f3..35e67f682 100644 --- a/lib/ruby_wasm/build/toolchain.rb +++ b/lib/ruby_wasm/build/toolchain.rb @@ -8,6 +8,12 @@ def initialize @tools = {} end + # If this toolchain compiles against wasi-libc, it needs + # wasi-libc's emulation feature flags. + def wasi_sysroot? + false + end + def find_tool(name) raise "not implemented" end @@ -90,6 +96,10 @@ def initialize( @name = "wasi-sdk" end + def wasi_sysroot? + true + end + def find_tool(name) if !File.exist?(@tools[name]) && !ENV["WASI_SDK_PATH"].nil? raise "missing tool '#{name}' at #{@tools[name]}" From 87d3151ab0a1ae74ffb5413b68aacc34878d0267 Mon Sep 17 00:00:00 2001 From: graial Date: Fri, 4 Sep 2026 03:19:58 +0800 Subject: [PATCH 2/2] update types and add test --- sig/ruby_wasm/build.rbs | 2 ++ test/toolchain_predicate_test.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/toolchain_predicate_test.rb diff --git a/sig/ruby_wasm/build.rbs b/sig/ruby_wasm/build.rbs index a62e8aaf8..663e2a55f 100644 --- a/sig/ruby_wasm/build.rbs +++ b/sig/ruby_wasm/build.rbs @@ -251,6 +251,7 @@ module RubyWasm def ar: -> String def install: (_CommandExecutor executor) -> void + def wasi_sysroot?: -> bool end class WASISDK < Toolchain @@ -268,6 +269,7 @@ module RubyWasm def download_url: () -> String def install_wasi_sdk: (_CommandExecutor executor) -> void def install: (_CommandExecutor executor) -> void + def wasi_sysroot?: -> bool end class Binaryen diff --git a/test/toolchain_predicate_test.rb b/test/toolchain_predicate_test.rb new file mode 100644 index 000000000..bee52ca49 --- /dev/null +++ b/test/toolchain_predicate_test.rb @@ -0,0 +1,17 @@ +require "test-unit" +require_relative "../lib/ruby_wasm/build/toolchain" +# require "bundler" + +class ToolchainPredicateTest < Test::Unit::TestCase + def test_base_toolchain_is_not_wasi_sysroot + assert_equal false, Class.new(RubyWasm::Toolchain).allocate.wasi_sysroot? + end + + def test_wasi_sdk_is_wasi_sysroot + assert_equal true, Class.new(RubyWasm::WASISDK).allocate.wasi_sysroot? + end + + def test_emscripten_is_not_wasi_sysroot + assert_equal false, Class.new(RubyWasm::Emscripten).allocate.wasi_sysroot? + end +end \ No newline at end of file