44> transitions. In particular, we want to get to a point eventually where the
55> top-level directory has separate directories for the compiler, build-system,
66> std libs, etc, rather than one huge ` src/ ` directory.
7+ >
8+ > As of this writing, the std libs have been moved to ` library/ ` and there is
9+ > an ongoing MCP to move the compiler to ` compiler/ ` .
710
811Now that we have [ seen what the compiler does] ( ./overview.md ) , let's take a
912look at the structure of the contents of the rust-lang/rust repo.
1013
1114## Workspace structure
1215
1316The ` rust-lang/rust ` repository consists of a single large cargo workspace
14- containing the compiler, the standard library ( core, alloc, std, etc), and
15- ` rustdoc ` , along with the build system and bunch of tools and submodules for
16- building a full Rust distribution.
17+ containing the compiler, the standard libraries ( ` core ` , ` alloc ` , ` std ` ,
18+ ` proc_macro ` , etc), and ` rustdoc ` , along with the build system and bunch of
19+ tools and submodules for building a full Rust distribution.
1720
1821As of this writing, this structure is gradually undergoing some transformation
1922to make it a bit less monolithic and more approachable, especially to
2023newcommers.
2124
22- > Eventually, the hope is for the standard library to live in a ` stdlib/ `
23- > directory, while the compiler lives in ` compiler/ ` . However, as of this
24- > writing, both live in ` src/ ` .
25-
2625The repository consists of a ` src ` directory, under which there live many
27- crates, which are the source for the compiler, standard library, etc, as
28- mentioned above.
26+ crates, which are the source for the compiler, build system, tools, etc. This
27+ directory is currently being broken up to be less monolithic. There is also a
28+ ` library/ ` directory, where the standard libraries (` core ` , ` alloc ` , ` std ` ,
29+ ` proc_macro ` , etc) live.
2930
3031## Standard library
3132
32- The standard library crates are obviously named ` libstd ` , ` libcore ` ,
33- ` liballoc ` , etc. There is also ` libproc_macro ` , ` libtest ` , and other runtime
34- libraries.
33+ The standard library crates are all in ` library/ ` . They have intuitive names
34+ like ` std ` , ` core ` , ` alloc ` , etc. There is also ` proc_macro ` , ` test ` , and
35+ other runtime libraries.
3536
3637This code is fairly similar to most other Rust crates except that it must be
3738built in a special way because it can use unstable features.
@@ -41,11 +42,16 @@ built in a special way because it can use unstable features.
4142> You may find it helpful to read [ The Overview Chapter] ( ./overview.md ) first,
4243> which gives an overview of how the compiler works. The crates mentioned in
4344> this section implement the compiler.
45+ >
46+ > NOTE: As of this writing, the crates all live in ` src/ ` , but there is an MCP
47+ > to move them to a new ` compiler/ ` directory.
4448
45- The compiler crates all have names starting with ` librustc_* ` . These are a large
46- collection of interdependent crates. There is also the ` rustc ` crate which is
47- the actual binary. It doesn't actually do anything besides calling the compiler
48- main function elsewhere.
49+ The compiler crates all have names starting with ` librustc_* ` . These are a
50+ collection of around 50 interdependent crates ranging in size from tiny to
51+ huge. There is also the ` rustc ` crate which is the actual binary (i.e. the
52+ ` main ` function); it doesn't actually do anything besides calling the
53+ ` rustc_driver ` crate, which drives the various parts of compilation in other
54+ crates.
4955
5056The dependency structure of these crates is complex, but roughly it is
5157something like this:
@@ -55,7 +61,7 @@ something like this:
5561 [ ` rustc_interface ` ] .
5662 - [ ` rustc_interface ` ] depends on most of the other compiler crates. It
5763 is a fairly generic interface for driving the whole compilation.
58- - The most of the other ` rustc_* ` crates depend on [ ` rustc_middle ` ] ,
64+ - Most of the other ` rustc_* ` crates depend on [ ` rustc_middle ` ] ,
5965 which defines a lot of central data structures in the compiler.
6066 - [ ` rustc_middle ` ] and most of the other crates depend on a
6167 handful of crates representing the early parts of the
@@ -75,12 +81,17 @@ something like this:
7581You can see the exact dependencies by reading the ` Cargo.toml ` for the various
7682crates, just like a normal Rust crate.
7783
78- One final thing: [ ` src/llvm-project ` ] is a submodule for our fork of LLVM.
84+ One final thing: [ ` src/llvm-project ` ] is a submodule for our fork of LLVM
85+ During bootstrapping, LLVM is built and the [ ` src/librustc_llvm ` ] and
86+ [ ` src/rustllvm ` ] crates contain rust wrappers around LLVM (which is written in
87+ C++), so that the compiler can interface with it.
7988
8089Most of this book is about the compiler, so we won't have any further
8190explanation of these crates here.
8291
8392[ `src/llvm-project` ] : https://github.com/rust-lang/rust/tree/master/src
93+ [ `src/librustc_llvm` ] : https://github.com/rust-lang/rust/tree/master/src
94+ [ `src/rustllvm` ] : https://github.com/rust-lang/rust/tree/master/src
8495
8596### Big picture
8697
0 commit comments