Skip to content

Commit 8810f22

Browse files
author
Herman Venter
committed
Add developer instructions to documentation
1 parent be82879 commit 8810f22

File tree

3 files changed

+153
-5
lines changed

3 files changed

+153
-5
lines changed

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ The initial focus will be on taint analyis.
1010
## Requirements
1111
__________ requires or works with
1212
* Mac OS X or Linux
13-
* ...
13+
* ... -->
1414

15-
## Building __________
16-
...
15+
## Building
16+
See the [developer guide](https://github.com/facebookexperimental/MIRAI/blob/master/documentation//DeveloperGuide.md)
17+
for instructions on how to build, run and debug MIRAI.
1718

19+
<!--
1820
## Installing __________
1921
...
2022
@@ -32,7 +34,7 @@ __________ requires or works with
3234
* Facebook page:
3335
* Mailing list
3436
* irc: -->
35-
See the CONTRIBUTING file for how to help out.
37+
See the [CONTRIBUTING](https://github.com/facebookexperimental/MIRAI/blob/master/CONTRIBUTING.md) file for how to help out.
3638

3739
## License
38-
Mirai is MIT licensed, as found in the LICENSE file.
40+
Mirai is MIT licensed, as found in the [LICENSE](https://github.com/facebookexperimental/MIRAI/blob/master/LICENSE) file.

documentation/DebuggingRustc.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Debugging Rustc
2+
3+
Since Mirai makes use of a private and unstable API with sparse documentation, it can be very helpful to debug
4+
Mirai while seeing the actual rustc sources in the debugger. By default, this does not happen.
5+
6+
To work around this some painful steps need to be taken. First of all, get the sources of rustc and build them.
7+
8+
```
9+
# cd to the directory where you want to keep the rust compiler sources
10+
git clone https://github.com/rust-lang/rust/ rustc
11+
cd rustc
12+
cp config.toml.example config.toml
13+
# Now edit config.toml and set debug, debug-assertions, debuginfo, and debuginfo-lines to true
14+
./x.py build src/rustc
15+
# You may have to change the architecture in the next command
16+
rustup toolchain link custom build/nightly-x86_64-apple-darwin/stage2
17+
```
18+
19+
If you have done the above previously, be sure to pull down the latest changes from the github repo.
20+
21+
Next build the Mirai sources.
22+
23+
```
24+
# cd to your mirai directory
25+
rustup override set custom
26+
cargo clean
27+
cargo build
28+
```
29+
30+
Now switch back to using the nightly build, or the Rust Language Service (RLS) will crash when you try to load VSCode or
31+
Clion.
32+
33+
```
34+
rustup override set nightly
35+
```
36+
37+
Now close and reload VSCode (Clion does not support this scenario) and modify the configuration to reference the custom
38+
build of rustc
39+
40+
``` {
41+
"type": "lldb",
42+
"request": "launch",
43+
"name": "Debug executable 'mirai'",
44+
"cargo": {
45+
"args": [
46+
"build",
47+
"--bin=mirai",
48+
"--package=Mirai"
49+
],
50+
"filter": {
51+
"kind": "bin"
52+
}
53+
},
54+
"env": {
55+
"DYLD_LIBRARY_PATH": "${env:HOME}/.rustup/toolchains/custom/lib",
56+
},
57+
"sourceLanguages": ["rust"],
58+
"args": [<what you'll give to rustc, split into an array of strings using space as the delimiter>],
59+
"cwd": "${workspaceFolder}",
60+
},
61+
```
62+
63+
Now switch back to the custom build, otherwise mirai wont load.
64+
65+
```
66+
rustup override set custom
67+
```
68+
69+
And now you can finally debug while seeing rustc sources. Be aware, however, that doing anything in the editor that
70+
invokes the RLS will cause it to crash, which sooner or later causes all sorts of trouble.
71+
72+
When you are done debugging, revert to the nightly build.

documentation/DeveloperGuide.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

Comments
 (0)