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
feat: add browser support (ECO-967) (ECO-1240) #1
Conversation
a2129b2
to
5760a3c
Compare
Hey @bryanchriswhite ! Super curious about this PR, are you able to run blst JS bindings in the browser? If so, what's your strategy? |
@dapplion the plan is to use webidl in conjunction with emscripten to generate web assembly bindings. At the moment, I seem to have massaged the generated binding code to the point where it's building the WASM module and supporting JS. Now I'm setting up webpack to integrate this with blst-ts in place of the native node module to get to the point where I can get the blst-ts tests passing in the browser. 😄 (The blst submodule draft changes are in fetchai/blst#1) |
5760a3c
to
66942d7
Compare
66942d7
to
9f73dcf
Compare
That's amazing! It would be down to help you upstream the browser support if you want. supranational has been very receptive in the past for modifications in the source to support bindings. What's the scope of the changes in blst C side? |
9f73dcf
to
1200fbf
Compare
@dapplion thanks, that's great to hear! 😄 So far the changes in blst are to include the generated WebIDL binding C++ source in the build script along with any I would love to hear your thoughts on how to structure things best so that browser / web assembly support can coexist upstream! |
@bryanchriswhite Once you got something stable and working I would upstream the changes in the blst repo. Keep modifications minimal and add the new bindings into their own folder along with the absolute minimal CI that ensures it works and shows how to integrate downstream. Then we can discuss in that PR with supranational if they prefer different structures. |
c16f9d8
to
927537c
Compare
fc78248
to
a161ecc
Compare
a161ecc
to
3ebe628
Compare
3ebe628
to
faf676e
Compare
Hey @dapplion! I did my best to setup karma but it looks like the tests aren't run unless you I've added a build script that uses docker, which seemed like the only sane option to me. I'm thinking that it will make sense to include the in-lined wasm binary in the npm release so that consumers don't need to build it. As you may have noticed, I turned on actions for the fork but have not added anything to the workflow yet. The only changes I've made to the actions were to update paths to things that I moved. The benchmark is failing because of the missing members (see PR description); I removed them from the |
Amazing progress! How big in the target bin size? Inlining and bundling into the release is the right path IMO. |
Thanks! 😄 The last build of the in-line JS I did was ~282kB. The original wasm was ~212 kB. |
e6e7ba7
to
9bb16f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some suggestions for the C++ and the new stuff
Co-authored-by: Ed Fitzgerald <edward.fitzgerald@fetch.ai>
Thanks @ejfitzgerald, that eliminates all |
@dapplion, any idea why the ARM jobs take soooo long, is that normal? |
Status
Browser-applicable tests are passing (i.e.
unit/bindings/*
andunit/lib/index.test.ts
). I assume that a web worker based analogue of theworker_thread
could be constructed, this is out of scope for my immediate needs.I also have this module linked locally (
yarn link
, etc.) in another project which is able to bundle it (once built) like a regular dependency. Once a release is cut which includes the emscripten binding, consumers should only have toyarn add
it and ensure their webpack config is compatible. See README -> using emscripten bindings for more.Missing Members
Some global members are still missing from the emscripten binding (as I haven't figured out how to bind them yet):
BLS12_381_G1
BLS12_381_NEG_G1
BLS12_381_G2
BLS12_381_NEG_G2
Changes
pre.js
,post.js
, andwebpack.config.js
to eslint ignore patternsbundle.js
,blst.wasm
, andblst.wasm.js
to gitignoreprebuild/*
toprebuild/swig/*
prebuild/emscripten
directoryinline:wasm
- serializes wasm binary to base64 encoded JS, exported as an arrray buffertest:browser
- runs browser-compatible testswebpack
webpack-cli
webpack-dev-server
ts-loader
path-browserify
stream-browserify
crypto-browserify
buffer
assert-browserify
run
functions to wait for the emscripten runtime to be ready, if presentDependencies