Skip to content

Wire ctc-emcc native launcher into WASM cross-file (skip Python wrapper) #2485

Closed

Description

@zackees

Background

The native build pipeline already replaced the slow clang-tool-chain-*-cpp.EXE Python entry points (~828ms startup each) with raw clang++.exe resolved by _resolve_fast_native_entries() in ci/meson/build_config.py. That single change cut Meson setup from 27.60s → 10.13s (-63%) and total build from 47.58s → 21.66s (-54%).

The WASM build path was not migrated and still pays the Python-wrapper cost on every compile.

Current state

ci/meson/wasm_cross_file.ini:17-19:

c   = 'clang-tool-chain-emcc'
cpp = 'clang-tool-chain-emcc'
ar  = 'clang-tool-chain-emar'

These are Python entry points (clang_tool_chain.wrapper:emcc_main, etc.). Each invocation pays the ~800ms+ Python startup tax.

What already exists

The native C++ launchers are already built and sitting in the cache directory:

  • .build/native-tools/ctc-emcc.exe — three-tier strategy compiled from launcher_emcc.cpp (in clang_tool_chain/native_tools/):
    1. User template (--compile-commands / --link-args): pre-cached clang/wasm-ld command with {input}/{output} substitution.
    2. Auto-cache: on first compile with EMCC_VERBOSE=1, captures the real clang command from stderr, templatizes it, caches by flag hash; subsequent same-flag compiles call clang directly.
    3. Python fallback: link/preprocess/uncached invocations exec the Python emcc.py.
  • .build/native-tools/ctc-wasm-ld.exe — same idea for the linker.
  • clang-tool-chain ships the launcher source; clang-tool-chain-bins (already installed, 0.4.1) ships the underlying emcc/node binaries; clang_tool_chain.commands.compile_native.compile_native() builds the launcher on demand.

The integration plumbing (_ensure_native_launcher(), _resolve_fast_native_entries()) already exists for ctc-clang/ctc-clang++. The WASM launchers are just not wired in yet.

Proposed change

Three files:

  1. ci/meson/wasm_cross_file.ini — point c / cpp / ar at the compiled ctc-emcc.exe / ctc-emar (or template variables resolved at generation time) instead of the Python entry points.
  2. ci/meson/build_config.py — extend _resolve_fast_native_entries() (line 186) and _ensure_native_launcher() (line 52) to also build/cache the emcc launchers, mirroring the clang++ path.
  3. ci/wasm_build.py — generate a WASM-flavored native file (or supplement the cross-file) so meson picks up the resolved binaries during ensure_meson_configured().

Fallback: if the native launcher build fails, keep the Python wrapper as the resolved value so the WASM build doesn't break.

Expected payoff

Similar magnitude to the native build win — likely 50–60% reduction in WASM meson setup time and a meaningful drop in compilation wall-clock from removing per-invocation Python startup.

Acceptance

  • WASM meson setup invokes ctc-emcc.exe (verifiable in the generated cross-file or native file).
  • A clean WASM build (bash compile wasm --examples Blink) runs end-to-end with the native launcher.
  • Benchmark: before/after timings recorded in the PR description.
  • Python-wrapper fallback path is exercised at least once (e.g., simulated by removing the cached native binary).

Activity

  1. added a commit that references this issue on May 18, 2026
    b94ab3a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions