You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: wasm-wrappers/README.md
+27-21Lines changed: 27 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,12 @@
1
-
##Basic wasm bindings for mintlayer
1
+
# Basic wasm bindings for mintlayer
2
2
3
3
This module has different basic functionalities of mintlayer compiled into wasm for various purposes, primarily interfacing with other systems and languages without having to rewrite code.
4
4
5
5
##### Note: This was tested on x86_64 Linux, and may not work on other platforms. It didn't work on M1 Mac directly (particularly the build. A pre-built wasm binary works fine on a browser, see below for more information).
6
6
7
+
## Running the tests
7
8
8
-
### To run in a web browser
9
+
### Preparation
9
10
10
11
Make sure you have wasm-pack and the wasm32-unknown-unknown target installed:
11
12
@@ -16,48 +17,53 @@ cargo install wasm-pack
16
17
17
18
Also make sure you have `clang` installed. It's required.
18
19
19
-
To build the wasm package from the crate, run (in the wasm Cargo.toml directory):
20
-
21
-
```
22
-
wasm-pack build --target web
23
-
```
24
-
25
20
**Note for mac users**: `llvm` installed by Xcode doesn't support wasm targets, but the homebrew version does, these commands may make it possible to compile to wasm targets. Note that using these commands could have other side effects on your toolchain. Please consider researching the clang toolchain and how it works before using them. We do not recommend copying and pasting commands without fully understanding the side-effects.
26
21
```
27
22
brew install llvm
28
23
AR=/opt/homebrew/opt/llvm/bin/llvm-ar CC=/opt/homebrew/opt/llvm/bin/clang wasm-pack build --target web
29
24
```
30
25
31
-
To test the wasm binary. First, install `http-server` web server (feel free to use any other web-server of your choosing):
26
+
Also, install TypeScript:
27
+
```
28
+
npm install -g typescript
29
+
```
30
+
31
+
### Compile the tests via `tsc`
32
32
33
+
In the wasm Cargo.toml directory, run:
33
34
```
34
-
cargo install http-server
35
+
tsc --project js-bindings-test/tsconfig.json
35
36
```
36
37
37
-
Then run the http server, and then choose the file `js-bindings/index.html`:
38
+
### Running the tests in a web browser
39
+
40
+
To build the wasm package from the crate, run (in the wasm Cargo.toml directory):
38
41
39
42
```
40
-
http-server --port 8080 --verbose
43
+
wasm-pack build --target web
41
44
```
42
45
43
-
If you're using a remote server, either tunnel to port 8080, or expose that port and run this (assuming you understand the security risks):
46
+
To test the wasm binary. First, install `http-server` web server (feel free to use any other web-server of your choosing):
44
47
45
48
```
46
-
http-server --port 8080 --host 0.0.0.0 --verbose
49
+
cargo install http-server
47
50
```
48
51
49
-
The ported wasm functions are exported to the file `js-bindings/index.js` and used in the file `js-bindings/index.html` with a basic test/example in them using JavaScript. Use your browser's console to see the output.
52
+
Then run the http server, and then choose the file `js-bindings-test/index.html`:
50
53
51
-
### To run in Node.js
54
+
```
55
+
http-server --port 8080
56
+
```
52
57
53
-
Make sure you have wasm-pack and the wasm32-unknown-unknown target installed:
58
+
If you're using a remote server, either tunnel to port 8080, or expose that port and run this (assuming you understand the security risks):
54
59
55
60
```
56
-
rustup target add wasm32-unknown-unknown
57
-
cargo install wasm-pack
61
+
http-server --port 8080 --host 0.0.0.0
58
62
```
59
63
60
-
Also make sure you have `clang` installed. It's required.
64
+
The ported wasm functions are exported to the file `js-bindings-test/index.js` and used in the file `js-bindings-test/index.html` with a basic test/example in them using JavaScript. Use your browser's console to see the output.
65
+
66
+
### Running the tests in Node.js
61
67
62
68
To build the wasm package from the crate, run (in the wasm Cargo.toml directory):
0 commit comments