Key wasi-sysroot build flags on the toolchain instead of the target triple - #666
Open
graial wants to merge 2 commits into
Open
Key wasi-sysroot build flags on the toolchain instead of the target triple#666graial wants to merge 2 commits into
graial wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Note: This bug report and fix is AI-assisted
Several build products decide whether to pass wasi-libc's emulation flags by testing the target triple string against
wasm32-unknown-wasi. Those flags exist because the code is being compiled against wasi-sysroot, a property of the toolchain, not the target.This means that a target using
RubyWasm::WASISDKwith triple other thanwasm32-unknown-wasi*is configured with the wasi-sdk compiler but fails to build without the flags, with an unhelpful failure message.This PR adds a
wasi_sysroot?predicate toRubyWasm::Toolchain, returningfalseby default andtrueonWASISDK, and switches the sysroot-driven sites to test it.The bug
lib/ruby_wasm/build/product/openssl.rb:45A wasi-sdk target failing this test gets none of
-D_WASI_EMULATED_SIGNAL,-D_WASI_EMULATED_PROCESS_CLOCKS,-D_WASI_EMULATED_MMAN,-D_WASI_EMULATED_GETPID,-DNO_CHMODor-DHAVE_FORK=0. OpenSSL then fails on wasi-libc'ssignal.h:lib/ruby_wasm/build/product/crossruby.rb:349has the same gate, carryingWASMOPT,WASI_SDK_PATH,ac_cv_func_fchmod=no,ac_cv_func_chmod=noandac_cv_func_realpath=no. CRuby's own configure hits the equivalent wall immediately after OpenSSL is cleared.The base array in
openssl.rbalready carries-no-sock,-no-dgram,-no-threadsand-Wl,--allow-undefinedunconditionally, so a failing build looks partly wasm-aware. That makes this harder to spot than it should be — the build appears to know it is targeting wasm, and fails anyway.Changes
Toolchain#wasi_sysroot?returningfalse;WASISDK#wasi_sysroot?returningtrue. Subclasses ofWASISDKinherit the correct answer.openssl.rbandcrossruby.rbtest the predicate instead of the triple prefix. Incrossruby.rbthe sysroot block is hoisted out of thecase, leaving thecasefor genuinely target-specific concerns. Itselsearm still raises on an unknown target, but now defers to the predicate rather than to a triple prefix, so a wasi-sdk target is not rejected by the guard after the block above has already handled it.Toolchain,WASISDKandEmscripten.Sites deliberately not changed
toolchain.rb:29dispatches triple to toolchain and cannot be predicate driven without circularity.packager.rb:47gates the wasip1 component adapter, which is genuinely specific to that triple.packager.rb:100,cli.rb:52are defaults.wasi_vfs.rb:15is a hardcoded build target for the wasi-vfs crate.The test applied at each site: is this here because of the sysroot, or because of the target's identity? Only the former became the predicate.
Naming
wasi_sysroot?names the actual reason the flags exist.wasi?was avoided deliberately: that ambiguity is what caused the bug, since a target can compile against wasi-sysroot without being wasip1.Testing
Built
3.3-wasm32-unknown-wasip1-fullonupstream/mainand on this branch. Both artifacts are byte-identical:fullrather thanminimalbecausebuild.rb:53constructsOpenSSLProductunconditionally, sofullexercises the OpenSSL gate thatminimalmay not reach.That result is what the change predicts, because the predicate returns the same answer as the triple test for every target that exists today:
wasm32-unknown-wasi, so the old gate is true;WASISDK#wasi_sysroot?is true. No change.Emscriptendescends fromToolchain, notWASISDK, so the predicate is false. No change.Both cases are covered by unit tests on the predicate itself. The emscripten case is asserted by test but not by a build — worth flagging rather than leaving for someone to notice.
steep checkis clean.Provenance
Found while adding a wasi-sdk target for the Internet Computer (#653). The bug is not specific to that target: it bites any new
WASISDKsubclass whose triple is not namedwasm32-unknown-wasi*, and it is worth fixing whether or not ruby.wasm decides to support an ICP target.