-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support static constructors (ctors) #1216
Description
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:
- Use wasm start-function linking and __cxa_atexit WebAssembly/tool-conventions#25
- Discussion about whether or not WASM should include ctors
- Ended up with just having a start function: https://github.com/WebAssembly/design/blob/master/Modules.md#module-start-function
- https://github.com/WebAssembly/binaryen#tools
wasm-ctor-evalpre-executes a list of functions meant as static constructors.
- A mechanism is needed for handling constructor functions with the LLVM wasm backend. emscripten-core/emscripten#4218
- Discussion on how emscripten handles this or will handle it in the future?
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!