Simple AssemblyScript example fails to compile
Closed this issue ยท 5 comments
Hi,
I'm trying to compile AssemblyScript with Lucetc, but even the most basic example seems to not work. I'm pretty sure I'm missing something because I get this error:
Error: Lucet Module: Unknown module for symbol `env::abort
These are the steps I used to get to that point:
- Install AssemblyScript globally with
npm install -g assemblyscript
. - Initialize a new AS project in the current directory with
npx asinit .
. - Compile the wasm module with
npm run asbuild:optimized
. - Compile the wasm module with lucetc with
lucetc build/optimized.wasm -o app
.
What's the expected abort symbol? I've seen some examples that use wasi_abort
, but I don't want/need wasi.
I put the generated wat in a gist. Now that I looked at it, it makes sense that it fails because AS is importing env::abort from its builtins:
https://gist.github.com/calavera/0e7344bd37495f2bfc413d40a6b8ae57#file-gistfile1-txt-L11
How can I tell lucetc to use those builtins?
Hello again @calavera ! ๐
Thanks for opening this issue! You can fix this by adding the --use abort=wasi_abort
flag when you compile your AssemblyScript ๐
What this will do, is assign the abort to the wasi_abort
provided by as-wasi (which I think I remember you saying you are using): https://github.com/jedisct1/as-wasi/blob/master/assembly/as-wasi.ts#L1036
What's the expected abort symbol? I've seen some examples that use wasi_abort, but I don't want/need wasi.
Ah, I just read this. So it seems that I do have an abort import on WasmBoy. But that was done a while ago, and the language has grown quite a bit since then.
Oh wait, I found it in the AS docs. You still use the --use abort=my_abort_function
when you compile your assemblyscript function when you use the asc
compiler in you npm run asbuild:optimized
npm script. Then you can handle aborting yourself however you see fit. ๐ That docs page also contains reasoning on why you need to handle aborting and things which may be helpful for you ๐
Let me know if that helps! ๐ Also, Sorry for the stream of consciousness reply haha ๐
Also, cc @dcodeIO . Maybe it's worth us adding some abort defaults? ๐ I'll open an issue
That's super helpful, thanks @torch2424.
I'm going to close this issue because it doesn't look like it's lucet's problem. I might open a PR with a more straightforward example if I make it work.