-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making scryer-prolog build successful with wasm32-wasi (discussion only) #1966
Conversation
hi @rujialiu ,
Yes, the |
Sorry for the confusion @mthom. I was simply asking whether my changes are correct :) |
0507f78
to
727b5f2
Compare
Now the code is updated on top of the merged #1972 @triska @lucksus You can build it with
But Anyway, when wasm-pack is finished, there will be a The codes are very preliminary and not meant to be merged, but you can playaround it especially whether it works with your own branch. TODO: Still can't make ring fully work. So I'm making a looooot of mocks. Some functions are available locally after enabling ring's |
@rujialiu: Thank you so much! Regarding |
I have a feeling that it's all my fault, so I'll take a deeper look first :) I'm pushing the codes now because people can play around other things first. |
For reference, I used the following instructions to compile to WASM, executed in the $ git remote add rujialiu https://github.com/rujialiu/scryer-prolog $ git fetch rujialiu $ git checkout -b wasm32-discussion rujialiu/wasm32-discussion $ curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh $ wasm-pack build --target web -- --no-default-features Excepting a few warnings, compilation works smoothly: Finished release [optimized + debuginfo] target(s) in 4m 28s [INFO]: ⬇️ Installing wasm-bindgen... [INFO]: ✨ Done in 4m 52s [INFO]: 📦 Your wasm pkg is ready to publish at ~/scryer-prolog/pkg. Now I launch the http server: $ python -m http.server Then I browse to http://localhost:8000/, and I see (stemming from result: [9,8,7,6,5,4,3,2,1]. [2,4,6,1,7,3,9,8,5]. [3,5,1,9,2,8,7,4,6]. [1,2,8,5,3,7,6,9,4]. [6,3,4,8,9,2,1,5,7]. [7,9,5,4,6,1,8,3,2]. [5,1,9,2,8,6,4,7,3]. [4,7,2,3,1,9,5,6,8]. [8,6,3,7,4,5,2,1,9]. Beautiful! I also have the directory LICENSE README.md package.json scryer_prolog.d.ts scryer_prolog.js scryer_prolog_bg.wasm scryer_prolog_bg.wasm.d.ts |
Interestingly, yesterday I dreamed of someone using scryer-prolog to draw some animated ASCII-art in the browser (probably some game)! Anyway, I hope I can find sometime to finish ring issues this week. And maybe some kind of minimalist top-level that's easier to port to wasm (rustyline+crossterm is no easy to port)? I don't know how hard to write another one, or just to use Then you can embed the wasm with the minimal top-level in the pages of |
It looks like ring's wasm32 support is incomplete: briansmith/ring#918 |
I took some time to learn a bit of crypto, and it seems that all things you got from Another way is to first identify exactly which features are not supported in |
The cryptographic functionality from
I have used All these functions have corresponding definitions in For your WASM port, I think it would be best to simply (automatically) remove unsupported functionality at compilation time. As the need arises, I will try to find suitable crates for replacement. I did consider other crates too when I implemented the cryptographic functionality, but found them less suitable at the time I wrote these functions. The situation may well have changed now, and we may be able to more easily use other crates now that have since become available. A good example for this is the |
Unfortunatelly, after commenting out the 6 functions you mentioned, the resulting wasm has still missing functions related to x25519, but maybe they are just referenced, not actually used. In that case, mocking these functions should be ok. So could you please write a few prolog tests that I can run in browsers (can easily check manually) to check whether each of these 12 functions are working or not? @triska |
If any of these functions yields warnings or does not compile for the WASM port, please simply remove it by "cfg"-ing it away for the port in its entirety. All cryptographic Rust functions appear in one contiguous block in scryer-prolog/src/machine/system_calls.rs Line 6888 in 66f6399
and ending here: scryer-prolog/src/machine/system_calls.rs Line 7360 in 66f6399
You can "cfg"-away the entire region, and then can also remove the scryer-prolog/src/machine/system_calls.rs Line 73 in 66f6399
I will incrementally add these functions back as needed, when I find suitable crates that work with WASM. |
I made some mistake. Actually exactly the set of striked out functions work in WASM :) Should I make a separate PR with just those changes (and some wasm32 related changes that won't break anything) because currently this PR is breaking non-wasm builds (defaults to no optional features) and contains some extra codes ( But one problem: I don't know how to throw |
@rujialiu: If you (via "cfg"-directives) remove all functions and corresponding dispatch entries that currently do not work with WASM, and also remove (via "cfg") all corresponding entries in scryer-prolog/build/instructions_template.rs Line 499 in 66f6399
and: scryer-prolog/build/instructions_template.rs Line 1831 in 66f6399
then everything should work as expected: An existence error will be thrown automatically if these (internal) predicates are not defined. You do not have to add any code, only remove (via "cfg") those parts that do not compile with WASM. The cryptographic functionality always occurs contiguously in one block everywhere it occurs in the Rust files, i.e., in Yes, please do file pull requests at any time for everything that can be merged immediately without causing regressions for the regular 64-bit target! In this way, other contributors who are now also working on the code can already incorporate the changes you know will be eventually necessary for the WASM port, and it will also simplify the remaining changes and make them easier to review and discuss. Thank you a lot! |
PR issued. What next? :) @triska |
Very impressive, thank you a lot! Next, I hope you are already preparing an awesome announcement and explanation of this new feature (explaining what it is, how it can be enabled, instructions for compilation, screenshot of an example etc.) and post it to the Scryer discussions as soon as the PR is merged! This will attract more interested application programmers to your contribution! |
Yes! :)
|
Intended to make discussions in #615 easier.