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: CONTRIBUTING.md
+73-43
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,17 @@
2
2
3
3
Welcome to the ReScript compiler project!
4
4
5
-
This documet will give you guidance on how to get up and running to work on the ReScript compiler and toolchain.
5
+
This document will give you guidance on how to get up and running to work on the ReScript compiler and toolchain.
6
+
7
+
(If you want to contribute to the documentation website, check out [rescript-association/rescript-lang.org](See https://github.com/reason-association/rescript-lang.org). For contributions to the ReScript syntax, please visit the [rescript-lang/syntax](https://github.com/rescript-lang/syntax) project.)
6
8
7
9
We tried to keep the installation process as simple as possible. In case you are having issues or get stuck in the process, please let us know in the issue tracker.
8
10
9
11
Happy hacking!
10
12
11
-
## Prerequisites
13
+
## Setup
12
14
13
-
> We are mainly working on Apple machines, so all our instructions are currently MacOS / Linux centric. Contributions for Windows development welcome!
15
+
> Most of our contributors are working on Apple machines, so all our instructions are currently MacOS / Linux centric. Contributions for Windows development welcome!
14
16
15
17
-[NodeJS v16](https://nodejs.org/)
16
18
- C compiler toolchain (usually installed with `xcode` on Mac)
@@ -57,7 +59,7 @@ The ReScript project is built with a vendored version of `ninja`. It requires bu
57
59
58
60
Whenever you edit a file, run `./scripts/ninja.js build` to rebuild the ReScript compiler. There's also an optional watcher to auto-rebuild on file changes: `node scripts/tasks.js`.
59
61
60
-
## Building the Project During Development (`dune` workflow)
62
+
## Build the Project during Development (`dune` workflow)
61
63
62
64
When working on a project you may want to use `dune` to compile all the files you've been working on. This is especially important for full IDE support, including auto-completion and showing compilation errors.
63
65
@@ -71,7 +73,9 @@ dune build -w
71
73
72
74
> Please note that `dune` will not build the final `rescript` binaries. Use the aforementioned `ninja` workflow if you want to build, test and distribute the final product.
73
75
74
-
### Troubleshoot Broken Build
76
+
### Troubleshoot a Broken Build
77
+
78
+
Usually whenever there's some issues with missing files, incompatible interfaces or stale artifacts, the easiest fix is to clean and rebuild the project:
75
79
76
80
```sh
77
81
./scripts/ninja.js clean # remove files not in version control
@@ -84,73 +88,72 @@ If this doesn't work (rare), then:
84
88
-`git clean -xdf .` to wipe all artifacts
85
89
- Then do a clean build as instructed above
86
90
87
-
## Test
91
+
## Running tests for independent ReScript files
92
+
93
+
The simplest way for running tests is to run your locally built compiler on separate ReScript files:
88
94
89
95
```sh
90
-
./darwin/bsc.exe myTestFile.ml
96
+
# Make sure to rebuild the compiler before running any tests (./scripts/ninja.js config / build etc)
97
+
./darwinarm64/bsc.exe myTestFile.res
91
98
```
92
99
93
-
(`./linux/bsc` for linux developers).
94
-
95
-
> Note: production, only `path/to/bsc myTestFile.ml` is needed. During development, you need to pass the `-I jscomp/runtime/` flag for various reasons (e.g. to avoid cyclic dependencies).
100
+
**Different architectures:**
96
101
97
-
Tips:
98
-
- To get a nice stack trace when you debug type errors from running `bsc`/`bsb`, uncomment the conditional compilation check in [`rescript_compiler_main.ml`](https://github.com/rescript-lang/rescript-compiler/blob/496c70d1d4e709c26dba23629e430dc944bd59f9/jscomp/main/rescript_compiler_main.ml#L501).
102
+
-`darwinarm64/bsc.exe`: M1 Macs
103
+
-`darwin/bsc.exe`: Intel Macs
104
+
-`linux/bsc.exe`: Linux computers
99
105
100
-
### Integration Test
106
+
### Testing the whole ReScript Package
101
107
102
-
If you'd like to use your modified ReScript like an end-user, try:
108
+
If you'd like to bundle up and use your modified ReScript like an end-user, try:
103
109
104
110
```sh
105
-
npm uninstall -g bs-platform # a cache-busting uninstall is needed, but only for npm >=7
111
+
npm uninstall -g rescript # a cache-busting uninstall is needed, but only for npm >=7
112
+
113
+
# This will globally install your local build via npm
106
114
BS_TRAVIS_CI=1 npm install -g .
107
115
```
108
116
109
-
Then go somewhere and create a dummy project:
117
+
Then you may initialize and build your ReScript project as usual:
110
118
111
119
```sh
112
-
bsb -init foo -theme basic
113
-
cdfoo
120
+
rescript init my-project
121
+
cdmy-project
114
122
npm run build
115
123
```
116
124
117
-
##Editor Support for Developing This Repo
125
+
### Running Automatic Tests
118
126
119
-
This is hard to set up and therefore not entirely encouraged. Use this deprecated [VSCode extension](https://marketplace.visualstudio.com/items?itemName=hackwaly.ocaml).
120
-
The extension requires using an opam switch for ocaml 4.02.3, with `merlin` and `ocp-indent` are installed.
127
+
We provide different test suites for different levels of the compiler and build system infrastructure. Always make sure to locally build your compiler before running any tests.
121
128
122
-
## Contribute to the Documentation
129
+
**Run Mocha tests for our runtime code:**
123
130
124
-
See https://github.com/reason-association/rescript-lang.org
131
+
This will run our `mocha` unit test suite defined in `jscomp/test`.
125
132
126
-
## Contribute to the API Reference
133
+
```
134
+
npx node scripts/ciTest.js -mocha
135
+
```
127
136
128
-
The API reference is generated from doc comments in the source code. [Here](https://github.com/rescript-lang/rescript-compiler/blob/99650/jscomp/others/js_re.mli#L146-L161)'s a good example.
137
+
**Run build system test (integration tests):**
129
138
130
-
Some tips:
139
+
This will run the whole build system test suite defined in `jscomp/build_tests`.
131
140
132
-
- The first sentence or line should be a very short summary. This is used in indexes and by tools like merlin.
133
-
- Ideally, every function should have **at least one**`@example`.
134
-
- Cross-reference another definition with `{! identifier}`. But use them sparingly, they’re a bit verbose (currently, at least).
135
-
- Wrap non-cross-referenced identifiers and other code in `[ ... ]`.
136
-
- Escape `{`, `}`, `[`, `]` and `@` using `\`.
137
-
- It’s possible to use `{%html ...}` to generate custom html, but use this very, very sparingly.
138
-
- A number of "documentation tags" are provided that would be nice to use, but unfortunately they’re often not supported for \`external\`s. Which is of course most of the API.
139
-
-`@param` usually doesn’t work. Use `{b <param>} ...` instead
140
-
-`@returns` usually doesn’t work. Use `{b returns} ...` instead.
141
-
- Always use `@deprecated` when applicable.
142
-
- Always use `@raise` when applicable.
143
-
- Always provide a `@see` tag pointing to MDN for more information when available.
141
+
```
142
+
# Make sure to globally install rescript via npm first
143
+
npm install -g .
144
144
145
-
See [Ocamldoc documentation](http://caml.inria.fr/pub/docs/manual-ocaml/ocamldoc.html#sec333) for more details.
145
+
npx node scripts/ciTest.js -bsb
146
+
```
146
147
147
-
To generate the html:
148
+
**Run ounit tests:**
149
+
150
+
This will run unit tests for compiler related modules. The tests can be found in `jscomp/ounit_tests`.
148
151
149
-
```sh
150
-
../scripts/ninja docs
152
+
```
153
+
npx node scripts/ciTest.js -ounit
151
154
```
152
155
153
-
## Contributing to the Runtime
156
+
## Contributing to the ReScript Runtime
154
157
155
158
Our runtime implementation is written in pure OCaml with some raw JS code embedded (`jscomp/runtime` directory).
156
159
@@ -285,6 +288,33 @@ In this repo, these files usually sit right next to each compiled `.ml` / `.re`
285
288
286
289
For any other dependency needed in the playground, such as `ReasonReact`, you will be required to serialize your `.cmi` / `.cmt` files accordingly from binary to hex encoded strings so that BS Playground's `ocaml.load` function can load the data. Right now we don't provide any instructions inside here yet, but [here's how the official ReasonML playground did it](https://github.com/reasonml/reasonml.github.io/blob/source/website/setupSomeArtifacts.js#L65).
287
290
291
+
## Contribute to the API Reference
292
+
293
+
The API reference is generated from doc comments in the source code. [Here](https://github.com/rescript-lang/rescript-compiler/blob/99650/jscomp/others/js_re.mli#L146-L161)'s a good example.
294
+
295
+
Some tips:
296
+
297
+
- The first sentence or line should be a very short summary. This is used in indexes and by tools like merlin.
298
+
- Ideally, every function should have **at least one**`@example`.
299
+
- Cross-reference another definition with `{! identifier}`. But use them sparingly, they’re a bit verbose (currently, at least).
300
+
- Wrap non-cross-referenced identifiers and other code in `[ ... ]`.
301
+
- Escape `{`, `}`, `[`, `]` and `@` using `\`.
302
+
- It’s possible to use `{%html ...}` to generate custom html, but use this very, very sparingly.
303
+
- A number of "documentation tags" are provided that would be nice to use, but unfortunately they’re often not supported for \`external\`s. Which is of course most of the API.
304
+
-`@param` usually doesn’t work. Use `{b <param>} ...` instead
305
+
-`@returns` usually doesn’t work. Use `{b returns} ...` instead.
306
+
- Always use `@deprecated` when applicable.
307
+
- Always use `@raise` when applicable.
308
+
- Always provide a `@see` tag pointing to MDN for more information when available.
309
+
310
+
See [Ocamldoc documentation](http://caml.inria.fr/pub/docs/manual-ocaml/ocamldoc.html#sec333) for more details.
311
+
312
+
To generate the html:
313
+
314
+
```sh
315
+
../scripts/ninja docs
316
+
```
317
+
288
318
## Code structure
289
319
290
320
The highlevel architecture is illustrated as below:
0 commit comments