guest271314 opened issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/xubuntu/localscripts/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmI then used wasm2wat to try to run the module that way, first testing with hello demo
#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not a comment and .py file.Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement.
guest271314 edited issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/user/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmI then used wasm2wat to try to run the module that way, first testing with hello demo
#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not a comment and .py file.Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement.
guest271314 edited issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/user/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmand
$ wasmtime compile nm_c.wasm#!/usr/bin/env wasmtime nm_c.cwasmI then used wasm2wat to try to run the module that way, first testing with hello demo
#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not a comment and .py file.Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement.
guest271314 edited issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/user/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmand
$ wasmtime compile nm_c.wasm#!/usr/bin/env wasmtime nm_c.cwasmI then used wasm2wat to try to run the module that way, first testing with hello demo
#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not a comment and .py file. I use shebang line in QuickJS, Deno, Bun, Node.js - and Python Native Messaging hosts.Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement.
guest271314 edited issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/user/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmand
$ wasmtime compile nm_c.wasm#!/usr/bin/env wasmtime nm_c.cwasmI then used wasm2wat to try to run the module that way, first testing with hello demo
#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not the beginning of a comment in JavaScript and .py file. I use shebang line in QuickJS, Deno, Bun, Node.js - and Python Native Messaging hosts.Why can't wastime recognize that we intend to execute the code below the shebang line and not self-execute the same file starting at the beginning of the script - just skip to the next line then execute the script body?
Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement.
guest271314 edited issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/user/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmand
$ wasmtime compile nm_c.wasm#!/usr/bin/env wasmtime nm_c.cwasmI then used wasm2wat to try to run the module that way, first testing with hello demo
#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )$ ./demo Error: failed to run main module `./demo` Caused by: 0: if you're trying to run a precompiled module, pass --allow-precompiled 1: expected `(` --> ./demo:1:1 | 1 | #!/usr/bin/env wasmtime | ^and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not the beginning of a comment in JavaScript and .py file. I use shebang line in QuickJS, Deno, Bun, Node.js - and Python Native Messaging hosts.Why can't wastime recognize that we intend to execute the code below the shebang line and not self-execute the same file starting at the beginning of the script - just skip to the next line then execute the script body?
Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement.
guest271314 edited issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host https://github.com/guest271314/native-messaging-c to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/user/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmand
$ wasmtime compile nm_c.wasm#!/usr/bin/env wasmtime nm_c.cwasmI then used wasm2wat to try to run the module that way, first testing with hello demo
#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )$ ./demo Error: failed to run main module `./demo` Caused by: 0: if you're trying to run a precompiled module, pass --allow-precompiled 1: expected `(` --> ./demo:1:1 | 1 | #!/usr/bin/env wasmtime | ^and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not the beginning of a comment in JavaScript and .py file. I use shebang line in QuickJS, Deno, Bun, Node.js - and Python Native Messaging hosts.Why can't wastime recognize that we intend to execute the code below the shebang line and not self-execute the same file starting at the beginning of the script - just skip to the next line then execute the script body?
Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement.
guest271314 edited issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host https://github.com/guest271314/native-messaging-c to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/user/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmand
$ wasmtime compile nm_c.wasm#!/usr/bin/env wasmtime nm_c.cwasmI then used wasm2wat to try to run the module that way, first testing with hello demo
#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )$ ./demo Error: failed to run main module `./demo` Caused by: 0: if you're trying to run a precompiled module, pass --allow-precompiled 1: expected `(` --> ./demo:1:1 | 1 | #!/usr/bin/env wasmtime | ^and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not the beginning of a comment in JavaScript - and Python .py file. I use shebang line in QuickJS, Deno, Bun, Node.js - and Python Native Messaging hosts.Why can't
wasmtimehave the option to recognize that we intend to execute the code below the shebang line and not self-execute the same file starting at the beginning of the script - just skip to the next line then execute the script body?Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement.
guest271314 edited issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host https://github.com/guest271314/native-messaging-c to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/user/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmand
$ wasmtime compile nm_c.wasm#!/usr/bin/env wasmtime nm_c.cwasmI then used wasm2wat to try to run the module that way, first testing with hello demo
#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )$ ./demo Error: failed to run main module `./demo` Caused by: 0: if you're trying to run a precompiled module, pass --allow-precompiled 1: expected `(` --> ./demo:1:1 | 1 | #!/usr/bin/env wasmtime | ^and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not the beginning of a comment in JavaScript - and Python .py file. I use shebang line in QuickJS, Deno, Bun, Node.js - and Python Native Messaging hosts.Why can't
wasmtimehave the option to recognize that we intend to execute the code below the shebang line and not self-execute the same file starting at the beginning of the script - just skip to the next line then execute the script body?Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement. Thanks.
guest271314 edited issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host https://github.com/guest271314/native-messaging-c to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/user/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmand
$ wasmtime compile nm_wasm.wasm#!/usr/bin/env wasmtime nm_wasm.cwasmI then used wasm2wat to try to run the module that way, first testing with hello demo
#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )$ ./demo Error: failed to run main module `./demo` Caused by: 0: if you're trying to run a precompiled module, pass --allow-precompiled 1: expected `(` --> ./demo:1:1 | 1 | #!/usr/bin/env wasmtime | ^and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not the beginning of a comment in JavaScript - and Python .py file. I use shebang line in QuickJS, Deno, Bun, Node.js - and Python Native Messaging hosts.Why can't
wasmtimehave the option to recognize that we intend to execute the code below the shebang line and not self-execute the same file starting at the beginning of the script - just skip to the next line then execute the script body?Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement. Thanks.
guest271314 edited issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host https://github.com/guest271314/native-messaging-c to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/user/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmand
$ wasmtime compile nm_wasm.wasm#!/usr/bin/env -S wasmtime nm_wasm.cwasmI then used wasm2wat to try to run the module that way, first testing with hello demo
#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )$ ./demo Error: failed to run main module `./demo` Caused by: 0: if you're trying to run a precompiled module, pass --allow-precompiled 1: expected `(` --> ./demo:1:1 | 1 | #!/usr/bin/env wasmtime | ^and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not the beginning of a comment in JavaScript - and Python .py file. I use shebang line in QuickJS, Deno, Bun, Node.js - and Python Native Messaging hosts.Why can't
wasmtimehave the option to recognize that we intend to execute the code below the shebang line and not self-execute the same file starting at the beginning of the script - just skip to the next line then execute the script body?Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement. Thanks.
guest271314 edited issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host https://github.com/guest271314/native-messaging-c to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/user/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmand
$ wasmtime compile nm_wasm.wasm#!/usr/bin/env -S wasmtime nm_wasm.cwasmI then used
wasm2watto try to run the module that way, first testing with hello demo#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )$ ./demo Error: failed to run main module `./demo` Caused by: 0: if you're trying to run a precompiled module, pass --allow-precompiled 1: expected `(` --> ./demo:1:1 | 1 | #!/usr/bin/env wasmtime | ^and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not the beginning of a comment in JavaScript - and Python .py file. I use shebang line in QuickJS, Deno, Bun, Node.js - and Python Native Messaging hosts.Why can't
wasmtimehave the option to recognize that we intend to execute the code below the shebang line and not self-execute the same file starting at the beginning of the script - just skip to the next line then execute the script body?Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement. Thanks.
guest271314 commented on issue #5614:
@tschneidereit Should I go ahead and close this issue?
tschneidereit commented on issue #5614:
@guest271314 if you think that shebang support is the only way to achieve your desired outcome here, then that might make sense. I don't have the bandwidth to look into the issue enough to know whether that's the case, I'm afraid
guest271314 commented on issue #5614:
W3C banned me so I can't propose anything given your current criteria. I am rather surprised that
wasmtimedoesn't support shebang. I kept searching after you locked the linked issue and found several issues concerning this limitation. I have went through all the hoops to download WASI SDK andwasmtimeand am not limited. I think it makes sense for you folks to figure out a way to solve this internally.
bjorn3 commented on issue #5614:
For reference I'm trying to help them over at https://github.com/guest271314/native-messaging-c/pull/2. Maybe it would make sense to close this issue and if the debugging over at there shows a concrete bug in wasmtime or a fetaure request that is reasonably likely to be accepted, a new issue could be opened focused on just this?
guest271314 commented on issue #5614:
@bjorn3 Sure. I just anticipated 19MB
wasmtimeand the breadth of WASI SDK to handle these cases.
guest271314 closed issue #5614:
I downloaded the WASI SDK and
wasmtime. I then compiled working C Native Messaging host https://github.com/guest271314/native-messaging-c to WASM, with and without--sysrootoption$ /home/user/wasi-sdk-19.0/bin/clang --sysroot=/home/user/wasi-sdk-19.0/share/wasi-sysroot /home/user/native-messaging-c/nm_c.c -o nm_wasm.wasmthen tried
#!/usr/bin/env -S wasmtime run /path/to/nm_wasm.wasmand
$ wasmtime compile nm_wasm.wasm#!/usr/bin/env -S wasmtime nm_wasm.cwasmI then used
wasm2watto try to run the module that way, first testing with hello demo#!/usr/bin/env wasmtime (module ;; Import the required fd_write WASI function which will write the given io vectors to stdout ;; The function signature for fd_write is: ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) ;; Write 'hello world\n' to memory at an offset of 8 bytes ;; Note the trailing newline which is required for the text to appear (data (i32.const 8) "hello world\n") (func $main (export "_start") ;; Creating a new io vector within linear memory (i32.store (i32.const 0) (i32.const 8)) ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string (i32.store (i32.const 4) (i32.const 12)) ;; iov.iov_len - The length of the 'hello world\n' string (call $fd_write (i32.const 1) ;; file_descriptor - 1 for stdout (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0 (i32.const 1) ;; iovs_len - We're printing 1 string stored in an iov - so one. (i32.const 20) ;; nwritten - A place in memory to store the number of bytes written ) drop ;; Discard the number of bytes written from the top of the stack ) )$ ./demo Error: failed to run main module `./demo` Caused by: 0: if you're trying to run a precompiled module, pass --allow-precompiled 1: expected `(` --> ./demo:1:1 | 1 | #!/usr/bin/env wasmtime | ^and after the script exited I searched and located https://github.com/bytecodealliance/wasmtime/issues/3715 then tried
#!/usr/bin/sh wasmtime run /dev/stdin <<__END__ (module (type $t0 (func (param i32 i32 i32) (result i32))) (type $t1 (func (param i32 i64 i32) (result i64))) (type $t2 (func (param i32) (result i32))) (type $t3 (func (param i32 i32) (result i32))) (type $t4 (func (param i32 i32 i32 i32) (result i32))) (type $t5 (func (param i32 i64 i32 i32) (result i32))) (type $t6 (func (param i32))) (type $t7 (func)) (type $t8 (func (result i32))) (import "wasi_snapshot_preview1" "fd_close" (func $__imported_wasi_snapshot_preview1_fd_close (type $t2))) (import "wasi_snapshot_preview1" "fd_fdstat_get" (func $__imported_wasi_snapshot_preview1_fd_fdstat_get (type $t3))) (import "wasi_snapshot_preview1" "fd_read" (func $__imported_wasi_snapshot_preview1_fd_read (type $t4))) (import "wasi_snapshot_preview1" "fd_seek" (func $__imported_wasi_snapshot_preview1_fd_seek (type $t5))) (import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type $t4))) (import "wasi_snapshot_preview1" "proc_exit" (func $__imported_wasi_snapshot_preview1_proc_exit (type $t6))) (func $__wasm_call_ctors (type $t7)) (func $_start (export "_start") (type $t7) ;; ...to no avail. See https://github.com/WebAssembly/wasi-filesystem/discussions/82.
Native Messaging protocol is initiated from the browser. The host reads input from the browser as stdin, stdout from the host is sent to the client browser. See Native messaging protocol; and MDN's Native Messaging.
Notice how we can use shebang line in a .js file where
#is not the beginning of a comment in JavaScript - and Python .py file. I use shebang line in QuickJS, Deno, Bun, Node.js - and Python Native Messaging hosts.Why can't
wasmtimehave the option to recognize that we intend to execute the code below the shebang line and not self-execute the same file starting at the beginning of the script - just skip to the next line then execute the script body?Not sure how to solve this given lack of shebang support and inability to utilize
/usr/bin/envwithSoption.Asking for help to achieve the requirement. Thanks.
guest271314 commented on issue #5614:
@tschneidereit @bjorn3 @JoeStrout
Solved.
I think the install script
curl https://wasmtime.dev/install.sh -sSf | bashsets
wasmtimeinPATHonly for local terminal, not system wide. So when we use something like#!/usr/bin/env -S wasmtime ...
envis not findingwasmtime, e.g.,$ sudo su # wasmtime --help wasmtime: command not foundWe need to use the full path to the
wasmtimeexecutable, e.g.,#!/usr/bin/env bash /home/user/.wasmtime/bin/wasmtime run nm_c.wasm#!/usr/bin/env -S /home/user/.wasmtime/bin/wasmtime run nm_c.wasmor more directly where we write the executable to the directory where we intent to use it
#!/wasmtime/bin/wasmtime run nm_c.wasmFor completeness I also tested using WAT in the shell script using "approach 1" from https://www.reddit.com/r/bash/comments/10i09se/comment/j5blsrw/, again, where I for this test just copied
wasmtimefrom~/.wasmtime/binto the directory I am using the executable in#!/bin/bash script=' (module ;; ... ) ' ./wasmtime <(printf '%s' "$script")
guest271314 edited a comment on issue #5614:
@tschneidereit @bjorn3 @JoeStrout
Solved.
I think the install script
curl https://wasmtime.dev/install.sh -sSf | bashsets
wasmtimeinPATHonly for local terminal, not system wide. So when we use something like#!/usr/bin/env -S wasmtime ...
envis not findingwasmtime, e.g.,$ sudo su # wasmtime --help wasmtime: command not foundWe need to use the full path to the
wasmtimeexecutable, e.g.,#!/usr/bin/env bash /home/user/.wasmtime/bin/wasmtime run nm_c.wasmor more directly where we write the executable to the directory where we intent to use it
#!/usr/bin/env -S ./wasmtime run nm_c.wasmFor completeness I also tested using WAT in the shell script using "approach 1" from https://www.reddit.com/r/bash/comments/10i09se/comment/j5blsrw/, again, where I for this test just copied
wasmtimefrom~/.wasmtime/binto the directory I am using the executable in#!/bin/bash script=' (module ;; ... ) ' ./wasmtime <(printf '%s' "$script")
guest271314 commented on issue #5614:
Note, the Bash process substitution approach does not kill
wasmtimewhrn the Native Messaging host exits.
guest271314 edited a comment on issue #5614:
@tschneidereit @bjorn3 @JoeStrout
Solved.
I think the install script
curl https://wasmtime.dev/install.sh -sSf | bashsets
wasmtimeinPATHonly for local terminal, not system wide. So when we use something like#!/usr/bin/env -S wasmtime ...
envis not findingwasmtime, e.g.,$ sudo su # wasmtime --help wasmtime: command not foundWe need to use the full path to the
wasmtimeexecutable, e.g.,#!/usr/bin/env bash /home/user/.wasmtime/bin/wasmtime run nm_c.wasmor more directly where we write the executable to the directory where we intent to use it
#!wasmtime nm_c.wasmor
#!wasmtime nm_c_wasm.watFor completeness I also tested using WAT in the shell script using "approach 1" from https://www.reddit.com/r/bash/comments/10i09se/comment/j5blsrw/, again, where I for this test just copied
wasmtimefrom~/.wasmtime/binto the directory I am using the executable in#!/bin/bash script=' (module ;; ... ) ' ./wasmtime <(printf '%s' "$script")
guest271314 commented on issue #5614:
The workaround so far for running
wasmtimewith WAT in the same file is using a separate script to terminatewasmtimeexecutable when the Native Messaging host exits#!/bin/bash # https://www.reddit.com/r/bash/comments/10i09se/comment/j5blsrw/ script=' (module ;; ... ) ' ./kill_wasmtime.sh & ./wasmtime <(printf '%s' "$script")#!/bin/bash while pgrep -f nm_c_wat.sh > /dev/null do sleep 1 done killall -9 wasmtime exit 0
guest271314 commented on issue #5614:
@tschneidereit @JoeStrout See https://github.com/WebAssembly/spec/issues/1581
Last updated: Dec 13 2025 at 19:03 UTC