4
4
> transitions. In particular, we want to get to a point eventually where the
5
5
> top-level directory has separate directories for the compiler, build-system,
6
6
> 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/ ` .
7
10
8
11
Now that we have [ seen what the compiler does] ( ./overview.md ) , let's take a
9
12
look at the structure of the contents of the rust-lang/rust repo.
10
13
11
14
## Workspace structure
12
15
13
16
The ` 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.
17
20
18
21
As of this writing, this structure is gradually undergoing some transformation
19
22
to make it a bit less monolithic and more approachable, especially to
20
23
newcommers.
21
24
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
-
26
25
The 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.
29
30
30
31
## Standard library
31
32
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.
35
36
36
37
This code is fairly similar to most other Rust crates except that it must be
37
38
built 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.
41
42
> You may find it helpful to read [ The Overview Chapter] ( ./overview.md ) first,
42
43
> which gives an overview of how the compiler works. The crates mentioned in
43
44
> 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.
44
48
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.
49
55
50
56
The dependency structure of these crates is complex, but roughly it is
51
57
something like this:
@@ -55,7 +61,7 @@ something like this:
55
61
[ ` rustc_interface ` ] .
56
62
- [ ` rustc_interface ` ] depends on most of the other compiler crates. It
57
63
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 ` ] ,
59
65
which defines a lot of central data structures in the compiler.
60
66
- [ ` rustc_middle ` ] and most of the other crates depend on a
61
67
handful of crates representing the early parts of the
@@ -75,12 +81,17 @@ something like this:
75
81
You can see the exact dependencies by reading the ` Cargo.toml ` for the various
76
82
crates, just like a normal Rust crate.
77
83
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.
79
88
80
89
Most of this book is about the compiler, so we won't have any further
81
90
explanation of these crates here.
82
91
83
92
[ `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
84
95
85
96
### Big picture
86
97
0 commit comments