I'm generating asm.js from a Rust file like so:
rustc demo.rs --target asmjs-unknown-emscripten -C opt-level=0 -C link-arg="-s MINIMAL_RUNTIME=1" -C link-arg="-s ENVIRONMENT=web" -C link-arg="-s LEGACY_VM_SUPPORT=1" -o ../../build/bytecode/demo.asm.js
However, when I look through the generated asm.js file, I can clearly see that those compiler options were not passed through - the code still assumes it can be run in any environment, and the legacy VM polyfills are missing.
What am I missing?
This is the rust file, in case that matters:
#[allow(dead_code)]
pub fn my_add(num1: f64, num2: f64) -> f64 {
return num1 + num2;
}
pub fn main() {
println!("Rust loaded");
}
I have two suggestions.
If we look at the documentation, there is both the
link-argoption to pass a single argument andlink-argsto pass multiple arguments. Becauselink-argsexist, and the doc specify that arguments must be separated by spaces, maybe you should use... link-args="-s MINIMAL_RUNTIME=1", or even... -C link-arg="-s" -C link-arg="MINIMAL_RUNTIME=1" ...Haven't tried it though.Second, there seem to be the old way of passing arguments to the linker of a specific compiler according to this post. You can create a wrapper around the
emcccompiler by creating a file namedemcc_sdlin your project folder which contains:Make it executable:
Create or edit the
.cargo/configfile and add:You should be able to build using:
Hope it helps.