dunnock / wasi-worker

WASM / WASI interface for browser service workers
MIT License
56 stars 3 forks source link

wasi_unstable VS wasi_snapshot_preview1? #4

Closed cheako closed 4 years ago

cheako commented 4 years ago

https://cheako.gitlab.io/-/websuite-rs/-/jobs/428990295/artifacts/public/notes/index.html Essentially empty. https://gitlab.com/cheako/websuite-rs/-/tree/d97bce33168fb18bb155bde9e99a7ba734f9424b

dunnock commented 4 years ago

Thanks for report, I know what the issue it will fix it shortly

dunnock commented 4 years ago

@cheako so this was caused by incompatible change introduced with rustc 1.41, WASM import object was renamed from wasi_unstable to wasi_snapshot_preview1. I have pushed fix with wasi-worker:0.5 and wasi-worker-cli:0.5 . Can you please confirm it works for you now.

One more change it introduces is you do not need to implement boilerplate function message_ready(), please remove it from your code otherwise compilation will fail:

pub extern "C" fn message_ready() -> usize {
    ServiceWorker::on_message().expect("ServiceWorker.on_message")
}
cheako commented 4 years ago

Edit: Sorry, I was still doing some wierd sed thing. I'm trying without that.

TypeError: WebAssembly.instantiate(): Import #1 module="__wbindgen_placeholder__" error: module is not an object or function

https://gitlab.com/cheako/websuite-rs/-/jobs/429810737 https://cheako.gitlab.io/-/websuite-rs/-/jobs/429810737/artifacts/public/notes/index.html

srv_websuite@olympus:~/src/websuite$ git diff ae36d7b1e6610fa9c5501bcd66884b977530460f | cat
diff --git a/notes/Cargo.toml b/notes/Cargo.toml
index c8d2b6a..aacfe41 100644
--- a/notes/Cargo.toml
+++ b/notes/Cargo.toml
@@ -16,7 +16,7 @@ default = [
 js-sys = '0.3'
 # rand = '0.7'
 wasm-bindgen = '0.2'
-wasi-worker = "0.4"
+wasi-worker = "0.5"
 # num = '0.2'

 # [dependencies.getrandom]
@@ -58,8 +58,8 @@ features = [
     'Window',
 ]

-[dev-dependencies]
-wasm-bindgen-test = '0.2'
+# [dev-dependencies]
+# wasm-bindgen-test = '0.3'
 [profile.release]
 opt-level = 's'

diff --git a/notes/src/bin/worker.rs b/notes/src/bin/worker.rs
index d72ff2e..44c560b 100644
--- a/notes/src/bin/worker.rs
+++ b/notes/src/bin/worker.rs
@@ -44,11 +44,3 @@ fn main() {
      * ```
      */
 }
-
-// this function will be called from worker.js when it receives message
-// In the future it will be substituted by poll_oneoff or thread::yield,
-// though currently poll_oneoff does not return control to browser
-#[no_mangle]
-pub extern "C" fn message_ready() -> usize {
-    ServiceWorker::on_message().expect("ServiceWorker.on_message")
-}
diff --git a/Cargo.lock b/Cargo.lock
index 91f6843..661f575 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -28,12 +28,6 @@ dependencies = [
  "wasm-bindgen",
 ]

-[[package]]
-name = "futures"
-version = "0.1.29"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef"
-
 [[package]]
 name = "heck"
 version = "0.3.1"
@@ -95,31 +89,13 @@ dependencies = [
  "version_check",
 ]

-[[package]]
-name = "proc-macro2"
-version = "0.4.30"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
-dependencies = [
- "unicode-xid 0.1.0",
-]
-
 [[package]]
 name = "proc-macro2"
 version = "1.0.8"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548"
 dependencies = [
- "unicode-xid 0.2.0",
-]
-
-[[package]]
-name = "quote"
-version = "0.6.13"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
-dependencies = [
- "proc-macro2 0.4.30",
+ "unicode-xid",
 ]

 [[package]]
@@ -128,15 +104,9 @@ version = "1.0.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
 dependencies = [
- "proc-macro2 1.0.8",
+ "proc-macro2",
 ]

-[[package]]
-name = "scoped-tls"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
-
 [[package]]
 name = "sourcefile"
 version = "0.1.4"
@@ -149,9 +119,9 @@ version = "1.0.14"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5"
 dependencies = [
- "proc-macro2 1.0.8",
- "quote 1.0.2",
- "unicode-xid 0.2.0",
+ "proc-macro2",
+ "quote",
+ "unicode-xid",
 ]

 [[package]]
@@ -160,12 +130,6 @@ version = "1.6.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"

-[[package]]
-name = "unicode-xid"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
-
 [[package]]
 name = "unicode-xid"
 version = "0.2.0"
@@ -180,9 +144,9 @@ checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"

 [[package]]
 name = "wasi-worker"
-version = "0.4.0"
+version = "0.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "da7127b7fa0787a553d008695b74d36c23a433e75841884611a66914a7e074d6"
+checksum = "92ef3a20b6283b2d189bb7d50f622545926e832f8b37c4d7ff640fc03a9ba214"

 [[package]]
 name = "wasm-bindgen"
@@ -203,32 +167,19 @@ dependencies = [
  "bumpalo",
  "lazy_static",
  "log",
- "proc-macro2 1.0.8",
- "quote 1.0.2",
+ "proc-macro2",
+ "quote",
  "syn",
  "wasm-bindgen-shared",
 ]

-[[package]]
-name = "wasm-bindgen-futures"
-version = "0.3.27"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c"
-dependencies = [
- "cfg-if",
- "futures",
- "js-sys",
- "wasm-bindgen",
- "web-sys",
-]
-
 [[package]]
 name = "wasm-bindgen-macro"
 version = "0.2.58"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "574094772ce6921576fb6f2e3f7497b8a76273b6db092be18fc48a082de09dc3"
 dependencies = [
- "quote 1.0.2",
+ "quote",
  "wasm-bindgen-macro-support",
 ]

@@ -238,8 +189,8 @@ version = "0.2.58"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "e85031354f25eaebe78bb7db1c3d86140312a911a106b2e29f9cc440ce3e7668"
 dependencies = [
- "proc-macro2 1.0.8",
- "quote 1.0.2",
+ "proc-macro2",
+ "quote",
  "syn",
  "wasm-bindgen-backend",
  "wasm-bindgen-shared",
@@ -251,31 +202,6 @@ version = "0.2.58"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f5e7e61fc929f4c0dddb748b102ebf9f632e2b8d739f2016542b4de2965a9601"

-[[package]]
-name = "wasm-bindgen-test"
-version = "0.2.50"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a2d9693b63a742d481c7f80587e057920e568317b2806988c59cd71618bc26c1"
-dependencies = [
- "console_error_panic_hook",
- "futures",
- "js-sys",
- "scoped-tls",
- "wasm-bindgen",
- "wasm-bindgen-futures",
- "wasm-bindgen-test-macro",
-]
-
-[[package]]
-name = "wasm-bindgen-test-macro"
-version = "0.2.50"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0789dac148a8840bbcf9efe13905463b733fa96543bfbf263790535c11af7ba5"
-dependencies = [
- "proc-macro2 0.4.30",
- "quote 0.6.13",
-]
-
 [[package]]
 name = "wasm-bindgen-webidl"
 version = "0.2.58"
@@ -285,8 +211,8 @@ dependencies = [
  "anyhow",
  "heck",
  "log",
- "proc-macro2 1.0.8",
- "quote 1.0.2",
+ "proc-macro2",
+ "quote",
  "syn",
  "wasm-bindgen-backend",
  "weedle",
@@ -313,7 +239,6 @@ dependencies = [
  "js-sys",
  "wasi-worker",
  "wasm-bindgen",
- "wasm-bindgen-test",
  "web-sys",
  "wee_alloc",
 ]
dunnock commented 4 years ago

It seems you compile worker with wasm-bindgen, can you try to conditionally switch it off so it does not pollute its wasm imports like it's done here: https://github.com/yewstack/yew/blob/master/Cargo.toml#L41

cheako commented 4 years ago

Not so much. https://gitlab.com/cheako/websuite-rs/-/jobs/429936890 https://cheako.gitlab.io/-/websuite-rs/-/jobs/429936890/artifacts/public/notes/index.html TypeError: WebAssembly.instantiate(): Import #0 module="wasi_snapshot_preview1" error: module is not an object or function

Still emitting only wasi_unstable

dunnock commented 4 years ago

@cheako I have tried to compile your code, it appears you are using console_error_panic_hook which is based on wasm_bindgen. Try to compile with:

[features]
default = [
    'wee_alloc',
]
console_panic = [ ]

[target.'cfg(all(feature = "console_panic", target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.console_error_panic_hook]
version = '0.1.6'
optional = true

To output to console from a worker you can just use println!(), for instance from a panic hook.

dunnock commented 4 years ago

One more note - it seems your build script has cached old version of wasi-worker-cli, so it still produces worker.js which has the old wasi_unstable imports:

'[ "$(type -p -t wasiworker)" == "file" ] || cargo install wasi-worker-cli'
cheako commented 4 years ago

cargo update doesn't update applications, cargo install seems to but complains if there is nothing to update? cargo install wasi-worker-cli || [ "$(type -p -t wasiworker)" == "file" ]??

dunnock commented 4 years ago

cargo install wasi-worker-cli --force updates already installed app

dunnock commented 4 years ago

Actually it should been without force:

If the package is already installed, Cargo will reinstall it if the installed version does not appear to be up-to-date.

dunnock commented 4 years ago

Yeah, actually your last build worked for me

Screenshot 2020-02-07 at 23 14 53
cheako commented 4 years ago

Yeah, I got that too. :) It's when installed in the cache that installing returns an error. We don't want to force install because that negates the cache. So as a compromise, for there not being a feature to update, I'm installing and on failure testing if there is an installed version.