bytecodealliance / preview2-prototyping

Polyfill adapter for preview1-using wasm modules to call preview2 functions.
Other
77 stars 20 forks source link

Fix support for tracing, add --mapdir to host cli #142

Closed pchickey closed 1 year ago

pchickey commented 1 year ago

Use the latest wasmtime, which needed the following to make the tracing: true feature in wasmtime-wit-bindgen actually emit something useful: https://github.com/bytecodealliance/wasmtime/pull/6209

Install the tracing_subscriber in host's main.rs, so that RUST_LOG=host=trace works from the cli. (It already worked in tests, via test_log.)

And finally, implement --mapdir as a command line flag, stolen out of the wasmtime cli. I had to rejigger how preopens are constructed slightly to make this work out.

Sample output:

[phickey@pch-tower:src/preview2-prototyping]% RUST_LOG=host=trace cargo run -p host -- read_empty_filename.component.wasm --mapdir /::tmp
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/host read_empty_filename.component.wasm --mapdir '/::tmp'`
2023-04-14T15:22:21.371311Z TRACE wit-bindgen export{module="default" function="main"}:wit-bindgen import{module="preopens" function="get-stdio"}: host::command::wasi::preopens: call
2023-04-14T15:22:21.371359Z TRACE wit-bindgen export{module="default" function="main"}:wit-bindgen import{module="preopens" function="get-stdio"}: host::command::wasi::preopens: return result=Ok(StdioPreopens { stdin: 0, stdout: 1, stderr: 2 })
2023-04-14T15:22:21.371451Z TRACE wit-bindgen export{module="default" function="main"}:wit-bindgen import{module="preopens" function="get-directories"}: host::command::wasi::preopens: call
2023-04-14T15:22:21.371485Z TRACE wit-bindgen export{module="default" function="main"}:wit-bindgen import{module="preopens" function="get-directories"}: host::command::wasi::preopens: return result=Ok([(3, "/")])
2023-04-14T15:22:21.371620Z TRACE wit-bindgen export{module="default" function="main"}:wit-bindgen import{module="filesystem" function="open-at"}: host::command::wasi::filesystem: call this=3 path_flags=(SYMLINK_FOLLOW) path="." open_flags=() flags=(READ) modes=(READABLE|WRITEABLE)
2023-04-14T15:22:21.371687Z TRACE wit-bindgen export{module="default" function="main"}:wit-bindgen import{module="filesystem" function="open-at"}: host::command::wasi::filesystem: return result=Ok(4)
2023-04-14T15:22:21.371766Z TRACE wit-bindgen export{module="default" function="main"}:wit-bindgen import{module="filesystem" function="stat"}: host::command::wasi::filesystem: call this=4
2023-04-14T15:22:21.371806Z TRACE wit-bindgen export{module="default" function="main"}:wit-bindgen import{module="filesystem" function="stat"}: host::command::wasi::filesystem: return result=Ok(DescriptorStat { device: 64769, inode: 17304241, type: DescriptorType::Directory, link-count: 2, size: 4096, data-access-timestamp: Datetime { seconds: 1681484998, nanoseconds: 564963481 }, data-modification-timestamp: Datetime { seconds: 1681348594, nanoseconds: 577238733 }, status-change-timestamp: Datetime { seconds: 1681348594, nanoseconds: 577238733 } })
2023-04-14T15:22:21.371896Z TRACE wit-bindgen export{module="default" function="main"}:wit-bindgen import{module="filesystem" function="read-via-stream"}: host::command::wasi::filesystem: call this=4 offset=0
2023-04-14T15:22:21.371926Z TRACE wit-bindgen export{module="default" function="main"}:wit-bindgen import{module="filesystem" function="read-via-stream"}: host::command::wasi::filesystem: return result=Ok(5)
pchickey commented 1 year ago

Closes #141