Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/ruby_wasm/build/product/crossruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -363,14 +362,17 @@ 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"] || ""
unless env_emcc_ldflags.empty?
ldflags << env_emcc_ldflags
end
else
raise "unknown target: #{target}"
raise "unknown target: #{target}" unless @toolchain.wasi_sysroot?
end

args.concat(self.tools_args)
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_wasm/build/product/openssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/ruby_wasm/build/toolchain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]}"
Expand Down
2 changes: 2 additions & 0 deletions sig/ruby_wasm/build.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ module RubyWasm
def ar: -> String

def install: (_CommandExecutor executor) -> void
def wasi_sysroot?: -> bool
end

class WASISDK < Toolchain
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions test/toolchain_predicate_test.rb
Original file line number Diff line number Diff line change
@@ -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