Skip to content

Example on creating a proper wasm file #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
koenvo opened this issue May 2, 2020 · 5 comments
Closed

Example on creating a proper wasm file #1

koenvo opened this issue May 2, 2020 · 5 comments

Comments

@koenvo
Copy link

koenvo commented May 2, 2020

Hi,

Thanks for this really interesting library. This is a great step for writing code that can run in the browser and in a python backend!

I was wondering if you can share an example of how to compile WebAssembly so it's loadable by python-ext-wasm. I know this issue might be unrelated to this library.

I tried this:

  1. install theassemblyscript npm package
  2. start a new assemblyscript project: npx asinit sometest
  3. build the index.ts file using npm run-script asbuild

When I try to load the file I keep getting:

Traceback (most recent call last):
  File "tests/wasm/test.py", line 7, in <module>
    wasm = Instance(code)
RuntimeError: Failed to instantiate the module:
    link error: Import not found, namespace: env, name: abort

It looks like it's related to "Support imports (needs #28)" but I'm confused by your example which doesn't do anything with imports.

from wasmer import Instance
wasm = Instance(open('yourscript.wasm', 'rb').read())

from wasmbind import Module
module = Module(wasm)

Could you share a some info on how to create a proper .wasm file?

Thanks a lot!

@miracle2k
Copy link
Owner

Yeah, when you compile webassembly you need to disable the abort import using --use abort=.

This is the command line I used:

npx assemblyscript lib/fixCaptionTrack.ts -b fixers.wasm --use  abort=

Actually, support for imports was recently merged into python-ext-wasm, so we could actually provide that import now.

@koenvo
Copy link
Author

koenvo commented May 2, 2020

That's great! thanks a lot.

I saw it was merged :-) I would like to install python-ext-wasm using pip instead of building it from source.

[edit]
I see it's also in the tests.. doh
[/edit]

@koenvo
Copy link
Author

koenvo commented May 3, 2020

I still get an error when I specify --use abort=:

koen$ cat /tmp/main.ts 
export function helloworld(s: string): string {
        return "foo:" + s
}
koen$ npx assemblyscript /tmp/main.ts -b --use abort= > /tmp/output.wasm
npx: installed 3 in 4.285s
ERROR: AssertionError: assertion failed
    at t.assert (/Users/koen/.npm/_npx/27619/lib/node_modules/assemblyscript/dist/assemblyscript.js:7:576726)
    at g.initialize (/Users/koen/.npm/_npx/27619/lib/node_modules/assemblyscript/dist/assemblyscript.js:7:44520)
    at Object.t.initializeProgram (/Users/koen/.npm/_npx/27619/lib/node_modules/assemblyscript/dist/assemblyscript.js:7:594197)
    at stats.compileTime.measure (/Users/koen/.npm/_npx/27619/lib/node_modules/assemblyscript/cli/asc.js:595:22)
    at measure (/Users/koen/.npm/_npx/27619/lib/node_modules/assemblyscript/cli/asc.js:1103:3)
    at Object.main (/Users/koen/.npm/_npx/27619/lib/node_modules/assemblyscript/cli/asc.js:594:26)
    at asc.ready.then (/Users/koen/.npm/_npx/27619/lib/node_modules/assemblyscript/bin/asc:21:47)
    at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:52:5)
    at Function.Module.runMain (internal/modules/cjs/loader.js:880:11)
    at findNodeScript.then.existing (/Users/koen/.nvm/versions/node/v11.15.0/lib/node_modules/npm/node_modules/libnpx/index.js:268:14)
koen$ npx assemblyscript -v
Version 0.9.4

@miracle2k
Copy link
Owner

miracle2k commented May 3, 2020

Hm - I think you have to open a ticket with AssemblyScript here, seems like a bug on their side. I've run into assertion errors myself, though this seems like to easy a function to cause them.

Note that overriding the abort function is documented and should be officially supported.

@koenvo
Copy link
Author

koenvo commented May 3, 2020

You are right. Found the issue on their side:
AssemblyScript/assemblyscript#1176 (and PR: AssemblyScript/assemblyscript#1177 )

This works:

koen$ npx [email protected] /tmp/main.ts -b --use abort= > /tmp/output.wasm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants