Skip to content

Commit 59de3a0

Browse files
jyn514Joshua Nelson
authored andcommitted
Document what 'sysroot' means
1 parent eb8fefb commit 59de3a0

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/appendix/glossary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Term | Meaning
7272
<span id="soundness">soundness</span> | A technical term in type theory. Roughly, if a type system is sound, then a program that type-checks is type-safe. That is, one can never (in safe rust) force a value into a variable of the wrong type. (see "completeness").
7373
<span id="span">span</span> | A location in the user's source code, used for error reporting primarily. These are like a file-name/line-number/column tuple on steroids: they carry a start/end point, and also track macro expansions and compiler desugaring. All while being packed into a few bytes (really, it's an index into a table). See the Span datatype for more.
7474
<span id="substs">substs</span> | The substitutions for a given generic type or item (e.g. the `i32`, `u32` in `HashMap<i32, u32>`).
75+
<span id="sysroot">sysroot</span> | The directory for build artifacts that are loaded by the compiler at runtime. ([see more](../building/bootstrapping.html#what-is-a-sysroot))
7576
<span id="tag">Tag</span> | The "tag" of an enum/generator encodes the [discriminant](#discriminant) of the active variant/state. Tags can either be "direct" (simply storing the discriminant in a field) or use a ["niche"](#niche).
7677
<span id="tcx">tcx</span> | The "typing context", main data structure of the compiler. ([see more](../ty.md))
7778
<span id="lifetime-tcx">`'tcx`</span> | The lifetime of the allocation arena. ([see more](../ty.md))

src/building/bootstrapping.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,65 @@ is built by the _beta_ compiler, but using the _master_ version of libstd!
264264
The only time `rustc` uses `cfg(bootstrap)` is when it adds internal lints
265265
that use diagnostic items. This happens very rarely.
266266

267+
### What is a 'sysroot'?
268+
269+
When you build a project with cargo, the build artifacts for dependendencies
270+
are normally stored in `target/debug/deps`. This only contains dependencies cargo
271+
knows about; in particular, it doesn't have the standard library. Where do
272+
`std` or `proc_macro` come from? It comes from the **sysroot**, the root
273+
of a number of directories where the compiler loads build artifacts at runtime.
274+
The sysroot doesn't just store the standard library, though - it includes
275+
anything that needs to be loaded at runtime. That includes (but is not limited
276+
to):
277+
278+
- `libstd`/`libtest`/`libproc_macro`
279+
- The compiler crates themselves, when using `rustc_private`. In-tree these
280+
are always present; out of tree, you need to install `rustc-dev` with rustup.
281+
- `libLLVM.so`, the shared object file for the LLVM project. In-tree this is
282+
either built from source or downloaded from CI; out-of-tree, you need to
283+
install `llvm-tools-preview` with rustup.
284+
285+
All the artifacts listed so far are *compiler* runtime dependencies. You can
286+
see them with `rustc --print sysroot`:
287+
288+
```
289+
$ ls $(rustc --print sysroot)/lib
290+
libchalk_derive-0685d79833dc9b2b.so libstd-25c6acf8063a3802.so
291+
libLLVM-11-rust-1.50.0-nightly.so libtest-57470d2aa8f7aa83.so
292+
librustc_driver-4f0cc9f50e53f0ba.so libtracing_attributes-e4be92c35ab2a33b.so
293+
librustc_macros-5f0ec4a119c6ac86.so rustlib
294+
```
295+
296+
There are also runtime dependencies for the standard library! These are in
297+
`lib/rustlib`, not `lib/` directly.
298+
299+
```
300+
$ ls $(rustc --print sysroot)/lib/rustlib/x86_64-unknown-linux-gnu/lib | head -n 5
301+
libaddr2line-6c8e02b8fedc1e5f.rlib
302+
libadler-9ef2480568df55af.rlib
303+
liballoc-9c4002b5f79ba0e1.rlib
304+
libcfg_if-512eb53291f6de7e.rlib
305+
libcompiler_builtins-ef2408da76957905.rlib
306+
```
307+
308+
`rustlib` includes libraries like `hashbrown` and `cfg_if`, which are not part
309+
of the public API of the standard library, but are used to implement it.
310+
`rustlib` is part of the search path for linkers, but `lib` will never be part
311+
of the search path.
312+
313+
Since `rustlib` is part of the search path, it means we have to be careful
314+
about which crates are included in it. In particular, all crates except for
315+
the standard library are built with the flag `-Z force-unstable-if-unmarked`,
316+
which means that you have to use `#![feature(rustc_private)]` in order to
317+
load it (as opposed to the standard library, which is always available).
318+
319+
You can find more discussion about sysroots in:
320+
- The [rustdoc PR] explaining why it uses `extern crate` for dependencies loaded from sysroot
321+
- [Discussions about sysroot on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/deps.20in.20sysroot/)
322+
- [Discussions about building rustdoc out of tree](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20to.20create.20an.20executable.20accessing.20.60rustc_private.60.3F)
323+
324+
[rustdoc PR]: https://github.com/rust-lang/rust/pull/76728
325+
267326
### Directories and artifacts generated by x.py
268327

269328
The following tables indicate the outputs of various stage actions:

0 commit comments

Comments
 (0)