rustyscreeps / cargo-screeps

Build tool for deploying Rust WASM code to Screeps game servers
MIT License
25 stars 13 forks source link

Screeps code doesn't run - CompileError: WebAssembly.Module() [...] Invalid Opcode (enable with --experimental-wasm-se) @+70767 #42

Closed Octaeon closed 9 months ago

Octaeon commented 1 year ago

To be honest, Web Assembly honestly seems like black magic to me and I hoped I wouldn't have to mess with it and just code in Rust, but as it stands, I couldn't even get the example code from https://github.com/rustyscreeps/screeps-starter-rust to work. The error messages vary between ticks for some reason, but the stack trace always ends at the code const wasmModule = new WebAssembly.Module(bytes);

I googled a bit and it seems like the problem is that WebAssembly can't parse the binary data. As per the error message, I tried to add --experimental-wasm-se to the extra_options = [] in [build] in screeps.toml, but when doing that, the code isn't even compiled when running the command cargo screeps deploy.

For the reference, here is the entire error message from screeps:

caught exception: CompileError: WebAssembly.Module(): Compiling wasm function #55:core::num::flt2dec::strategy::grisu::format_exa... failed: Invalid opcode (enable with --experimental-wasm-se) @+43788 at screeps-starter-rust:410:20 at screeps-starter-rust:416:3 at Object.exports.evalCode (:15851:76) at Object.requireFn (:46524:28) at Object.module.exports.loop (main:28:27) at mainLoop:1:52 at mainLoop:2:3 at Object.exports.evalCode (:15851:76) at Object.exports.run (:46474:24)

I haven't changed anything in the code itself or the configuration, apart from changing the name of the destination directory from default to rust-screeps to compare the differences between my new and old code.

LeonMatthes commented 1 year ago

I'm not a developer of cargo-screeps, but encountered the same issue. See https://github.com/rustyscreeps/screeps-game-api/issues/391 for a workaround.