CodeVetter · Repo Unpack · System map
rust-lang/rust
The repo is a Cargo workspace whose members are the rustc binary crate plus ~35 in-tree tools; the compiler proper is ~70 rustc_* crates under compiler/, the standard library is a separate workspace under library/, and src/bootstrap is a self-contained build system excluded from the workspace. The rustc binary is a stub that links rustc_driver as a dylib and calls rustc_driver::main(). The heart of the compiler is the query system defined in compiler/rustc_middle/src/queries.rs and wired together in rustc_interface::passes::DEFAULT_QUERY_PROVIDERS. Build/test orchestration is bootstrap (x.py -> src/bootstrap), and CI is GitHub Actions whose job matrix is computed by the in-tree citool crate from src/ci/github-actions/jobs.yml.
- The root Cargo.toml defines a workspace with members compiler/rustc, src/build_helper, src/rustdoc-json-types, the rustc-std-workspace shims, and ~35 tools under src/tools/ (compiletest, tidy, miri, clippy, rustfmt, opt-dist, etc.); src/bootstrap, compiler/rustc_codegen_cranelift, compiler/rustc_codegen_gcc, and tests/rustdoc-gui are explicitly excluded.
- The rustc binary entrypoint is compiler/rustc/src/main.rs: it uses #![feature(rustc_private)] to link rustc_driver as a dylib, calls rustc_driver::override_c_allocator_in_binary!() so the whole process (including LLVM's C++ allocations) uses jemalloc, and its main() is just rustc_driver::main().
- compiler/rustc_driver is an intentionally empty crate that re-exports rustc_driver_impl so that rustc_driver_impl can be compiled in parallel with the other rustc_* crates.
- rustc_driver_impl::run_compiler is the primary compiler entry point: it expands @-argfiles (args::arg_expand_all), parses options (handle_options), builds session options (config::build_session_options), handles --explain, builds an interface::Config, and calls interface::run_compiler with a callback that runs the whole pipeline.
- rustc_interface::run_compiler sets the parallel/dyn-thread-safe mode, initializes the jobserver, builds the target config, loads the codegen backend (dylib or injected via Config::make_codegen_backend), builds the Session, parses --cfg/--check-cfg, builds the lint store, and runs the caller's closure inside util::run_in_thread_pool_with_globals.
- The compiler is decomposed into ~70 rustc_* crates: rustc_lexer/rustc_parse (lexing/parsing), rustc_ast/rustc_hir (AST/HIR), rustc_expand (macro expansion), rustc_resolve (name resolution), rustc_hir_typeck/rustc_hir_analysis/rustc_trait_selection (type checking/traits), rustc_borrowck, rustc_mir_build/rustc_mir_transform/rustc_mir_dataflow (MIR), rustc_monomorphize, rustc_metadata (rmeta), and rustc_codegen_ssa/rustc_codegen_llvm (codegen).
- The query system is declared in compiler/rustc_middle/src/queries.rs inside rustc_queries proc-macro blocks (implemented in compiler/rustc_macros/src/query.rs), which generate TyCtxt methods, provider structs, caching, and dep-graph integration; the default providers are assembled in rustc_interface::passes::DEFAULT_QUERY_PROVIDERS which calls each subcrate's provide() function.
- Build entry: ./x (sh), x.ps1 (Windows), or x.py all funnel to src/bootstrap/bootstrap.py, which verifies/downloads the stage0 toolchain pinned in src/stage0 (with sha256 verification of downloads), compiles the bootstrap crate, and execs it; the Rust side starts at src/bootstrap/src/bin/main.rs -> bootstrap::cli_main::main -> Flags::parse -> Config::parse.
- Bootstrap staging: stage0 (downloaded beta compiler) builds stage1 rustc+std, stage1 builds stage2; output lives under build/ with downloaded tarballs cached in build/cache; the flow is documented in src/bootstrap/README.md.
- library/ is its own Cargo workspace (library/Cargo.toml, resolver=1) with members std, sysroot, coretests, alloctests; library/sysroot is a dummy crate whose public dependencies (proc_macro, std, test, optional profiler_builtins) force all required crates into the distributed sysroot.
- There are three codegen backends: rustc_codegen_llvm (in-workspace, FFI through compiler/rustc_llvm and the src/llvm-project submodule), and the workspace-excluded subtrees compiler/rustc_codegen_cranelift and compiler/rustc_codegen_gcc.
- CI is GitHub Actions: .github/workflows/ci.yml runs a calculate_matrix job that executes `cargo run --locked calculate-job-matrix` in src/ci/citool over src/ci/github-actions/jobs.yml, then fans out matrix jobs that run src/ci/scripts/run-build-from-ci.sh; a 'bors' GitHub environment with S3/secrets is only attached for automation/bors/* branches.
- Distribution artifacts are produced by bootstrap dist steps (src/bootstrap/src/core/build_steps/dist.rs), packaged via src/tools/rust-installer and src/tools/build-manifest, and uploaded to S3/GitHub artifacts by CI scripts; src/tools/opt-dist performs PGO-optimized builds.