supranational / blst

Multilingual BLS12-381 signature library
Apache License 2.0
471 stars 177 forks source link

build.sh: better support for use with emscripten #121

Closed bryanchriswhite closed 2 years ago

bryanchriswhite commented 2 years ago

Rationale

I've wired up bindings to this library using emscripten. In the course of doing so, I found that I needed more flexibility from the build script than was available. This is the minimal set of changes I had to make to be able to build a WebAssembly module using emscripten.

Changes

dot-asm commented 2 years ago

I've wired up bindings to this library using emscripten

Cool stuff! Great in fact! However, as for the suggested modification, no:-( build.sh is about bridging blst as a library[!] with other build systems, and I see no reason to take it any further. As for building emscripten module, I'd argue that you make it unnecessarily complicated for yourself. You know everything there is to know about your compiler environment and don't need to rely on heuristics (similar to ones that build.sh might provide). To be more specific, there is nothing preventing you from simply calling emcc -O youfile.cpp -I.../blst/bindings .../blst/src/server.c ... with a universally predictable outcome. It's ultimately transparent, simpler and hence more reliable (because of the smaller amount of moving parts:-). If you think that build.sh might provide some hidden knowledge about which files need to be compiled on blst behalf, note that Rust and Go bindings don't rely on the build.sh and simply compile server.c. In other words you'll be in a good company by going for the suggested straightforward command line:-)

I hope you don't mind if I ask some questions and comment on the referred #63. The goal would be to gather some understanding of the platform and corresponding challenges. Maybe there is something that would be appropriate to do slightly differently in the blst.hpp...

Just in case for reference, on a potentially related note. Github actions exercise Rust test suite through wasmtime. Unfortunately I've failed to make the Rust test suite work in a browser, but managed to put together a trivial sign-n-verify snippet.

dot-asm commented 2 years ago

note that Rust and Go bindings don't rely on the build.sh and simply compile server.c.

And so does node.js/binding.gyp. Bottom line is that we are committed to having just one .c file to compile.

bryanchriswhite commented 2 years ago

Thanks for the compliment! :blush: and for explaining so thoroughly!

I'd argue that you make it unnecessarily complicated for yourself.

Yup :joy:. Getting emcc builds to work with build.sh happened pretty early on in my experimentation and I just never looked back. Now that you've dispelled any magic that I thought might be going on in there, I'm happy to close this and move the building step into the other repo!

I hope you don't mind if I ask some questions and comment on the referred https://github.com/ChainSafe/blst-ts/pull/63.

Yes please! I appreciate the engagement, thoughtful questions and insights. So, thanks again :smile: