Skip to content

Commit a3aa24c

Browse files
committed
fix(book): only set web_sys_unstable_apis for examples that need it
1 parent dc337d3 commit a3aa24c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

docs/book/post_build.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ def build_and_copy_demo(script_dir, category, md_name):
2222
name = md_name[:-3]
2323
example_dir = os.path.normpath(os.path.join(script_dir, f"../../examples/{name}"))
2424
if os.path.exists(example_dir):
25-
env = os.environ.copy()
26-
env["RUSTFLAGS"] = (env.get("RUSTFLAGS", "") + " --cfg=web_sys_unstable_apis").strip()
25+
# only inject web_sys_unstable_apis for examples that have it in their
26+
# .cargo/config.toml (e.g. use_web_lock, use_webtransport)
27+
cargo_config = os.path.join(example_dir, ".cargo", "config.toml")
28+
env = None
29+
if os.path.exists(cargo_config):
30+
with open(cargo_config, "r") as f:
31+
if "web_sys_unstable_apis" in f.read():
32+
env = os.environ.copy()
33+
env["RUSTFLAGS"] = (env.get("RUSTFLAGS", "") + " --cfg=web_sys_unstable_apis").strip()
2734
p = subprocess.Popen(["trunk", "build", "--release"], cwd=example_dir, env=env)
2835
code = p.wait()
2936

0 commit comments

Comments
 (0)