I have a Rust library with the following regular structure:
Cargo.toml
src
|--lib.rs
.cargo
|--config (specifies target=asmjs-unknown-emscripten)
target
|......
When I do cargo build, I get a new directory under the target name asmjs-unknown-emscripten, but the .js files I expect do not exist.
As this user notes , you need to do something special to export functions to asm.js, in addition to being publicly available:
Basically, you have this template now:
#[link_args = "-s EXPORTED_FUNCTIONS=['_hello_world']"]
extern {}
fn main() {}
#[no_mangle]
pub extern fn hello_world(n: c_int) -> c_int {
n + 1
}
Then you can use this in your javascript to access and call the function:
var hello_world = cwrap('hello_world', 'number', ['number']);
console.log(hello_world(41));
However, Rust complains about the directive #[link_args...]as deprecated. Is there any documentation that can explain how this works?