Closed janus closed 5 years ago
The code is for !isNodeJs
, i.e., browsers.
Module()
is defined in bls_c.js, and a function defined in it calls wasm file.
Please can you give me the importObject
to use in the below:
I managed to craft this .. it compiles but has no value,
env: {
'__table_base': 0,
'__memory_base': 0,
'memory': new WebAssembly.Memory({initial: 256, maximum: 256}),
'table': new WebAssembly.Table({initial: 232, element: 'anyfunc', maximum: 232}),
'a': 66928,
'b': function(){},
'c': function(val){return val},
'd': function(requestedSize){return false},
'e': function(){},
'f': function(){},
abort: function(){},
}
}
fetch(`http://localhost:8080/dist/${name}.wasm`) // eslint-disable-line
.then(response => response.arrayBuffer()) //response.arrayBeuffer())
.then(buffer => WebAssembly.compile(buffer))
.then((module) => new WebAssembly.Instance(module, importObject))
.then((instance) => {
bls_c.js is generated by Emscripten so please see the documents.
@herumi
Thanks .. but when I tried wasm2wat to the wasm file provided I found that it lacked bls functions. I would have compiled to wasm by myself but I dont know where this file is ,../mcl/src/fp.cpp
. Easy it possible to get that file?
And could you compile to only wasm ... that is something like this emcc -o blc_s.wasm src/bls_c384.cpp ../mcl/src/fp.cpp $(EMCC_OPT).
Please try the following command.
mkdir work
cd work
git clone git@github.com:herumi/mcl
git clone git@github.com:herumi/bls
cd bls
make bls-wasm
Thanks ... I have been able to compile to wasm only ... I will test ... and give you feed back.
I have searched through bls.js to see how wasm file is used. But it is not clear to me. And I found this function call strange ,
Module()
. Where is this function calling from?`` fetch(
./${name}.wasm`) // eslint-disable-line .then(response => response.arrayBuffer()) .then(buffer => new Uint8Array(buffer)) .then(() => { exports.mod = Module() // eslint-disable-line exports.mod.cryptoGetRandomValues = _cryptoGetRandomValues exports.mod.onRuntimeInitialized = () => { setup(exports, curveType) resolve() } })