|
1 | 1 | # Contributing
|
2 | 2 |
|
3 |
| -Thanks for your help! Due to ReScript's nature, the contribution setup isn't all straightforward. If something isn't working, please file an issue! |
| 3 | +Welcome to the ReScript compiler project! |
| 4 | + |
| 5 | +This documet will give you guidance on how to get up and running to work on the ReScript compiler and toolchain. |
| 6 | + |
| 7 | +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 | + |
| 9 | +Happy hacking! |
4 | 10 |
|
5 | 11 | ## Prerequisites
|
6 | 12 |
|
7 |
| -- [NodeJS](https://nodejs.org/) |
8 |
| -- C compiler toolchain (you probably already have it installed) |
9 |
| -- OS: Mac/Linux (ReScript works on Windows, but developing the repo using Windows isn't tested. Contribution welcome!) |
| 13 | +> We are mainly working on Apple machines, so all our instructions are currently MacOS / Linux centric. Contributions for Windows development welcome! |
10 | 14 |
|
11 |
| -## Install native OCaml compiler |
| 15 | +- [NodeJS v16](https://nodejs.org/) |
| 16 | +- C compiler toolchain (usually installed with `xcode` on Mac) |
| 17 | +- `opam` (OCaml Package Manager) |
| 18 | +- VSCode (+ [OCaml Platform Extension](https://marketplace.visualstudio.com/items?itemName=ocamllabs.ocaml-platform)) |
12 | 19 |
|
13 |
| -If you are familiar with OCaml toolchain, you can use |
| 20 | +## Install native OCaml compiler, dune, testing utilities |
14 | 21 |
|
15 |
| -``` |
16 |
| -opam switch 4.06.1+rescript |
17 |
| -eval $(opam env) |
18 |
| -``` |
| 22 | +The ReScript compiler compiles with any recent OCaml compiler. We are using `dune` as a build system for easy workflows and proper IDE support. |
19 | 23 |
|
20 |
| -If you don't want to bother with opam, we provided a vendored compiler, you can use it directly |
21 | 24 | ```
|
22 |
| -node ./scripts/buildocaml.js |
23 |
| -# make sure the built compiler is in your PATH, checkout native directory |
| 25 | +brew install opam |
| 26 | +opam init |
| 27 | +
|
| 28 | +# Install build system |
| 29 | +opam install dune |
| 30 | +
|
| 31 | +# Install language server for IDE support |
| 32 | +opam install ocaml-lsp-server |
| 33 | +
|
| 34 | +# Any recent OCaml version works as a development compiler |
| 35 | +opam switch create 4.12.1 |
| 36 | +
|
| 37 | +# We use NodeJS to run our test suites and other utilities. |
| 38 | +npm install |
24 | 39 | ```
|
25 | 40 |
|
| 41 | +## Configure and Build the Compiler (`ninja` workflow) |
26 | 42 |
|
27 |
| -## Build |
| 43 | +> Note: These instructions allow you to do full builds of the project. In case you only want to build the project for development purposes, you can use the `dune` workflow. |
| 44 | +
|
| 45 | +The ReScript project is built with a vendored version of `ninja`. It requires build files to correctly detect, compile and link all the OCaml files within our project. The build files are generated and managed by a NodeJS script (`./scripts/ninja.js`). |
28 | 46 |
|
29 | 47 | ```sh
|
30 |
| -npm install # install some JS tools for testing purposes |
31 |
| -./scripts/ninja.js config # the repo is build with Ninja. Generate the ninja build files |
32 |
| -./scripts/ninja.js build # runs `ninja` under the hood against the generated ninja build files |
| 48 | +# Generate all the necessary ninja build files |
| 49 | +./scripts/ninja.js config |
| 50 | + |
| 51 | +# Run ninja to read and execute the generated build files |
| 52 | +./scripts/ninja.js build |
| 53 | + |
| 54 | +# Clean (remove) all ninja build files |
| 55 | +./scripts/ninja.js clean |
33 | 56 | ```
|
34 | 57 |
|
35 |
| -Whenever you edit a file, run `./scripts/ninja.js build` to rebuild. Optional watcher to auto-rebuild on file changes: `node scripts/tasks.js`. |
| 58 | +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 | + |
| 60 | +## Building the Project During Development (`dune` workflow) |
| 61 | + |
| 62 | +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 | + |
| 64 | +``` |
| 65 | +# One off build |
| 66 | +dune build |
| 67 | +
|
| 68 | +# Watch mode |
| 69 | +dune build -w |
| 70 | +``` |
36 | 71 |
|
37 |
| -In the rare case there you're making changes to the vendored OCaml fork, rebuild the fork with `node scripts/buildocaml.js` then run `./scripts/ninja.js cleanbuild`. `cleanbuild` (aka `clean` + `build`) is necessary since the binary artifacts between versions of compiler may be incompatible. |
| 72 | +> 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. |
38 | 73 |
|
39 | 74 | ### Troubleshoot Broken Build
|
40 | 75 |
|
|
0 commit comments