oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1# Vendored dependency patches
2
3## fastrand-2.5.0
4
5### The problem
6
7`yrs` (pinned exact in `core/Cargo.toml`) depends on `fastrand` with its
8`js` feature enabled unconditionally, and fastrand's own manifest ties that
9feature, on `wasm32`/`wasm64`-`unknown`, to `getrandom` with the `wasm_js`
10feature forced on. That feature makes `getrandom` default to a
11`wasm-bindgen`-based backend which imports host JS functions
12(`crypto.getRandomValues`, etc.) — an import the Go/wazero host cannot
13satisfy, and the thing `core/tests/no_host_imports.rs` gates against.
14
15`yrs::Doc` calls into this path unconditionally on construction (even via
16`Doc::with_client_id`, which still generates a random document GUID via
17`fastrand::Rng::new()` -> `getrandom`). Worse: merely *referencing*
18`yrs::Doc` anywhere in `docs-core`'s public API — required for
19`apply_update`/`text_content`, since the test suite calls them from a
20separate compilation unit against the `rlib` — is enough for those
21`wasm-bindgen` exports to end up linked into the final `.wasm` module, even
22along code paths that are never reached at runtime. Reproduced in
23isolation (a scratch crate depending on nothing but `yrs = "=0.23.5"`, with
24a single `pub fn unused(_doc: &yrs::Doc) {}` and no method calls at all);
25see `task-3-report.md` in the plan directory for the full trace.
26
27### The fix, and why it needs vendoring
28
29`getrandom` supports exactly this scenario: selecting its `custom` backend
30via `--cfg getrandom_backend="custom"` (set in `docs-wt-core/.cargo/
31config.toml`, scoped to the `wasm32-unknown-unknown` target only) routes
32entropy requests to a symbol we provide ourselves
33(`__getrandom_v03_custom` in `core/src/lib.rs`, which — deliberately —
34fails rather than fabricating bytes; see the doc comment above it), with
35no JS dependency.
36
37That override alone doesn't compile, though. `getrandom-0.4.3`'s
38`src/error.rs:181-185` has a `Display`/`Debug` match arm:
39
40```rust
41#[cfg(all(
42 feature = "wasm_js",
43 target_arch = "wasm32",
44 any(target_os = "unknown", target_os = "none")
45))]
46Error::WEB_CRYPTO => "Web Crypto API is unavailable",
47```
48
49gated only on the `wasm_js` Cargo *feature* — not on which backend is
50actually *selected* via `--cfg getrandom_backend`. `Error::WEB_CRYPTO`
51itself is defined inside `src/backends/wasm_js.rs:71`, inside the `mod
52wasm_js;` declaration that a `getrandom_backend="custom"` override skips
53compiling entirely (`src/backends.rs`'s `cfg_if!` chain is mutually
54exclusive; `custom` is checked first and short-circuits the rest). Result,
55reproduced directly against the pinned version with nothing changed except
56adding the cfg override:
57
58```
59error[E0599]: no associated function or constant named `WEB_CRYPTO` found for struct `error::Error` in the current scope
60 --> .../getrandom-0.4.3/src/error.rs:185:20
61```
62
63As long as *anything* in the dependency graph requests fastrand's `js`
64feature on a wasm32/wasm64-unknown target — which `yrs` does,
65unconditionally, and which we cannot override, since Cargo features are
66additive across the whole graph and `docs-core` has no way to un-request a
67feature another crate requires — this is a hard compile error, regardless
68of which non-`wasm_js` backend `--cfg getrandom_backend` selects (`custom`,
69`unsupported`, etc. all hit the same match arm). This looks like a real
70gap in `getrandom` 0.4.3's own cfg-gating (the match arm's cfg should also
71require `not(getrandom_backend = "custom")` or equivalent, matching what
72the backend-selection `cfg_if!` already does) rather than anything specific
73to this project; `getrandom`'s own issue tracker has at least one adjacent,
74still-open report of the same problem area — a `custom`-backend override
75not fully insulating a build from a `wasm_js` feature forced on by another
76dependency in the graph — closed "not planned":
77<https://github.com/rust-random/getrandom/issues/633>. We did not find an
78issue number for this exact `E0599`/`WEB_CRYPTO` symptom; if one turns up,
79add it here.
80
81### What was changed
82
83This vendored copy of `fastrand-2.5.0` is the unmodified upstream Rust
84source (`src/`, `benches/`, `tests/`, licenses — byte-identical to the
85crates.io tarball); only `Cargo.toml` differs, by exactly one edit: the
86`wasm32`/`wasm64`-`unknown`-scoped `getrandom` dependency drops
87`features = ["wasm_js"]` (kept `optional = true`). Nothing in fastrand's
88actual logic changes — the `js` feature still exists, `fastrand::Rng::new()`
89still calls into `getrandom` the same way — only *which* `getrandom`
90backend ends up linked changes, and that's exactly what the
91`--cfg getrandom_backend="custom"` override in `.cargo/config.toml` is
92choosing on purpose. Wired in via `[patch.crates-io]` in `core/Cargo.toml`.
93
94### When this can be deleted
95
96Try removing the `[patch.crates-io]` block from `core/Cargo.toml` (and
97`vendor/fastrand-2.5.0/`) and running:
98
99```
100cargo build --release --manifest-path core/Cargo.toml --target wasm32-unknown-unknown
101```
102
103If that compiles cleanly (no `E0599`), delete the patch and this
104directory — that's the goal state. Concretely, that becomes true once any
105one of:
106
1071. A `getrandom` release fixes `error.rs`'s `WEB_CRYPTO` match arm to also
108 respect `getrandom_backend` (e.g. adds `not(getrandom_backend =
109 "custom")`), and `core/Cargo.toml`'s `getrandom = "=0.4.3"` pin is
110 bumped to that version.
1112. A `fastrand` release stops forcing `wasm_js` onto its optional
112 `getrandom` dependency (making it opt-in instead, which is what
113 getrandom issue #633 above is effectively asking for), and `yrs`'s pin
114 on it moves to that version.
1153. `yrs` stops requiring `fastrand`'s `js` feature at all for the
116 wasm32-unknown-unknown target — unlikely while it still generates
117 random document GUIDs internally, but would remove the whole problem.
118
119Verified as of this writing (2026-08-30) that the patch is still required:
120removing it and rebuilding reproduces the exact `E0599` above.
121