Skip to content

Commit 35cfe2b

Browse files
committed
docs(readme): Add instructions about building LLVM from source
1 parent f1b285a commit 35cfe2b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,62 @@ cargo install bpf-linker
3333

3434
### Using external LLVM
3535

36+
#### System packages
37+
3638
On Debian based distributions you need to install the `llvm-21-dev`, `libclang-21-dev`
3739
and `libpolly-21-dev` packages, from the official LLVM repo at https://apt.llvm.org.
3840

41+
You may need to build LLVM from source if a recent version is not available
42+
through any package manager that supports your platform.
43+
3944
Once you have installed LLVM 21 you can install the linker running:
4045

4146
```sh
4247
cargo install bpf-linker --no-default-features --features llvm-21
4348
```
4449

50+
#### Building LLVM from source
51+
52+
LLVM can be built from source using the `xtask build-llvm` subcommand, included
53+
in bpf-linker sources.
54+
55+
First, the LLVM sources offered in [our fork][llvm-fork] need to be cloned,
56+
using the branch matching the Rust toolchain you want to use. For current
57+
nightly:
58+
59+
```sh
60+
git clone -b rustc/21.1-2025-08-01 https://github.com/aya-rs/llvm-project ./llvm-project
61+
```
62+
63+
If in doubt about which branch to use, check the LLVM version used by your Rust
64+
compiler:
65+
66+
```sh
67+
rustc [+toolchain] --version -v | grep LLVM
68+
```
69+
70+
When the sources are ready, the LLVM artifacts can be built and installed in
71+
the directory provided in the `--install-prefix` argument, using `--build-dir`
72+
to store the state of the build.
73+
74+
```sh
75+
cargo xtask llvm build \
76+
--src-dir ./llvm-project \
77+
--build-dir ./llvm-build \
78+
--install-prefix ./llvm-install
79+
```
80+
81+
After that, bpf-linker can be built with the `LLVM_SYS_211_PREFIX` environment
82+
variable pointing to that directory:
83+
84+
```sh
85+
LLVM_SYS_211_PREFIX=./llvm-install cargo install --path .
86+
```
87+
4588
If you don't have cargo you can get it from https://rustup.rs or from your distro's package manager.
4689

90+
[llvm-fork]: https://github.com/aya-rs/llvm-project
91+
4792
## Usage
4893

4994
### Rust

0 commit comments

Comments
 (0)