From a7af8a41c26d19c5866a07540e19e85e65fc0263 Mon Sep 17 00:00:00 2001 From: sylph-pi Date: Mon, 7 Sep 2026 21:06:41 +0200 Subject: [PATCH] fix(wasm): make `cargo check --target wasm32` compile With the `mio` subtree gone (previous commit), two blockers remain. Each was invisible until the one before it was cleared, which is why #11 was written around only the first. 1. getrandom 0.3 refuses wasm32-unknown-unknown without being told which backend to use. It needs `--cfg getrandom_backend="wasm_js"` AND the crate's `wasm_js` feature; its own error is explicit that either alone is insufficient. Nothing here depends on getrandom directly -- it arrives through `ahash`, in `sylpheed-viewer` only -- so the feature half is declared there purely to switch it on. 2. error: bevy_egui uses unstable APIs to support clipboard on web. Needs `--cfg web_sys_unstable_apis`. Both cfgs live in /.cargo/config.toml scoped to the wasm target, so native builds are untouched. Verified on aarch64 / rustc 1.98.1 -- the runner's toolchain -- from scratch with the cache cleared: exit 0 in 163s. Independently reproduced on x86_64 / rustc 1.90.0 as a controlled A/B against the parent, both running the job's exact invocation: with this branch exit 0, zero errors, 38s same command at 885b4d4 exit 101, the getrandom error The control also shows `bevy_egui` is never reached when getrandom fails, and the passing case contains no `mio` and no `tokio` in the wasm graph at all -- so each blocker is confirmed separately rather than by the aggregate exit code. This does NOT make the WASM job green, and the next failure is already identified rather than left to be discovered. `Install Trunk` uses `jetli/trunk-action@v0.5.0`, whose bundled `dist/index.js` contains the string `x86_64-unknown-linux-gnu` exactly once and `aarch64` not at all, while calling `os.arch()` five times with no mapping for it. On this aarch64 runner it will fetch an x86_64 binary. Upstream trunk does ship `trunk-aarch64-unknown-linux-gnu.tar.gz`, so the asset exists and only the action's selection is wrong -- but replacing the install step means picking a version to pin and an install method, which is a decision, not a fix. Left for #11 to decide. Refs #11 Co-Authored-By: Claude Opus 5 --- .cargo/config.toml | 29 +++++++++++++++++++++++++++++ Cargo.lock | 3 +++ crates/sylpheed-viewer/Cargo.toml | 7 +++++++ 3 files changed, 39 insertions(+) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..dd11e687 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,29 @@ +# getrandom 0.3 refuses to build for wasm32-unknown-unknown unless it is told +# which backend to use. The target has no OS entropy source, so the crate will +# not guess: it wants the `wasm_js` backend named explicitly, AND the matching +# feature enabled on the crate itself. Its own error is unusually clear that one +# without the other is not enough: +# +# error: The wasm32-unknown-unknown targets are not supported by default; you +# may need to enable the "wasm_js" configuration flag. Note that enabling the +# `wasm_js` feature flag alone is insufficient. +# +# This is the cfg half. The feature half is a wasm32-only dependency in +# crates/sylpheed-viewer/Cargo.toml — that is the only crate reaching getrandom +# here, transitively through `ahash`. +# +# Scoped to the wasm target, so native builds are untouched. Note that a +# RUSTFLAGS environment variable, if one is ever set, replaces this rather than +# adding to it. +# +# The second cfg is bevy_egui's. Its web clipboard support calls web-sys APIs +# that are still gated behind an unstable flag, and it refuses to build without +# it rather than silently dropping the feature: +# +# error: bevy_egui uses unstable APIs to support clipboard on web. +# +[target.wasm32-unknown-unknown] +rustflags = [ + '--cfg', 'getrandom_backend="wasm_js"', + '--cfg', 'web_sys_unstable_apis', +] diff --git a/Cargo.lock b/Cargo.lock index 83cbd322..2c962ed3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2497,9 +2497,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", + "js-sys", "libc", "r-efi", "wasip2", + "wasm-bindgen", ] [[package]] @@ -4675,6 +4677,7 @@ dependencies = [ "bevy", "bevy_egui", "futures", + "getrandom 0.3.4", "image", "rfd", "rodio", diff --git a/crates/sylpheed-viewer/Cargo.toml b/crates/sylpheed-viewer/Cargo.toml index 455938d6..3a3816e5 100644 --- a/crates/sylpheed-viewer/Cargo.toml +++ b/crates/sylpheed-viewer/Cargo.toml @@ -56,3 +56,10 @@ rodio = { workspace = true } image = { version = "0.25", default-features = false, features = ["png"] } # Off-thread rasterization of embedded-font samples (avoids egui's global fonts). ab_glyph = "0.2" + +# Reached only through `ahash`, which needs an entropy source for its random +# state. Declared here purely to turn on the `wasm_js` feature; nothing in this +# crate calls getrandom directly. The paired `--cfg getrandom_backend` lives in +# /.cargo/config.toml — both are required, neither is sufficient. +[target.'cfg(target_arch = "wasm32")'.dependencies] +getrandom = { version = "0.3", features = ["wasm_js"] }