@@ -12,8 +12,7 @@ Repository.
12
12
- [ Environment Setup] ( #environment-setup )
13
13
* [ Latest Rust] ( #latest-rust )
14
14
* [ Formatting] ( #formatting )
15
- * [ Wasm Build] ( #wasm-build )
16
- * [ Coding Style] ( #coding-style )
15
+ * [ WASM Build] ( #wasm-build )
17
16
18
17
- [ Code of Conduct] ( #code-of-conduct )
19
18
@@ -23,14 +22,17 @@ Repository.
23
22
### Latest Rust
24
23
This project uses a few things that you should set yourself up with before
25
24
starting work. First of all, make sure you have the latest ` rust ` and ` cargo `
26
- installed. The best way to do that is with ` rustup ` , and you can read about it
27
- more in the [ rust
28
- book] ( https://doc.rust-lang.org/book/second-edition/ch01-01-installation.html ) .
29
- But to get yourself uptodate with all the things:
25
+ installed. The best way to do that is with ` rustup ` , and you can read about
26
+ it more in the [ rust
27
+ book] ( https://doc.rust-lang.org/book/ch01-01-installation.html ) . Similarly
28
+ working with cargo is better described in [ the
29
+ book] ( https://doc.rust-lang.org/book/ch01-03-hello-cargo.html )
30
30
31
+ To get yourself uptodate with all the things:
31
32
``` bash
32
33
rustup update
33
34
```
35
+
34
36
### Formatting
35
37
We are using two tools to help with best-practice fromatting:
36
38
[ rustfmt] ( https://github.com/rust-lang-nursery/rustfmt ) and
@@ -54,43 +56,44 @@ augroup filetype_rust
54
56
augroup END
55
57
```
56
58
` rust-nursery ` also has support for other editors, like
57
- [ vscode] ( https://github.com/rust-lang-nursery/rls-vscode ) .
58
-
59
- ` rustfmt ` will also run as a pre-commit hook. You will need to copy the file
60
- that's currently in ` ./hooks/pre-commit ` to your local ` .git ` directory:
61
- ``` bash
62
- cp hooks/pre-commit ./git/hooks/pre-commit
63
- ```
59
+ [ vscode] ( https://github.com/rust-lang-nursery/rls-vscode ) . You can just add
60
+ this plugin to your VSCode setup, and magic :sparkles : , everything works!
64
61
65
- ### Wasm Build
62
+ ### WASM Build
66
63
To be able to use this module in JavaScript and Node, we compile it to WASM. For
67
64
that we use [ wasm-bindgen] ( https://github.com/rustwasm/wasm-bindgen ) inside our
68
65
` lib.rs ` , and [ wasm-pack] ( https://github.com/rustwasm/wasm-pack ) to make a
69
66
package to be published to ` npm ` . To do so, install ` wasm-pack ` :
70
67
``` bash
71
- cargo install wasm-pack
68
+ curl https://rustwasm.github.io/ wasm-pack/installer/init.sh -sSf | sh
72
69
```
70
+
73
71
and run build that will generate a ` pkg ` directory that can be then published to
74
72
npm:
73
+
75
74
``` bash
76
- wasm-pack build
75
+ wasm-pack build --no-typescript --release --scope=mongodb-rust
77
76
```
78
- Travis CI will also run a wasm-pack build to check we are able to compile this correctly.
79
77
80
- ### Coding Style
81
-
82
- A few things to follow when working on this project.
78
+ If you are developing locally, you can also point your javascript imports to
79
+ the build. For example:
80
+ ``` js
81
+ var schemaWasm = import (' ../../mongodb-schema-parser/pkg' )
82
+ ```
83
83
84
- 1 . Avoid using ` unsafe-rust ` . ` lib.rs ` is already setup with
85
- ` #[deny(unsafe-rust)] ` to help with that.
84
+ To publish you can also use ` wasm-pack ` :
85
+ ``` bash
86
+ wasm-pack publish --access=public
87
+ ```
86
88
87
- 2 . Structs should implement ` Copy ` and ` Debug ` traits to avoid future
88
- complications. These can be simple appended with:
89
- ``` rust
90
- #[derive(Debug , Copy )]
91
- struct Pair (Box <i32 >, Box <i32 >)
89
+ As you are developing sometimes it's useful to know whether you can compile
90
+ to WASM. Especially when you add a new crate to the setup:
91
+ ``` bash
92
+ cargo check --target wasm32-unknown-unknown
92
93
```
93
94
95
+ Travis CI will also run a wasm-pack build to check we are able to compile this correctly.
96
+
94
97
## Code of Conduct
95
98
The project has a [ Code of Conduct] ( ./CODE_OF_CONDUCT.md ) that * all*
96
99
contributors are expected to follow. This code describes the * minimum* behavior
0 commit comments