Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make shell.nix better #1858

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 24 additions & 57 deletions src/building/suggested.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,67 +270,34 @@ If you're using nix, you can use the following nix-shell to work on Rust:

```nix
{ pkgs ? import <nixpkgs> {} }:

# This file contains a development shell for working on rustc.
let
# Build configuration for rust-lang/rust. Based on `config.example.toml` (then called
# `config.toml.example`) from `1bd30ce2aac40c7698aa4a1b9520aa649ff2d1c5`
config = pkgs.writeText "rustc-config" ''
profile = "compiler" # you may want to choose a different profile, like `library` or `tools`

[build]
patch-binaries-for-nix = true
# The path to (or name of) the GDB executable to use. This is only used for
# executing the debuginfo test suite.
gdb = "${pkgs.gdb}/bin/gdb"
python = "${pkgs.python3Full}/bin/python"

[rust]
debug = true
incremental = true
deny-warnings = false

# Indicates whether some LLVM tools, like llvm-objdump, will be made available in the
# sysroot.
llvm-tools = true

# Print backtrace on internal compiler errors during bootstrap
backtrace-on-ice = true
'';

ripgrepConfig =
let
# Files that are ignored by ripgrep when searching.
ignoreFile = pkgs.writeText "rustc-rgignore" ''
configure
config.example.toml
x.py
LICENSE-MIT
LICENSE-APACHE
COPYRIGHT
**/*.txt
**/*.toml
**/*.yml
**/*.nix
*.md
src/ci
src/etc/
src/llvm-emscripten/
src/llvm-project/
src/rtstartup/
src/rustllvm/
src/stdsimd/
src/tools/rls/rls-analysis/test_data/
'';
in
pkgs.writeText "rustc-ripgreprc" "--ignore-file=${ignoreFile}";
in
pkgs.mkShell {
name = "rustc";
nativeBuildInputs = with pkgs; [
gcc_multi binutils cmake ninja openssl pkgconfig python39 git curl cacert patchelf nix psutils
binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
];
buildInputs = [
Noratrieb marked this conversation as resolved.
Show resolved Hide resolved
openssl glibc.out glibc.static
];
RIPGREP_CONFIG_PATH = ripgrepConfig;
# Avoid creating text files for ICEs.
RUSTC_ICE = "0";
}
```

Note that when using nix on a not-NixOS distribution, it may be necessary to set
**`patch-binaries-for-nix = true` in `config.toml`**.
Bootstrap tries to detect whether it's running in nix and enable patching automatically,
but this detection can have false negatives.

You can also use your nix shell to manage `config.toml`:

```nix
let
config = pkgs.writeText "rustc-config" ''
# Your config.toml content goes here
''
pkgs.mkShell {
/* ... */
# This environment varaible tells bootstrap where our config.toml is.
RUST_BOOTSTRAP_CONFIG = config;
}
```
Expand Down