rust-lang/rust
Other runtime crates
The library/ directory contains many crates besides core/alloc/std. Most of them are runtime support — code that lives in the sysroot but isn't typically used directly.
proc_macro
library/proc_macro/ is the public surface of procedural macros: TokenStream, Span, TokenTree, Group, Punct, Ident, Literal, plus the pub fn proc_macro_derive machinery.
Proc macros run as separate processes sandboxed by the compiler. The protocol — encoding TokenStreams and replies across the rustc/proc-macro process boundary — is implemented as a bridge between this crate (consumer side) and compiler/rustc_proc_macro/ (server side). The user-facing API stays stable; the bridge is internal.
test
library/test/ is Rust's built-in test harness — what cargo test uses. Provides:
- The
#[test]attribute (the attribute is compiler-handled; this crate provides the runtime) - The default
mainfor#[test]binaries - The
BencherAPI for#[bench](still unstable) - Output formatting (pretty, terse, JSON, JUnit)
- Filter / shuffle / parallel test running
Most users never extern crate test; directly; they just write #[test] fn .... The compiler injects the harness for them.
panic_unwind / panic_abort
Two implementations of the panic_handler runtime:
library/panic_unwind/— unwinds the stack on panic, calling destructors. Useslibrary/unwind/under the hood.library/panic_abort/— aborts on panic. Smaller binaries, no unwinding bookkeeping in codegen.
Selected at link time via panic = "unwind" or panic = "abort" in the profile.
unwind
library/unwind/ is the FFI to the system unwinder:
- Linux/BSD:
libgcc_sorlibunwind - macOS:
libunwind(Apple) - Windows: SEH (uses MSVC intrinsics)
- Bare-metal: a custom unwinder linked separately
This crate provides _Unwind_RaiseException, _Unwind_Backtrace, etc., normalized across platforms. panic_unwind calls into here.
compiler-builtins
library/compiler-builtins/ (vendored subtree from rust-lang/compiler-builtins) implements low-level intrinsics the compiler may emit calls to:
- 64-bit math on 32-bit targets (
__udivdi3,__umoddi3, …) - Soft-float operations (
__addsf3,__multf3, …) - Memory operations (
memcpy,memset,memcmp,memmove) whenlibcisn't available
It's a Rust port of LLVM's compiler-rt. Linked into every Rust program; on most platforms its symbols are weak so they don't conflict with libc's.
profiler_builtins
library/profiler_builtins/ is the Rust-side wrapper over LLVM's profile runtime — used for source-based code coverage (-Cinstrument-coverage). Built only when profiling is enabled.
stdarch
library/stdarch/ (vendored subtree from rust-lang/stdarch) provides architecture-specific SIMD and intrinsic types:
core::arch::x86,core::arch::x86_64— Intel/AMD intrinsics (_mm_add_ps, …)core::arch::aarch64— ARM NEONcore::arch::wasm32— WebAssembly SIMDcore::arch::riscv64,core::arch::powerpc64, … — many architectures
The core::arch::* module re-exports come from this crate. Most of the content is generated from architecture vendor headers.
portable-simd
library/portable-simd/ (vendored subtree from rust-lang/portable-simd) provides core::simd::* — portable SIMD types (Simd<f32, 4>, Mask<i32, 8>) that compile to native SIMD on each target. Still unstable; the design is being iterated.
backtrace
library/backtrace/ (vendored subtree from rust-lang/backtrace-rs) provides the underlying backtrace functionality re-exported as std::backtrace::Backtrace. It walks the unwinder, symbolicates frames against debug info, and formats them. Platform-specific backends (gimli, libbacktrace, Windows DbgHelp).
rtstartup
library/rtstartup/ is runtime startup glue — tiny pieces of code that run before main to set up things like the panic handler, signal handlers, the global allocator hook, etc. It contains both Rust-callable and C-callable entry points. Used on bare-metal and platforms that don't have a libc-like crt0.
sysroot
library/sysroot/ is a meta-crate that depends on every other library that needs to be in the sysroot. It exists so bootstrap can build the entire sysroot in one Cargo invocation. There's almost no code in it — just Cargo.toml and a one-line lib.rs.
std_detect
library/std_detect/ provides runtime CPU feature detection (is_x86_feature_detected!, is_aarch64_feature_detected!, …). Used by SIMD-using crates that want to gracefully fall back when AVX2 isn't available.
windows_link
library/windows_link/ is a very small crate (a single macro) used by std's Windows backend to declare extern symbols imported from system DLLs. It exists to avoid pulling in the windows-sys crate's heavier set of bindings into the standard library.
rustc-std-workspace-{core,alloc,std}
library/rustc-std-workspace-core/, …-alloc/, …-std/ are tiny shim crates used to make external crates that want to depend on core/alloc/std via crates.io work in the rustc workspace. They're an artifact of how Cargo and rustc handle the standard library at build time. Don't worry about them unless you're adding a new external dependency to the standard library.
How they fit together
graph TD
Cb[compiler-builtins] --> Core
Core[core] --> Alloc
Core --> Stdarch[stdarch]
Core --> Portable[portable-simd]
Alloc --> Std
Pa[panic_abort] -.alternative.-> Std
Pu[panic_unwind] --> Unw[unwind]
Pu --> Std
Bt[backtrace] --> Std
Sd[std_detect] --> Std
Pm[proc_macro] --> Std
Test[test] --> Std
Sysroot[sysroot] --> Std
Sysroot --> Pm
Sysroot --> Test
Pb[profiler_builtins] -.optional.-> StdSee also
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.