diff --git a/Rakefile b/Rakefile index 71b4f288e..b723298ec 100644 --- a/Rakefile +++ b/Rakefile @@ -16,7 +16,8 @@ BUILDS = BUILD_SOURCES .product(BUILD_PROFILES) .map { |src, profile| [src, "wasm32-unknown-wasip1", profile] } + - BUILD_SOURCES.map { |src| [src, "wasm32-unknown-emscripten", "full"] } + BUILD_SOURCES.map { |src| [src, "wasm32-unknown-emscripten", "full"] } + + BUILD_SOURCES.map { |src| [src, "wasm32-unknown-icp", "minimal"] } NPM_PACKAGES = [ { 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/product/product.rb b/lib/ruby_wasm/build/product/product.rb index 726517c3a..2a24fda1d 100644 --- a/lib/ruby_wasm/build/product/product.rb +++ b/lib/ruby_wasm/build/product/product.rb @@ -17,6 +17,8 @@ def system_triplet_args args.concat(%W[--host wasm32-wasi]) when "wasm32-unknown-emscripten" args.concat(%W[--host wasm32-emscripten]) + when "wasm32-unknown-icp" + args.concat(%W[--host wasm32-wasi]) else raise "unknown target: #{@target.triple}" end diff --git a/lib/ruby_wasm/build/toolchain.rb b/lib/ruby_wasm/build/toolchain.rb index 67fa201f3..6206d3579 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 @@ -27,6 +33,13 @@ def self.get(target, options, build_dir = nil) ) when "wasm32-unknown-emscripten" return RubyWasm::Emscripten.new + when "wasm32-unknown-icp" + return( + RubyWasm::Icp.new( + build_dir: build_dir, + version: options[:wasi_sdk_version] + ) + ) else raise "unknown target: #{target}" end @@ -90,6 +103,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]}" @@ -285,4 +302,10 @@ def find_tool(name) @tools[name] end end + + class Icp < WASISDK + def name + "icp" + end + end end diff --git a/sig/ruby_wasm/build.rbs b/sig/ruby_wasm/build.rbs index a62e8aaf8..f6f66b698 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,11 @@ module RubyWasm def download_url: () -> String def install_wasi_sdk: (_CommandExecutor executor) -> void def install: (_CommandExecutor executor) -> void + def wasi_sysroot?: -> bool + end + + class Icp < WASISDK + def name: -> String 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