WebAssembly is a binary language that intends to, among other goals, break the barriers between programming languages.
Currently, it's easy enough to compile C++ code to WebAsm and include it into JavaScript code. There's even a proposal and a Webpack polyfill to make it as easy as import { foo } from 'bar.wasm'.
Moreover, WebAssembly supports wasm files that list their own dependencies, in the form of import declarations.
Is there some polyfill build tool that allows users to include a webasm module into a C++ compilation unit, in the process of compiling it to wasm? For example, let's say I have a Rust module that I want to use inside a C++ module, both of which I'm compiling to wasm. Is there a way to write code equivalent to this:
#include "node_modules/some_rust_utility/index.wasm"
int someCppFunction(const std::string& data) {
return some_rust_utility::foobar(data.c_str());
}
and have it compile or not depending on whether foobar is defined with a matching type in some_rust_utility?
Note: I expect the answer to this question may change over time as WebAssembly support marches on. If you see this question years afterwards and the answer has changed, feel free to add an update.