Have some free time on my hands so I thought I'd try out Odin, an interesting language I came across a few weeks ago. I haven't dived too far into it but so far from what I understand, it's another language in a similar vain of Rust and Zig(both also very good)
Since as far as I can tell, though Odin does support WebAssembly, how specifically to build for it is not well documented so I thought I should post a very basic setup for WebAssembly.
All the Odin app does is
- export a function that called
setup
that calls an imported JS functiongetWindowWidth
- In the JS, it calls
setup
and logs the result.
When building the Odin code, the command is roughly
odin build <app location> -target="js_wasm32" -out="<output location>"
If you add custom packages, don't forget to add the -collection
flag to the command.
Note there are multiple flavors of Wasm you can build for but js_wasm32 is likely gonna be what you want if you intend to interface with JS. At the time of this writing(2/13/2024), the targets include
- freestanding_wasm32
- wasi_wasm32
- js_wasm32
- freestanding_wasm64p32
- js_wasm64p32
- wasi_wasm64p32
There's still a lot I don't understand of course, especially how the foreign
keyword works in this context so take this with a grain of salt.