Open csking101 opened 5 months ago
@csking101 : This is a great start. Thanks a lot!!
I am wondering whether it's a good idea to actually capture this into a GH discussion. Let's keep the PR open, so that it allows us to iterate, but essential discussions should be captured in discussions (because PRs once closed or merged, those discussions get kind of lost.)
I quickly looked at the cargo test --target wasm32-unknown-unknown
issue. This is because of the errno
dependency, which is due to pcap
dev-dependency (required for examples). So we may have to wrap that into two separate feature
(say wasm
and pcap
). And then do a cargo test
per feature. I will take a shot at this. Is that cool?
Sure sir, that sounds great!
Also, I think we can continue in the discussions about what functions will be WASM supported, as you said, they have can different feature
s for the same. It'll be better to segregate the two at this stage I believe.
Parts of this PR are merged with merge of #66 . Thank you for your contribution.
We can keep this PR open or move some relevant links, information to the Discussions page.
Referencing #61
We had discussed about whether our crate can support WASM. This PR creates a demonstration of the same.
Instructions to run
wasm-pack
installed. It can be found here. Simply runcargo install wasm-pack
. This is used to create the WASM files based on our target (which in this case is the web). It also has the potential to create WASM files for different targets as well such as NodeJS.wasm-pack build --target web
. It will create WASM binaries in./pkg/
.index.html
served by a simple Python server to avoid CORS issues. This can be done by runningpython -m http.server
in the same directory asindex.html
.Dissect Packet
button to see this:My Analysis
./pkg/scalpel.js
, created bywasm-pack
. I tried loading the./pkg/scalpel_bg.wasm
file directly into the script, however, I was facing some import issues. It turns out thatWebAssembly is not yet integrated with <script type='module'> or import statements, thus there is not a path to have the browser fetch modules for you using imports.
as stated in MDN Docs. Therefore, instead of tediously creating theArrayBuffer
s for containing the WASM binary and following a few more steps, I ended up using thewasm-pack
generated./pkg/scalpel.js
file. (However, the alternative options of loading and running the WASM binary directly can be explored)dissect_packet
function to thelib.rs
file temporarily.wasm-pack
generates WASM bindings for particular functions, that have the#[wasm_bindgen]
attribute. They can't be tested from examples. Therefore, we need to look into creating a separate module to provide the functions that can be used by the browser, or any other entity using the WASM file. The functions that can be supported are a point of discussionENCAP_TYPE_ETH
, however in the future functions that are to be written, this must be taken care of.More areas to look into
cargo test --target wasm32-unknown-unknown
Further Resources
wasm-bindgen
Guidewasm-pack