Skip to content

Commit ccc286b

Browse files
jyn514Joshua Nelson
authored and
Joshua Nelson
committed
Add sample nix shell
This also suggests using `x.py setup` instead of copying config.toml.
1 parent 9b0135d commit ccc286b

File tree

2 files changed

+77
-13
lines changed

2 files changed

+77
-13
lines changed

src/building/how-to-build-and-run.md

+6-13
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,10 @@ cd rust
2020

2121
## Create a `config.toml`
2222

23-
To start, copy [`config.toml.example`] to `config.toml`:
23+
To start, run `x.py setup`. This will create a `config.toml` with reasonable defaults.
2424

25-
[`config.toml.example`]: https://github.com/rust-lang/rust/blob/master/config.toml.example
26-
27-
```bash
28-
cp config.toml.example config.toml
29-
```
30-
31-
Then you will want to open up the file and change the following
32-
settings (and possibly others, such as `llvm.ccache`):
25+
You may also want to change some of the following settings (and possibly others, such as
26+
`llvm.ccache`):
3327

3428
```toml
3529
[llvm]
@@ -54,10 +48,9 @@ debug-logging = true
5448
incremental = true
5549
```
5650

57-
If you have already built `rustc`, then you may have to execute `rm -rf build` for subsequent
58-
configuration changes to take effect. Note that `./x.py clean` will not cause a
59-
rebuild of LLVM, so if your configuration change affects LLVM, you will need to
60-
manually `rm -rf build/` before rebuilding.
51+
If you have already built `rustc` and you change settings related to LLVM, then you may have to
52+
execute `rm -rf build` for subsequent configuration changes to take effect. Note that `./x.py
53+
clean` will not cause a rebuild of LLVM.
6154

6255
## What is `x.py`?
6356

src/building/suggested.md

+71
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,74 @@ git worktree add -b my-feature ../rust2 master
203203

204204
You can then use that rust2 folder as a separate workspace for modifying
205205
and building `rustc`!
206+
207+
## Using nix-shell
208+
209+
If you're using nix, you can use the following nix-shell to work on Rust:
210+
211+
```nix
212+
{ pkgs ? import <nixpkgs> {} }:
213+
214+
# This file contains a development shell for working on rustc.
215+
let
216+
# Build configuration for rust-lang/rust. Based on `config.toml.example` from
217+
# `1bd30ce2aac40c7698aa4a1b9520aa649ff2d1c5`.
218+
config = pkgs.writeText "rustc-config" ''
219+
profile = "compiler" # you may want to choose a different profile, like `library` or `tools`
220+
changelog-seen = 2
221+
222+
[build]
223+
# The path to (or name of) the GDB executable to use. This is only used for
224+
# executing the debuginfo test suite.
225+
gdb = "${pkgs.gdb}/bin/gdb"
226+
python = "${pkgs.python3Full}/bin/python"
227+
228+
[rust]
229+
debug = true
230+
incremental = true
231+
deny-warnings = false
232+
233+
# Indicates whether some LLVM tools, like llvm-objdump, will be made available in the
234+
# sysroot.
235+
llvm-tools = true
236+
237+
# Print backtrace on internal compiler errors during bootstrap
238+
backtrace-on-ice = true
239+
'';
240+
241+
ripgrepConfig =
242+
let
243+
# Files that are ignored by ripgrep when searching.
244+
ignoreFile = pkgs.writeText "rustc-rgignore" ''
245+
configure
246+
config.toml.example
247+
x.py
248+
LICENSE-MIT
249+
LICENSE-APACHE
250+
COPYRIGHT
251+
**/*.txt
252+
**/*.toml
253+
**/*.yml
254+
**/*.nix
255+
*.md
256+
src/ci
257+
src/etc/
258+
src/llvm-emscripten/
259+
src/llvm-project/
260+
src/rtstartup/
261+
src/rustllvm/
262+
src/stdsimd/
263+
src/tools/rls/rls-analysis/test_data/
264+
'';
265+
in
266+
pkgs.writeText "rustc-ripgreprc" "--ignore-file=${ignoreFile}";
267+
in
268+
pkgs.mkShell {
269+
name = "rustc";
270+
nativeBuildInputs = with pkgs; [
271+
gcc9 binutils cmake ninja openssl pkgconfig python39 git curl cacert patchelf nix psutils
272+
];
273+
RIPGREP_CONFIG_PATH = ripgrepConfig;
274+
RUST_BOOTSTRAP_CONFIG = config;
275+
}
276+
```

0 commit comments

Comments
 (0)