Repository navigation
perf(wasm): upgrade to clang-tool-chain 1.5.1, wire all 7 native launchers including ctc-wasm-ld - #2490
Conversation
Extends the WASM cross-file generator to wire the remaining native
launchers from clang-tool-chain's emtool family (1.3.1+). All four
binaries (emar + emstrip + emranlib + emnm) come from a single
launcher_emtool.cpp compilation, so this is essentially free.
Changes:
- EmccNativeLaunchers dataclass: add emstrip/emranlib/emnm fields.
- WasmNativeEntries dataclass: add strip/ranlib/nm fields (Optional;
None means meson should omit the corresponding cross-file field
because clang-tool-chain ships no Python wrapper fallback for these
three — see zackees/clang-tool-chain#23).
- _ensure_emcc_native_launcher: probe all six binaries; trigger
compile_native() if any are missing.
- resolve_wasm_native_entries: populate the new fields.
- _render_wasm_cross_file: emit strip/ranlib/nm only when the native
launcher resolved; log each that resolved.
The compile/link path is unchanged — strip/ranlib/nm aren't typically
invoked during normal WASM compile-and-link. Wiring them follows the
established pattern and gives speedup if/when meson does invoke them
(e.g., on `meson install --strip` or future cross-build flows).
Companion to upstream tracking:
- zackees/clang-tool-chain#22 (no clean ctc-wasm-ld integration path)
- zackees/clang-tool-chain#23 (Python wrapper parity for emstrip/
emranlib/emnm — once shipped, this PR's None-omission logic can be
simplified to match the emar fallback pattern)
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds required native launcher paths (emcc/empp/emar/emstrip/emranlib/emnm/wasm_ld) and updates resolvers/dataclasses to require and validate them; introduces an Emscripten patch helper, sets EMCC_WASM_LD when rendering Meson cross-files, emits strip/ranlib/nm in [binaries], and bumps clang-tool-chain. ChangesExtend emcc native tool launcher support to strip, ranlib, nm, wasm_ld
Sequence DiagramsequenceDiagram
participant WasmCrossFileGen as _render_wasm_cross_file
participant Resolver as resolve_wasm_native_entries
participant NativeProbe as _ensure_emcc_native_launcher
participant Env as os.environ
participant Meson as MesonCrossFile
WasmCrossFileGen->>Resolver: request resolved entries (c/cpp/ar/strip/ranlib/nm/wasm_ld)
Resolver->>NativeProbe: probe and compile ctc-em* native launchers
NativeProbe-->>Resolver: EmccNativeLaunchers (native paths)
Resolver-->>WasmCrossFileGen: WasmNativeEntries (native paths)
WasmCrossFileGen->>Env: set EMCC_WASM_LD=wasm_ld (if native)
WasmCrossFileGen->>Meson: emit [binaries] including strip/ranlib/nm values
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ci/meson/build_config.py`:
- Around line 69-71: Add runtime type validation by importing typechecked from
typeguard and applying the `@typechecked` decorator to the dataclasses that
declare the emstrip, emranlib, emnm fields (and the other dataclass around lines
88-90). Specifically, add "from typeguard import typechecked" at the top and
place `@typechecked` immediately above the existing `@dataclass` declarations for
the classes that contain those Optional[str] attributes so they perform runtime
type checking.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 00e9c2a5-901b-433b-870d-5e9008ce2181
📒 Files selected for processing (2)
ci/meson/build_config.pyci/wasm_build.py
clang-tool-chain 1.5.1 (released 2026-05-19) closes both upstream issues filed during the previous WASM optimization work: - #22 (ctc-wasm-ld integration): emscripten installer now patches shared.py to honor EMCC_WASM_LD env var, letting downstream projects swap in ctc-wasm-ld for the bundled linker. - #23 (Python wrapper parity): clang-tool-chain-emstrip, -emranlib, -emnm, -wasm-ld console scripts now exist, mirroring -emar/-emcc/-empp. Changes ------- pyproject.toml: clang-tool-chain >=1.4.0 -> >=1.5.1 ci/meson/build_config.py: - Add @TypeChecked decorators to EmccNativeLaunchers and WasmNativeEntries (matches the project-wide convention enforced in 5 other ci/ modules; CodeRabbit feedback on PR #2490). - Add wasm_ld field to both dataclasses. - Simplify WasmNativeEntries: strip/ranlib/nm/wasm_ld are now always str (Python wrapper fallback names exist in 1.5.1), no more Optional / omit-on-missing complexity. - _ensure_emcc_native_launcher: probe ctc-wasm-ld alongside the other six binaries. - resolve_wasm_native_entries: populate all fields with native paths when available, Python wrapper names otherwise. ci/wasm_build.py: - New _ensure_emscripten_wasm_ld_patch helper: lazily calls ensure_emscripten_available() once per process to apply (idempotent) the EMCC_WASM_LD shared.py patch on the existing emscripten install. - _render_wasm_cross_file now sets EMCC_WASM_LD in os.environ pointing at the resolved wasm_ld path (native ctc-wasm-ld when compiled, Python wrapper otherwise). This routes emcc's internal wasm-ld invocation through ctc-wasm-ld for the link step. - Cross-file template always emits strip/ranlib/nm (Python wrapper fallbacks are now usable values). - Log resolution status for all six native launchers including ctc-wasm-ld. Verification ------------ Clean WASM build of examples/Blink with native launcher cache cleared: [WASM] Using native ctc-emcc launcher: ...\ctc-emcc.exe [WASM] Using native ctc-emar launcher: ...\ctc-emar.exe [WASM] Using native ctc-emstrip launcher: ...\ctc-emstrip.exe [WASM] Using native ctc-emranlib launcher: ...\ctc-emranlib.exe [WASM] Using native ctc-emnm launcher: ...\ctc-emnm.exe [WASM] Using native ctc-wasm-ld for emcc linker: ...\ctc-wasm-ld.exe [WASM] Build successful! Total: 17.50s The shared.py patch is confirmed in place at ~/.clang-tool-chain/emscripten/win/x86_64/emscripten/tools/shared.py: # CTC_EMCC_WASM_LD_PATCH: honor EMCC_WASM_LD for ctc-wasm-ld integration WASM_LD = os.environ.get('EMCC_WASM_LD') or llvm_tool_path('wasm-ld') Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…1 guarantees natives
clang-tool-chain >=1.5.1 is pinned and compile_native() builds all
seven WASM launchers (clang, emcc/em++, emar, emstrip, emranlib, emnm,
wasm-ld) in one call. The Python-wrapper fallback paths were dead
weight — every successful build resolved 7-of-7 natives, and any
failure mode is better surfaced as a hard error than silent
degradation to 800ms-per-call Python wrappers.
Changes
-------
ci/meson/build_config.py:
- EmccNativeLaunchers: all fields are str (was Optional[str]).
- WasmNativeEntries: all fields are str (was Optional for
strip/ranlib/nm); dropped used_native_launcher (always True now
or function raises).
- _ensure_emcc_native_launcher: raises RuntimeError with a
descriptive message if compile_native() fails or any binary
is missing afterward. No more None returns.
- resolve_wasm_native_entries: tiny pass-through. No fallback
construction.
ci/wasm_build.py:
- _render_wasm_cross_file: unconditional native-launcher logging
(one line per binary); no more "ctc-X unavailable; using Python
wrapper" branches.
Aligns with the project guideline "Never use silent fallbacks for
missing critical resources — always fail fast with descriptive errors"
flagged by CodeRabbit on the original ctc-emcc PR.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The python_pipeline lint phase was failing on master with two KeyboardInterrupt-handling violations and one type-mismatch the KBI errors were hiding. Cleared all three so the pipeline goes green end-to-end. 1. ci/compiler/pio.py:518 — try/except Exception without explicit KeyboardInterrupt handler (KBI001). Added the standard `except KeyboardInterrupt as ki: handle_keyboard_interrupt(ki); raise` ahead of the generic Exception clause. Module already imports handle_keyboard_interrupt. 2. ci/util/fbuild_runner.py:161 — KeyboardInterrupt handler re-raised without calling handle_keyboard_interrupt or _thread.interrupt_main (KBI002). Routed through handle_keyboard_interrupt (inline import to avoid adding a top-level dependency in this utility module). 3. ci/compiler/pio.py:346 — _init_platformio_build was being called positionally with self.additional_defines slipping into the build_dir slot (ty: invalid-argument-type). Switched to keyword arguments for all optional params so the alignment is explicit. This was a latent bug — the function would have failed at runtime if build_dir was used (e.g., for path resolution). Caught by ty only after the KBI lint failures stopped masking the rest of the python_pipeline output. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ci/wasm_build.py`:
- Around line 474-493: The try-except currently swallows KeyboardInterrupt;
modify the block so KeyboardInterrupt is handled before the broad Exception: add
an except KeyboardInterrupt: raise to re-raise the interrupt, then keep the
existing except Exception as e: print(...) fallback that sets/mentions
_emscripten_patch_applied and the EMCC_WASM_LD patch attempt log; locate the try
that calls ensure_emscripten_available and adjust the exception handlers
accordingly so user Ctrl+C will propagate.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9cc04d42-fec9-4d85-9ba6-71ab8d53cc36
📒 Files selected for processing (2)
ci/meson/build_config.pyci/wasm_build.py
| try: | ||
| import platform as _platform_mod | ||
|
|
||
| from clang_tool_chain.installers.emscripten import ensure_emscripten_available | ||
|
|
||
| system = _platform_mod.system().lower() | ||
| platform_name = ( | ||
| "win" | ||
| if system == "windows" | ||
| else ("darwin" if system == "darwin" else "linux") | ||
| ) | ||
| machine = _platform_mod.machine().lower() | ||
| arch = "x86_64" if machine in ("x86_64", "amd64") else "arm64" | ||
| ensure_emscripten_available(platform_name, arch) | ||
| _emscripten_patch_applied = True | ||
| except Exception as e: | ||
| # Patch is best-effort. Without it, EMCC_WASM_LD is ignored and emcc | ||
| # falls back to the bundled wasm-ld — the build still works, just | ||
| # without the ctc-wasm-ld speedup on link. | ||
| print(f"[WASM] EMCC_WASM_LD patch attempt failed (non-fatal): {e}") |
There was a problem hiding this comment.
Handle KeyboardInterrupt before catching generic Exception.
The try-except block catches all exceptions including KeyboardInterrupt, preventing users from cancelling the operation with Ctrl+C. While the patch is best-effort, KeyboardInterrupt should propagate to allow user cancellation.
🐛 Proposed fix
try:
import platform as _platform_mod
from clang_tool_chain.installers.emscripten import ensure_emscripten_available
system = _platform_mod.system().lower()
platform_name = (
"win"
if system == "windows"
else ("darwin" if system == "darwin" else "linux")
)
machine = _platform_mod.machine().lower()
arch = "x86_64" if machine in ("x86_64", "amd64") else "arm64"
ensure_emscripten_available(platform_name, arch)
_emscripten_patch_applied = True
+ except KeyboardInterrupt:
+ raise
except Exception as e:
# Patch is best-effort. Without it, EMCC_WASM_LD is ignored and emcc
# falls back to the bundled wasm-ld — the build still works, just
# without the ctc-wasm-ld speedup on link.
print(f"[WASM] EMCC_WASM_LD patch attempt failed (non-fatal): {e}")As per coding guidelines, "All Python try-catch blocks must handle KeyboardInterrupt before other exceptions".
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| try: | |
| import platform as _platform_mod | |
| from clang_tool_chain.installers.emscripten import ensure_emscripten_available | |
| system = _platform_mod.system().lower() | |
| platform_name = ( | |
| "win" | |
| if system == "windows" | |
| else ("darwin" if system == "darwin" else "linux") | |
| ) | |
| machine = _platform_mod.machine().lower() | |
| arch = "x86_64" if machine in ("x86_64", "amd64") else "arm64" | |
| ensure_emscripten_available(platform_name, arch) | |
| _emscripten_patch_applied = True | |
| except Exception as e: | |
| # Patch is best-effort. Without it, EMCC_WASM_LD is ignored and emcc | |
| # falls back to the bundled wasm-ld — the build still works, just | |
| # without the ctc-wasm-ld speedup on link. | |
| print(f"[WASM] EMCC_WASM_LD patch attempt failed (non-fatal): {e}") | |
| try: | |
| import platform as _platform_mod | |
| from clang_tool_chain.installers.emscripten import ensure_emscripten_available | |
| system = _platform_mod.system().lower() | |
| platform_name = ( | |
| "win" | |
| if system == "windows" | |
| else ("darwin" if system == "darwin" else "linux") | |
| ) | |
| machine = _platform_mod.machine().lower() | |
| arch = "x86_64" if machine in ("x86_64", "amd64") else "arm64" | |
| ensure_emscripten_available(platform_name, arch) | |
| _emscripten_patch_applied = True | |
| except KeyboardInterrupt: | |
| raise | |
| except Exception as e: | |
| # Patch is best-effort. Without it, EMCC_WASM_LD is ignored and emcc | |
| # falls back to the bundled wasm-ld — the build still works, just | |
| # without the ctc-wasm-ld speedup on link. | |
| print(f"[WASM] EMCC_WASM_LD patch attempt failed (non-fatal): {e}") |
🧰 Tools
🪛 Ruff (0.15.13)
[warning] 489-489: Do not catch blind exception: Exception
(BLE001)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@ci/wasm_build.py` around lines 474 - 493, The try-except currently swallows
KeyboardInterrupt; modify the block so KeyboardInterrupt is handled before the
broad Exception: add an except KeyboardInterrupt: raise to re-raise the
interrupt, then keep the existing except Exception as e: print(...) fallback
that sets/mentions _emscripten_patch_applied and the EMCC_WASM_LD patch attempt
log; locate the try that calls ensure_emscripten_available and adjust the
exception handlers accordingly so user Ctrl+C will propagate.
…ndler (#2586) The try/except around ensure_emscripten_available() catches Exception broadly. While KeyboardInterrupt is not Exception (so Ctrl-C does propagate in practice), the repo guideline is to make the re-raise explicit. Adds `except KeyboardInterrupt: raise` before the existing `except Exception as e:` handler. Addresses CodeRabbit finding D2 from meta #2580 (originally #2490).
Summary
Upgrades
clang-tool-chainto 1.5.1, which closes both upstream issues filed during the previous WASM optimization work (#22, #23), and wires the full set of native launchers — includingctc-wasm-ldfor the emcc link step, which was previously blocked on upstream.Builds on #2487 (ctc-emcc), #2489 (ctc-emar).
What's new in clang-tool-chain 1.5.1
clang-tool-chain install emscriptennow patchesshared.pyto honor theEMCC_WASM_LDenv var. Setting it lets downstream projects route emcc's internal wasm-ld through a custom binary (e.g.,ctc-wasm-ld).clang-tool-chain-emstrip/-emranlib/-emnm/-wasm-ld— mirroring the existing-emcc/-empp/-emartrio.compile-nativenow produces 1 binary + 17 hardlinks instead of 17 separate compile targets.argv[0]basename dispatches. Saves ~19 MB per platform.Changes in this PR
pyproject.tomlci/meson/build_config.py@typecheckeddecorators to bothEmccNativeLaunchersandWasmNativeEntries(matches the project convention enforced in 5 otherci/modules; CodeRabbit feedback).wasm_ldfield to both dataclasses.WasmNativeEntries:strip/ranlib/nm/wasm_ldare now alwaysstr(Python wrapper fallback names exist in 1.5.1) — no moreOptionalor omit-on-missing complexity._ensure_emcc_native_launcherprobesctc-wasm-ldalongside the other six binaries.resolve_wasm_native_entriespopulates all fields: native paths when available, Python wrapper names otherwise.ci/wasm_build.py_ensure_emscripten_wasm_ld_patch()helper: lazily callsensure_emscripten_available()once per process to apply (idempotent) theEMCC_WASM_LDshared.pypatch on the existing emscripten install._render_wasm_cross_filenow setsEMCC_WASM_LDinos.environpointing at the resolvedwasm_ldpath. This routes emcc's internal wasm-ld invocation through our launcher.strip/ranlib/nm(fallbacks exist).ctc-wasm-ld.Verification
Clean WASM build of
examples/Blinkwith native launcher cache cleared:shared.pypatch confirmed in place at~/.clang-tool-chain/emscripten/win/x86_64/emscripten/tools/shared.py:Test plan
bash lint— passbash compile wasm --examples Blink— pass, all 7 launchers resolvedshared.pypatch verified applied@typecheckeddecorators added per project convention🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Behavior Change
Bug Fixes
Chores