Skip to content

feat: support multiple and private #[wasm_bindgen(start)] functions - #5081

Merged
guybedford merged 5 commits into
mainfrom
feat/multiple-start-functions
Apr 6, 2026
Merged

guybedford merged 5 commits into
mainfrom
feat/multiple-start-functions

Conversation

@guybedford

@guybedford guybedford commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Adds support for multiple start functions by chaining them together when registered, including an end-to-end CLI test to verify execution order.

Also adds support for #[wasm_bindgen(start, private)] to declare private start functions which are not exported by the Wasm exports. This one implies a schema bump.

@guybedford
guybedford force-pushed the feat/multiple-start-functions branch 5 times, most recently from ccf22dc to a50adec Compare April 3, 2026 02:32
@guybedford guybedford changed the title feat: support multiple #[wasm_bindgen(start)] functions feat: support multiple and private #[wasm_bindgen(start)] functions Apr 3, 2026
@guybedford guybedford added the schema-change Changes which require a schema version bump label Apr 3, 2026
@guybedford
guybedford force-pushed the feat/multiple-start-functions branch from a50adec to 9392b9d Compare April 3, 2026 02:34
@guybedford
guybedford force-pushed the feat/multiple-start-functions branch from 459ad06 to c151ba5 Compare April 6, 2026 18:16
guybedford and others added 2 commits April 6, 2026 15:40
…_bindgen(start, private)]`

Previously, specifying more than one `#[wasm_bindgen(start)]` function
would error with "cannot specify two `start` functions". This removes
that restriction and chains multiple start functions together.

Also adds support for `#[wasm_bindgen(start, private)]` which registers
the function as a start function without exporting it to JS.

The `start: bool` field in the shared schema is replaced with a
`StartKind` enum (None, Public, Private).
@guybedford
guybedford force-pushed the feat/multiple-start-functions branch from 5da733f to 93635bc Compare April 6, 2026 22:40
@hoodmane

hoodmane commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

How do you tell what order multiple start functions should run in?

@guybedford

Copy link
Copy Markdown
Contributor Author

We basically have zero ordering guarantees.

@hoodmane

hoodmane commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Is it fair to call it a start function anymore then? I think that is more like a C constructor. Does Rust allow similar things on other platforms?

@guybedford

Copy link
Copy Markdown
Contributor Author

The use case is more about the JS embedding - JavaScript modules participate in initialization steps that are able to interact with the host environment. This gives that capacity to separate Rust code, without requiring a singular coordination point, just like modules in JS don't need to register their top-level initializations to access things like globals.

@guybedford

Copy link
Copy Markdown
Contributor Author

I'm open to giving it a new alias, but this does match the WebAssembly start function semantics in the JS ESM integration.

@guybedford
guybedford enabled auto-merge (squash) April 6, 2026 23:02
@guybedford
guybedford merged commit d6c12bd into main Apr 6, 2026
63 checks passed
@guybedford
guybedford deleted the feat/multiple-start-functions branch April 6, 2026 23:14
@guybedford guybedford mentioned this pull request Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

schema-change Changes which require a schema version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants