Stream: git-wasmtime

Topic: wasmtime / Issue #2438 [CLI] How to link multiple wasm's ...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 21 2020 at 18:02):

Horki opened Issue #2438:

Example 1
I have written a gcd unit tests into gcd.wast

(module
  ;; Do I need this header?
  (import "gcd" "gcd" (func $gcd (param i32) (param i32) (result i32)))
)

(assert_return (invoke "gcd" (i32.const 27) (i32.const 6)) (i32.const 3))
(assert_return (invoke "gcd" (i32.const 6) (i32.const 27)) (i32.const 3))

And I want to run wast file from CLI, with importing wat file.

wasmtime --import gcd.wat wast gcd.wast

Example 2
Linking example

How can I do this?
wasmtime --import examples/linking2.wat run examples/linking1.wat

view this post on Zulip Wasmtime GitHub notifications bot (Nov 23 2020 at 15:44):

alexcrichton commented on Issue #2438:

I think you might be looking for the --preload CLI option? That allows loading modules under specific names I think for this use case

view this post on Zulip Wasmtime GitHub notifications bot (Nov 23 2020 at 17:55):

Horki commented on Issue #2438:

Hi @alexcrichton , --preload currently only works with run command, but it's missing in wast command

Meaning example2 is working;

# Example 2 ! Works
$ wasmtime run --preload linking2=examples/linking2.wat examples/linking1.wat --invoke run

# Not working for wast command
$ wasmtime wast --preload gcd=examples/gcd.wat gcd.wast
> Found argument '--preload' which wasn't expected, or isn't valid in this context

What would be the proper way to preload while using wast for unit testing?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 23 2020 at 18:15):

Horki edited a comment on Issue #2438:

Hi @alexcrichton , --preload currently only works with run command, but it's missing in wast command

Meaning example2 is working;

# Example 2 ! Works
$ wasmtime run --preload linking2=examples/linking2.wat examples/linking1.wat --invoke run

# Not working for wast command
$ wasmtime wast --preload gcd=examples/gcd.wat gcd.wast
> Found argument '--preload' which wasn't expected, or isn't valid in this context

What would be the proper way to preload while using wast for unit testing?

EDIT:
I know I could do a manual hack, and add field preload here, but that would be VERY WRONG IMGO

https://github.com/bytecodealliance/wasmtime/blob/ac0ee271b16891883d0e6d40697bc0885f66c058/src/commands/wast.rs#L17-L24

view this post on Zulip Wasmtime GitHub notifications bot (Nov 23 2020 at 18:15):

Horki edited a comment on Issue #2438:

Hi @alexcrichton , --preload currently only works with run command, but it's missing in wast command

Meaning example2 is working;

# Example 2 ! Works
$ wasmtime run --preload linking2=examples/linking2.wat examples/linking1.wat --invoke run

# Not working for wast command
$ wasmtime wast --preload gcd=examples/gcd.wat gcd.wast
> Found argument '--preload' which wasn't expected, or isn't valid in this context

What would be the proper way to preload while using wast for unit testing?

EDIT:
I know I could do a manual hack, and add field preload here, but that would be VERY WRONG IMHO

https://github.com/bytecodealliance/wasmtime/blob/ac0ee271b16891883d0e6d40697bc0885f66c058/src/commands/wast.rs#L17-L24

view this post on Zulip Wasmtime GitHub notifications bot (Nov 23 2020 at 18:21):

alexcrichton commented on Issue #2438:

Ah sorry I missed that! I believe that the wast command doesn't have support for this yet but it probably wouldn't be too hard to do so!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 23 2020 at 21:30):

Horki commented on Issue #2438:

@alexcrichton

Ok, I've got it, no need for preload in my case

gcd.wast

(assert_return (invoke "gcd" (i32.const 27) (i32.const 6)) (i32.const 3))
(assert_return (invoke "gcd" (i32.const 6) (i32.const 27)) (i32.const 3))
# This will run
$ wasmtime wast examples/gcd.wat gcd.wast

As in https://github.com/bytecodealliance/wasmtime/blob/ac0ee271b16891883d0e6d40697bc0885f66c058/src/commands/wast.rs#L44-L48

view this post on Zulip Wasmtime GitHub notifications bot (Nov 23 2020 at 21:30):

Horki closed Issue #2438:

Example 1
I have written a gcd unit tests into gcd.wast

(module
  ;; Do I need this header?
  (import "gcd" "gcd" (func $gcd (param i32) (param i32) (result i32)))
)

(assert_return (invoke "gcd" (i32.const 27) (i32.const 6)) (i32.const 3))
(assert_return (invoke "gcd" (i32.const 6) (i32.const 27)) (i32.const 3))

And I want to run wast file from CLI, with importing wat file.

wasmtime --import gcd.wat wast gcd.wast

Example 2
Linking example

How can I do this?
wasmtime --import examples/linking2.wat run examples/linking1.wat


Last updated: Nov 22 2024 at 16:03 UTC