Skip to content

worker-build: keep the producers section in emscripten builds - #1104

Merged
guybedford merged 1 commit into
cloudflare:mainfrom
JesusFileto:emscripten-producers-section
Oct 19, 2026
Merged

guybedford merged 1 commit into
cloudflare:mainfrom
JesusFileto:emscripten-producers-section

Conversation

@JesusFileto

Copy link
Copy Markdown
Contributor

worker-build --emscripten output carries almost none of the WebAssembly producers custom section. The examples/emscripten build ends up with only the sdk: workers-rs entry, while wasm32-unknown-unknown builds also record the source languages and the tools that processed the module. That section is how we tell which toolchain built a Wasm file, and we also use it for internal metrics (see #1091).

The cause is emcc's default: EMIT_PRODUCERS_SECTION is off, and the final link strips producers to save size and avoid leaking toolchain details on websites (WebAssembly/tool-conventions#93). worker-build then re-adds just its sdk entry, so detection still works, but the compiler and tool entries are lost.

This adds -sEMIT_PRODUCERS_SECTION=1 to the emcc link settings. With emsdk 6.0.10, examples/emscripten goes from

sdk: workers-rs 0.8.7

to

language: Rust, C11, C99
processed-by: rustc 1.100.0-beta.7, clang 24.0.0git, walrus 0.27.2,
              wasm-bindgen 0.2.129
sdk: workers-rs 0.8.7

That's 227 bytes raw (173 gzipped). Only the producers section changes: with custom sections stripped the modules are byte-identical, and index.js is unchanged. Recording Emscripten itself under processed-by would be a possible follow-up, and is left out of this PR.

Testing: built examples/emscripten before and after the change and compared the two modules with wasm-tools metadata show and wasm-tools strip -a. Ran the CI wrangler dev smoke test against the new build, plus cargo test -p worker-build, clippy, cargo fmt --check and cargo check --locked.

emcc strips the producers custom section unless
EMIT_PRODUCERS_SECTION is set, so --emscripten builds only carried the
sdk entry worker-build adds afterwards. Set it at link so they keep
the language and processed-by entries that wasm32-unknown-unknown
builds already have.

@logan-gatlin logan-gatlin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

@guybedford
guybedford merged commit c24dec9 into cloudflare:main Oct 19, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants