|
| 1 | +PLEASE NOTE - THIS PROJECT IS NOT PRODUCTION READY |
1 | 2 |
|
| 3 | +spcp256k1-wasm |
| 4 | +============== |
2 | 5 |
|
3 |
| -### Repositories you need to clone |
4 |
| - |
5 |
| -* git clone https://github.com/aspectron/secp256k1-wasm |
6 |
| -* git clone https://github.com/WebAssembly/binaryen.git |
7 |
| -* git clone https://github.com/llvm/llvm-project.git |
8 |
| -* git clone https://github.com/emscripten-core/emscripten.git |
9 |
| - |
10 |
| - |
11 |
| -### Build emscripten |
12 |
| -``` |
13 |
| -cd emscripten |
14 |
| -mkdir build |
15 |
| -cd build/ |
16 |
| -cmake ../../llvm-project/llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS='lld;clang' -DLLVM_TARGETS_TO_BUILD="host;WebAssembly" -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF |
17 |
| -cmake --build . -j NNN |
18 |
| -NNN = no of CPU cores/threads to faster the build process; |
19 |
| -OR: cmake --build . --config Release -j NNN |
20 |
| -cd .. (emscripten dir) |
21 |
| -./emcc -v cd .. |
22 |
| -<this command "./emcc -v" will create .emscripten file> |
23 |
| - in .emscripten file ---> |
24 |
| -point "LLVM_ROOT" to <path to emscripten>/build/bin |
25 |
| -point "BINARYEN_ROOT" to <path to binaryen> |
26 |
| -restest "./emcc -v" command now all should be ok to show version of emcc, clang and InstalledDir etc info |
27 |
| -``` |
28 |
| - |
29 |
| -### Build binaryen |
30 |
| -``` |
31 |
| -cd binaryen |
32 |
| -cmake . |
33 |
| -cmake --build . --config Release |
34 |
| -cmake --build . --config Release -j NNN |
35 |
| -``` |
36 |
| - |
37 |
| -### Build secp256k1-wasm |
38 |
| -``` |
39 |
| -emcc -I ./depend/secp256k1-wasm -I ./depend/secp256k1-wasm/src secp.cpp -o http/secp.html -s EXTRA_EXPORTED_RUNTIME_METHODS=["cwrap"] -std=c++11 --bind -s ALLOW_MEMORY_GROWTH=1 |
40 |
| -
|
41 |
| -npm install |
42 |
| -node server |
43 |
| -``` |
44 |
| - |
45 |
| -### msys2 |
46 |
| -``` |
47 |
| -pacman -S python base-devel |
48 |
| -``` |
| 6 | +EMCC+LLVM WebAssembly bindings for [libsecp256k1 ](https://github.com/bitcoin-core/secp256k1) |
| 7 | + |
| 8 | +This project provides Emscripten WASM bindings for libsecp256k1 and provides basic scaffolding to build the native libsecp256k1 C code to WASM using EMCC. |
| 9 | + |
| 10 | +Building secp256k1-wasm |
| 11 | +----------------------- |
| 12 | + |
| 13 | +Repositories you will need to clone: |
| 14 | + |
| 15 | + $ git clone https://github.com/aspectron/secp256k1-wasm |
| 16 | + $ git clone https://github.com/WebAssembly/binaryen |
| 17 | + $ git clone https://github.com/llvm/llvm-project |
| 18 | + $ git clone https://github.com/emscripten-core/emscripten |
| 19 | + |
| 20 | +Building Binaryen: |
| 21 | + |
| 22 | + $ cd binaryen |
| 23 | + $ cmake . |
| 24 | + $ cmake --build . --config Release -j NNN |
| 25 | + NNN = number of CPU cores/threads |
| 26 | + |
| 27 | + |
| 28 | +Building Emscripten and LLVM: |
| 29 | + |
| 30 | +The following process builds LLVM inside the `./emscripten/build` folder |
| 31 | + |
| 32 | + $ cd emscripten |
| 33 | + $ mkdir build |
| 34 | + $ cd build/ |
| 35 | + $ cmake ../../llvm-project/llvm \ |
| 36 | + -DCMAKE_BUILD_TYPE=Release \ |
| 37 | + -DLLVM_ENABLE_PROJECTS='lld;clang' \ |
| 38 | + -DLLVM_TARGETS_TO_BUILD="host;WebAssembly" \ |
| 39 | + -DLLVM_INCLUDE_EXAMPLES=OFF \ |
| 40 | + -DLLVM_INCLUDE_TESTS=OFF |
| 41 | + $ cmake --build . --config Release -j NNN |
| 42 | + NNN = number of CPU cores/threads |
| 43 | + $ cd .. |
| 44 | + |
| 45 | +We are now back in the Emscripten folder. Generate the default `.emscripten` file: |
| 46 | + |
| 47 | + $ ./emcc -v |
| 48 | + |
| 49 | +Edit the `.emscripten` file to contain correct paths to LLVM and Binaryen: |
| 50 | + |
| 51 | + * point `LLVM_ROOT` to `<path to emscripten>/build/bin` or `<path to emscripten>/build/Release/bin` if LLVM was built using Visual C++ |
| 52 | + * point `BINARYEN_ROOT` to `<path to binaryen>` |
| 53 | + |
| 54 | +Re-run `./emcc -v` to check that everything is ok. You should now see the version of EMCC, clang and InstalledDir information. |
| 55 | + |
| 56 | +Build secp256k1-wasm: |
| 57 | + |
| 58 | +You can run `./build` or `build.bat` to build the WASM binaries or execute the following: |
| 59 | + |
| 60 | + $ emcc -I ./depend/secp256k1 -I ./depend/secp256k1/src secp256k1-bindings.cpp -o http/secp256k1.html -s EXTRA_EXPORTED_RUNTIME_METHODS=["cwrap"] -std=c++11 --bind -s ALLOW_MEMORY_GROWTH=1 -s IMPORTED_MEMORY |
| 61 | + |
| 62 | +To test the build, you will require an installed version of NodeJs. From within the `secp256k1-wasm` folder please run the following: |
| 63 | + |
| 64 | + $ npm install |
| 65 | + $ node server |
| 66 | + |
| 67 | +You should now be able to access the emscripten environment with secp256k1 loaded at http://localhost:3000 |
0 commit comments