Closed AaronFriel closed 3 years ago
I've added CI changes here which I think may work, but I'm more of a GitLab yaml engineer myself.
https://github.com/AaronFriel/typetag/commit/3c76524c26c3ccea3c9973b87b5abe54e09bd193
Hey @dtolnay, I'm not sure if that would work for dynamic linking of WASM modules. Would linkme
work with WASM module support, at least as I've understood this:
https://github.com/WebAssembly/module-linking/blob/master/proposals/module-linking/Explainer.md
Admittedly, I don't know much about the state of the WASM spec or if it's possible to use a WebAssembly.Global() that is extended/modified on module instantiation.
Would linkme
support that use case, or - at least - allow collecting all of the trait implementations defined in a module into a single variable, so the global type registry can be updated?
Oh I think I may have misunderstood - if linkme
were a language feature do you mean as a Rust RFC? I'm afraid LLVM and WASM semantics are a few steps beyond what I'm familiar with, I doubt I'd be the right person to champion that.
Problem
WASM targets do not support
ctor
crate, a dependency ofinventory
. Static/pre-main registration also goes against the Rust guidelines (covered elsewhere) that there ought to be no code before main. (Part of the philosophy of explicit is better than implicit, I take it?)This is an issue and has been reported in #30, #15, and others.
Possible Solution
Runtime, explicit registration functions.
This adds a feature
runtime
which enables runtime registration of types and removesinventory
.This likely isn't up to the coding standard you'd use or how features ought to be used, and I'd appreciate any advice there. I thought about declaring feature
std = ["std", "inventory"]
, but I think inventory works in no_std, non-wasm environments, so I'm not sure if there's a way to turn offinventory
as a dependency and enableruntime
as a feature in wasm environments automatically. If there is, that would be fantastic.The two things I'm most uncertain about are:
register
fn on traits, should probably rename that to something less likely to conflict, though it is a static method, so it's only callable via<A as Trait>::register()
whereTrait
has a#[typetag]
macro-attr