There may be some relevant or interesting things to learn by looking at this:
I've wanted to do some kind of dynamic Wasm generation--even very simple--so we can have something like the experience of the TCC natives, but on the web. So seeing what they have to go through is probably informative.
Here are the design notes: