Skip to content

fix: re-add reference-types target feature stripped by strip = true#1015

Closed
connyay wants to merge 1 commit into
cloudflare:mainfrom
connyay:cjh-prevent-strip-bomb
Closed

fix: re-add reference-types target feature stripped by strip = true#1015
connyay wants to merge 1 commit into
cloudflare:mainfrom
connyay:cjh-prevent-strip-bomb

Conversation

@connyay

@connyay connyay commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

strip = true (alias for strip = "symbols") drops the target_features custom section from the compiled wasm, which removes the reference-types advertisement that wasm-bindgen needs to run its externref transform. Without it, builds fail with "externref table required for catch wrappers".

Generalize the wasm custom-section helpers in producers.rs so they can be reused, and add a new reference_types module that patches the feature back in after cargo and before wasm-bindgen runs.

Fixes #1014

`strip = true` (alias for `strip = "symbols"`) drops the
`target_features` custom section from the compiled wasm, which removes
the `reference-types` advertisement that `wasm-bindgen` needs to run
its externref transform. Without it, builds fail with
"externref table required for catch wrappers".

Generalize the wasm custom-section helpers in `producers.rs` so they
can be reused, and add a new `reference_types` module that patches the
feature back in after cargo and before `wasm-bindgen` runs.

Fixes cloudflare#1014
Comment on lines +513 to +516
// `strip = true` drops the target_features section that wasm-bindgen
// needs to enable its externref transform. Patch it back in.
crate::reference_types::ensure_reference_types_feature(&wasm_path)
.context("Failed to ensure the reference-types target feature is advertised")?;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm torn on if patching is the right call here. https://rustwasm.github.io/docs/book/reference/code-size.html#optimizing-builds-for-code-size doesn't mention strip = true, so I am not sure how widespread strip = true or strip = "symbols" is in the wild.

Might be safer to detect strip = true or strip = "symbols" and raise an error instead. Open to suggestions/feedback here.

@guybedford

Copy link
Copy Markdown
Collaborator

Could we just ungate the reference types feature check for externref transforms in wasm bindgen? Surely it can just be assumed now?

@connyay

connyay commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Could we just ungate the reference types feature check for externref transforms in wasm bindgen? Surely it can just be assumed now?

yes. I'll take that approach

@connyay connyay closed this Jun 16, 2026
@connyay connyay deleted the cjh-prevent-strip-bomb branch June 16, 2026 23:55
@connyay

connyay commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Could we just ungate the reference types feature check for externref transforms in wasm bindgen? Surely it can just be assumed now?

yes. I'll take that approach

hm. actually. would need to bump the wasm-bindgen rust version to 1.82 - is there appetite for that?
https://github.com/wasm-bindgen/wasm-bindgen/blob/6ff7f1cd2f636d6f19d29b45680885088cc9e653/Cargo.toml#L15

@guybedford

Copy link
Copy Markdown
Collaborator

We can't bump the library MSRV for another 4 months. The CLI MSRV (the one required by the actual processor), should already be above 1.82 though?

@connyay

connyay commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

👉 wasm-bindgen/wasm-bindgen#5205

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.

[BUG] Can no longer compile with strip = true

2 participants