|
| 1 | +## Requirements for `rustc_private` |
| 2 | + |
| 3 | +### Overview |
| 4 | + |
| 5 | +The `rustc-private` feature allows external crates to use compiler internals, but requires specific components to be properly installed. This document explains how to resolve common linker errors related to missing LLVM libraries when working with this feature. |
| 6 | + |
| 7 | +### Using `rustc-private` with Official Toolchains |
| 8 | + |
| 9 | +When using the `rustc_private` feature with official Rust toolchains distributed via rustup, you need to install two additional components: |
| 10 | + |
| 11 | +1. **`rustc-dev`**: Provides compiler libraries |
| 12 | +2. **`llvm-tools`**: Provides LLVM libraries required for linking |
| 13 | + |
| 14 | +#### Installation Steps |
| 15 | + |
| 16 | +Install both components using rustup: |
| 17 | + |
| 18 | +```bash |
| 19 | +rustup component add rustc-dev llvm-tools |
| 20 | +``` |
| 21 | + |
| 22 | +#### Common Error |
| 23 | + |
| 24 | +Without the `llvm-tools` component, you'll encounter linking errors like: |
| 25 | + |
| 26 | +``` |
| 27 | +error: linking with `cc` failed: exit status: 1 |
| 28 | + | |
| 29 | + = note: rust-lld: error: unable to find library -lLLVM-{version} |
| 30 | +``` |
| 31 | + |
| 32 | +### Using `rustc-private` with Custom Toolchains |
| 33 | + |
| 34 | +For custom-built toolchains or environments not using rustup, additional configuration is typically required: |
| 35 | + |
| 36 | +#### Requirements |
| 37 | + |
| 38 | +- LLVM libraries must be available in your system's library search paths |
| 39 | +- The LLVM version must match the one used to build your Rust toolchain |
| 40 | + |
| 41 | +#### Troubleshooting Steps |
| 42 | + |
| 43 | +1. **Check LLVM installation**: Verify LLVM is installed and accessible |
| 44 | +2. **Configure library paths**: You may need to set environment variables: |
| 45 | + ```bash |
| 46 | + export LD_LIBRARY_PATH=/path/to/llvm/lib:$LD_LIBRARY_PATH |
| 47 | + ``` |
| 48 | +3. **Check version compatibility**: Ensure your LLVM version is compatible with your Rust toolchain |
| 49 | + |
| 50 | +### Additional Resources |
| 51 | + |
| 52 | +- [GitHub Issue #137421](https://github.com/rust-lang/rust/issues/137421): Explains that `rustc_private` linker failures often occur because `llvm-tools` is not installed |
0 commit comments