|
| 1 | +# Developer Guide |
| 2 | + |
| 3 | +## Building |
| 4 | + |
| 5 | +You'll need to have Rust installed on your system. See |
| 6 | +[here](https://doc.rust-lang.org/book/2018-edition/ch01-01-installation.html) for instructions. |
| 7 | + |
| 8 | +Mirai depends on unstable private APIs of the rust compiler to do things like parsing, type checking and |
| 9 | +lowering to MIR. These can only be accessed by using the nightly build of the compiler. So use rustup to set |
| 10 | +the nightly build as the default for the mirai project. |
| 11 | + |
| 12 | +```rustup override set nightly``` |
| 13 | + |
| 14 | +That done, all you need to do to build Mirai is to type `cargo build` in your command shell. Generally building happens |
| 15 | +automatically as you run tests. |
| 16 | + |
| 17 | + |
| 18 | +## Editing |
| 19 | + |
| 20 | +The best editing experience seems to be with [Clion](https://www.jetbrains.com/clion/). |
| 21 | + |
| 22 | +Alternatively there is also |
| 23 | +[VSCode](https://code.visualstudio.com/). You'll want to install these extensions: |
| 24 | +[Rust (rls)](https://github.com/rust-lang-nursery/rls-vscode), [CodeLLDB](https://github.com/vadimcn/vscode-lldb) and |
| 25 | +[Better TOML](https://github.com/bungcip/better-toml). |
| 26 | + |
| 27 | +There is also [Nuclide](https://nuclide.io/). You'll want to install the [Rust](https://atom.io/packages/language-rust) |
| 28 | +extension. This option is pretty basic and not recommended right now. It does have a better integration with Git, so I |
| 29 | +actually use Clion for editing, VSCode for debugging and Nuclide for doing source control. |
| 30 | + |
| 31 | +## Running |
| 32 | + |
| 33 | +Run the mirai binary as if it were rustc. To do this via cargo, set the `RUSTC_WRAPPER` environment variable to `mirai`. |
| 34 | + |
| 35 | +At the moment you'll also need to set the `DYLD_LIBRARY_PATH` environment variable to |
| 36 | +`~/.rustup/toolchains/nightly-x86_64-apple-darwin/lib`. This is a bit strange and I'd love to find out how to avoid |
| 37 | +it. |
| 38 | + |
| 39 | +## Debugging |
| 40 | + |
| 41 | +VSCode gives a better experience than Clion at the moment. To use VSCode you'll need to add the following to the |
| 42 | +configurations property of the content of the launch.json file in the .vscode directory of your project directory: |
| 43 | +``` { |
| 44 | + "type": "lldb", |
| 45 | + "request": "launch", |
| 46 | + "name": "Debug executable 'mirai'", |
| 47 | + "cargo": { |
| 48 | + "args": [ |
| 49 | + "build", |
| 50 | + "--bin=mirai", |
| 51 | + "--package=Mirai" |
| 52 | + ], |
| 53 | + "filter": { |
| 54 | + "kind": "bin" |
| 55 | + } |
| 56 | + }, |
| 57 | + "env": { |
| 58 | + "DYLD_LIBRARY_PATH": "${env:HOME}/.rustup/toolchains/nightly-x86_64-apple-darwin/lib", |
| 59 | + }, |
| 60 | + "sourceLanguages": ["rust"], |
| 61 | + "args": [<what you'll give to rustc, split into an array of strings using space as the delimiter>], |
| 62 | + "cwd": "${workspaceFolder}", |
| 63 | + }, |
| 64 | +``` |
| 65 | + |
| 66 | +Since Mirai makes use of a private and unstable API with sparse documentation, it can be very helpful to debug |
| 67 | +Mirai while seeing the actual rustc sources in the debugger. By default, this does not happen. To make it happen, see |
| 68 | +[debugging](https://github.com/facebookexperimental/MIRAI/blob/master/documentation/DebuggingRustc.md) with Rustc |
| 69 | +sources. |
| 70 | + |
| 71 | +## Testing |
| 72 | + |
| 73 | +For now we test mirai by running it on itself, by doing `cargo build` in the mirai directory while setting the |
| 74 | +`RUSTC_WRAPPER` environment variable to `mirai`. |
0 commit comments