Conversation
Signed-off-by: csking101 <chinmayasahu101@gmail.com>
|
@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 |
|
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 |
|
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-packinstalled. 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.htmlserved by a simple Python server to avoid CORS issues. This can be done by runningpython -m http.serverin the same directory asindex.html.Dissect Packetbutton to see this:My Analysis
./pkg/scalpel.js, created bywasm-pack. I tried loading the./pkg/scalpel_bg.wasmfile 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 theArrayBuffers for containing the WASM binary and following a few more steps, I ended up using thewasm-packgenerated./pkg/scalpel.jsfile. (However, the alternative options of loading and running the WASM binary directly can be explored)dissect_packetfunction to thelib.rsfile temporarily.wasm-packgenerates 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-unknownFurther Resources
wasm-bindgenGuidewasm-pack