Skip to content

Commit 6d1b678

Browse files
committed
fix(doc-tests): empty // platforms: opts out of host run phase
The previous rule was: if a banner had no `platforms:` line at all, default to all hosts. That collapsed the legitimate "opt out of the host run phase" case (FFI imports only resolve under --target wasm / --target web) into the same default-all branch, so wasm_snippets.ts was being host-linked and failing on missing `bloom_*` externs. - doc-tests/main.rs: track `platforms_seen` and only fall back to the default-all set when no directive was present at all. An explicit empty `// platforms:` now means "no host platforms". - wasm_snippets.ts: switch to the new opt-out form and document why. Cargo.lock follows v0.5.324 from 8190ec6.
1 parent 8190ec6 commit 6d1b678

3 files changed

Lines changed: 47 additions & 36 deletions

File tree

Cargo.lock

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/perry-doc-tests/src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,15 @@ fn read_banner(path: &Path) -> Result<Banner> {
415415
let text = std::fs::read_to_string(path)
416416
.with_context(|| format!("reading {}", path.display()))?;
417417
let mut b = Banner::default();
418+
let mut platforms_seen = false;
418419
for line in text.lines().take(15) {
419420
let line = line.trim_start();
420421
if !line.starts_with("//") {
421422
break;
422423
}
423424
let body = line.trim_start_matches("//").trim();
424425
if let Some(rest) = body.strip_prefix("platforms:") {
426+
platforms_seen = true;
425427
for item in rest.split(',') {
426428
let t = item.trim();
427429
if !t.is_empty() {
@@ -447,8 +449,13 @@ fn read_banner(path: &Path) -> Result<Banner> {
447449
}
448450
}
449451
}
450-
// Default to "all hosts" if banner didn't specify.
451-
if b.platforms.is_empty() {
452+
// Default to "all hosts" only when no `platforms:` directive was given.
453+
// An explicit empty `// platforms:` (no values) is the way an example
454+
// opts out of the host run phase entirely — used by examples whose
455+
// `declare function` FFI imports only resolve under `--target wasm` /
456+
// `--target web`, where they lower to WASM imports instead of host
457+
// linker externs.
458+
if !platforms_seen {
452459
for p in ["macos", "linux", "windows"] {
453460
b.platforms.insert(p.to_string());
454461
}

docs/examples/platforms/wasm_snippets.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
// demonstrates: per-API wasm/web snippets shown in docs/src/platforms/wasm.md
22
// docs: docs/src/platforms/wasm.md
3-
// platforms: macos, linux, windows
3+
// platforms:
4+
// targets: wasm, web
45
// run: false
56

6-
// `run: false` because the snippets here either declare external FFI
7-
// functions whose host implementations live only in the browser bridge,
8-
// or call `fetch()` against a non-existent telemetry endpoint. The harness
9-
// still compiles + links the file on every PR, which catches API drift in
10-
// `declare function`, `fetch()`'s options shape, and `parallelMap` (whose
11-
// FFI lives in perry-runtime + perry-stdlib).
7+
// Empty `// platforms:` opts out of the host run phase. The `declare function`
8+
// FFI imports (`bloom_init_window`, `bloom_draw_rect`) lower to WASM imports
9+
// under `--target wasm` / `--target web`, but resolve through the host linker
10+
// on a native compile — and the host has no `bloom_*` symbols, so a native
11+
// link fails with `undefined reference`. The cross-compile phase still drives
12+
// `--target wasm` and `--target web` to catch API drift in `declare function`,
13+
// `fetch()`'s options shape, and `parallelMap` (whose FFI lives in
14+
// perry-runtime + perry-stdlib). `run: false` keeps the cross-compile artifact
15+
// from being executed.
1216

1317
import { parallelMap } from "perry/thread"
1418

0 commit comments

Comments
 (0)