Skip to content

Support static constructors (ctors) #1216

@daboross

Description

@daboross

My main motivation here is using typetag, which depends on rust-ctor to function.

rust-ctor uses link sections on Windows, Mac and Linux to allow functions to run main. Any crate can add these functions, and then they'll all be run without needing central configuration. The problem is that this depends on Windows/Mac/Linux specific link sections, and there is no equivalent for wasm32.

I'm opening this issue for discussion of static constructors (also called global or module constructors) and wasm-bindgen. . My ideal resolution would be adding support for something to wasm-bindgen, and then rust-ctor could use that support and crates like typetag would simply work.

I opened stdweb#321 earlier for the same issue, but @koute mentioned that it might be a good idea to coordinate how this is done across the ecosystem rather than having stdweb and wasm-bindgen implement separate measures.


Arbitrary discussions I've found about ctors and WASM which may or may not be relevant:


I don't have a concrete proposal, mostly just opening this up for discussion. Also, if anyone knows any prior work on ctors+rust+wasm that could be linked, I'd greatly appreciate it!

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