Closed dmalkr closed 4 years ago
Nix build is partially complete. So far problem is closurecompiler fails with:
/tmp/tmpAkGIfe.cl.js:7461: ERROR - This language feature is only supported for ECMASCRIPT6 mode or better: block-scoped function declaration.
function doBrowserLoad() {
^
/tmp/tmpAkGIfe.cl.js:7468: ERROR - This language feature is only supported for ECMASCRIPT6 mode or better: block-scoped function declaration.
function useRequest() {
Relevant issues:
To be more exact. 1.37.36 (from snapshot used by hschain atm) gives error above, while 1.38.28 gives different and completely inscrutable error
Overview
Here are Haskell bindings for GHCJS for using
bls-signatures
.To use this bindings, we need to compile
bls-signatures
for JavaScript environment. As a result, we get two files:blsjs.wasm
-- WASM module ofbls-signatures
, andbundle.js
-- JavaScript bindings forbls-signatures
and all its dependencies. It is need to load both of this files before usebls-signatures
in GHCjs-compiled haskell modules.Current structure of bls-signatures support
./bls-signatures
-- submodule with "raw API". It abstractsbls-signatures
C++ package from other Haskell code. So developer can just addbls-signatures
dependency and don't worry about native/JavaScript environment../bls-signatures/bls-signatures.cabal
-- this cabal file contains instructions to configure import C++/JavaScript modules and GHC/GHCJS packages./bls-signatures/src/Bls/CPP/*
-- native support forbls-signaturs
./bls-signatures/src/Bls/JavaScript/*
-- JavaScript support forbls-signaturs
./bls-signatures/src/Bls.hs
-- file which exports necessary parts of this submodule depends on compile environment./hschain-crypto-bls
-- submodule with high-levelhschain
-compatable API.Using WASM/JS-modules
At first, we need to load
bundle.js
(see building instuctions below). For example, we can load it in<head>
section ofindex.html
file:Then in Haskell files we need to call
initBls
function before usingbls-signatures
. This call load upblsjs.wasm
and setup bls-signatures environment.See example of main unittest file:
Building instructions
Building WASM image for
bls-signatures
At first, it is need to build WASM image for
bls-signatures
. But only once! After image is ready it is not necessary to constanly rebuild them.We need fresh
bls-signatures
copy of repo. So let's clone and cd to it and update submodules:Next we need installed Emscripted C++ (https://emscripten.org/) to build from C++ to WASM. I prefer to use Docker image
wasm/toolchain
which contains everything we need to build. So we download image and enter into it:That docker image contain Emscripted C++ but outdated Node JS (which also need to build). So let's install fresh NodeJS in Docker session:
bls-signatures
repo contains file./js_build.sh
for simply build. But it contains error, so let's repeat correct commands by yourself:Now main part of BLS-Signatures is compiled:
./js_build/js-bindings/blsjs.wasm
and./js_build/js-bindings/blsjs.wasm
. Now we need to pack all dependencies into one NodeJS package:Result
Now we have two files:
./js_build/js-bindings/blsjs.wasm
-- WASM module ofbls-signatures
./js_build/js-bindings/bundle.js
-- JavaScript bindings forbls-signatures
and all its dependencies.