Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 28fd922

Browse files
committed
Support LLVM14
Signed-off-by: Nikita Baksalyar <[email protected]>
1 parent 62fb6fb commit 28fd922

File tree

6 files changed

+45
-21
lines changed

6 files changed

+45
-21
lines changed

Cargo.lock

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ programs using Rust. It includes:
6363

6464
`LLVM` is required in your build system to compile BPF bytecode using RedBPF.
6565

66-
- **LLVM 13**
67-
It is needed to compile BPF bytecode.
66+
- **LLVM 14 or 13**
67+
It is needed to compile BPF bytecode. If you're using Rust 1.60 or later, LLVM 14 is required.
68+
If you need to use LLVM 13, use the feature `llvm13-0`.
6869

6970
- One of the followings:
7071
1. The Linux kernel headers
@@ -74,7 +75,7 @@ programs using Rust. It includes:
7475

7576
### On Ubuntu 20.04 LTS
7677

77-
Install LLVM 13 and the Linux kernel headers
78+
Install LLVM 14 and the Linux kernel headers
7879
```console
7980
# apt-get update \
8081
&& apt-get -y install \
@@ -85,12 +86,15 @@ Install LLVM 13 and the Linux kernel headers
8586
libelf-dev \
8687
linux-headers-generic \
8788
pkg-config \
88-
&& wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh 13 && rm -f ./llvm.sh
89-
# llvm-config-13 --version | grep 13
89+
&& wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh 14 && rm -f ./llvm.sh
90+
# llvm-config-14 --version | grep 14
9091
```
9192

9293
### On Fedora 35
9394

95+
Currently, only LLVM 13 is available in the official Fedora repositories.
96+
Consider building LLVM from source until Fedora 36 is released.
97+
9498
Install LLVM 13 and the Linux kernel headers
9599
```console
96100
# dnf install -y \
@@ -126,25 +130,28 @@ Install LLVM 13 and the Linux kernel headers
126130
# llvm-config --version | grep -q '^13'
127131
```
128132

133+
At the time of writing, LLVM 14 is not available in the official package repository.
134+
If you need to use Rust 1.60 or later, please build LLVM from source.
135+
129136
### Building LLVM from source
130137

131138
If your Linux distro does not support the latest LLVM as pre-built packages
132139
yet, you may build LLVM from the LLVM source code.
133140

134141
```console
135-
$ tar -xaf llvm-13.0.0.src.tar.xz
136-
$ mkdir -p llvm-13.0.0.src/build
137-
$ cd llvm-13.0.0.src/build
138-
$ cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/llvm-13-release -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_LLVM_DYLIB=1
142+
$ tar -xaf llvm-14.0.0.src.tar.xz
143+
$ mkdir -p llvm-14.0.0.src/build
144+
$ cd llvm-14.0.0.src/build
145+
$ cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/llvm-14-release -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_LLVM_DYLIB=1
139146
$ cmake --build . --target install
140147
```
141148

142149
Then you can use your LLVM by specifying the custom installation path when
143150
installing `cargo-bpf` or building RedBPF like this:
144151

145152
```console
146-
$ LLVM_SYS_130_PREFIX=$HOME/llvm-13-release/ cargo install cargo-bpf
147-
$ LLVM_SYS_130_PREFIX=$HOME/llvm-13-release/ cargo build
153+
$ LLVM_SYS_140_PREFIX=$HOME/llvm-14-release/ cargo install cargo-bpf
154+
$ LLVM_SYS_140_PREFIX=$HOME/llvm-14-release/ cargo build
148155
```
149156

150157
Make sure correct `-DCMAKE_BUILD_TYPE` is specified. Typically `Debug` type is
@@ -235,7 +242,8 @@ There are two LLVM versions involved in compiling BPF programs:
235242

236243
| Rust version | LLVM version of the rustc | Valid LLVM version of system |
237244
|:-------------|:-------------------------:|:-----------------------------|
238-
| 1.56 ~ | LLVM 13 | LLVM 13 and newer |
245+
| 1.56 ~ 1.60 | LLVM 13 | LLVM 13 and newer |
246+
| 1.60 ~ | LLVM 14 | LLVM 14 and newer |
239247

240248
## Docker images for RedBPF build test
241249

TUTORIAL.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ For some reasons, you may want to build LLVM from source code.
4545

4646
When you build LLVM, consider building LLVM with `Release` build mode.
4747

48-
For example, when you build LLVM13 from source code, you can pass
48+
For example, when you build LLVM14 from source code, you can pass
4949
`-DCMAKE_BUILD_TYPE=Release` to the `cmake` command as below:
5050

5151
```console
52-
$ tar -xaf llvm-13.0.0.src.tar.xz
53-
$ mkdir -p llvm-13.0.0.src/build
54-
$ cd llvm-13.0.0.src/build
55-
$ cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/llvm-13-release -DCMAKE_BUILD_TYPE=Release
52+
$ tar -xaf llvm-14.0.0.src.tar.xz
53+
$ mkdir -p llvm-14.0.0.src/build
54+
$ cd llvm-14.0.0.src/build
55+
$ cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/llvm-14-release -DCMAKE_BUILD_TYPE=Release
5656
$ cmake --build . --target install
5757
```
5858

cargo-bpf/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ anyhow = "1.0"
3939
# if `strict-versioning` feature is off, llvm-sys-130 can be linked to
4040
# libLLVM13 and newer libraries.
4141
llvm-sys-130 = { version = "130", optional = true, package = "llvm-sys" }
42+
llvm-sys-140 = { version = "140", optional = true, package = "llvm-sys" }
4243
cfg-if = "1.0"
4344
rustversion = "1.0"
4445
rustc_version = "0.4.0"
@@ -53,11 +54,12 @@ cfg-if = "1.0.0"
5354
default = ["command-line", "llvm-sys"]
5455
bindings = ["libbpf-sys", "bpf-sys", "bindgen", "syn", "quote", "proc-macro2", "tempfile"]
5556
build = ["bindings", "libc", "toml_edit", "redbpf"]
56-
docsrs-llvm = ["llvm-sys-130/no-llvm-linking", "llvm-sys-130/disable-alltargets-init"]
57+
docsrs-llvm = ["llvm-sys-140/no-llvm-linking", "llvm-sys-140/disable-alltargets-init"]
5758
build-c = []
5859
command-line = ["build", "clap", "redbpf/load", "futures", "tokio", "hexdump"]
59-
llvm-sys = ["llvm-sys-130"] # Use current default LLVM version or higher
60+
llvm-sys = ["llvm-sys-140"] # Use current default LLVM version or higher
6061
llvm13 = ["llvm-sys-130"]
62+
llvm14 = ["llvm-sys-140"]
6163

6264
[package.metadata.docs.rs]
6365
all-features = false

cargo-bpf/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn print_cargo_bpf_llvm_version() {
5656

5757
fn main() {
5858
cfg_if::cfg_if! {
59-
if #[cfg(all(feature = "llvm-sys-130", not(feature = "docsrs-llvm")))] {
59+
if #[cfg(all(any(feature = "llvm-sys-130", feature = "llvm-sys-140"), not(feature = "docsrs-llvm")))] {
6060
print_cargo_bpf_llvm_version();
6161
} else {
6262
println!("cargo:rustc-env=CARGO_BPF_LLVM_VERSION=0.0.0");

cargo-bpf/src/llvm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ second.
2222
cfg_if::cfg_if! {
2323
if #[cfg(feature = "llvm-sys-130")] {
2424
use llvm_sys_130 as llvm_sys;
25+
} else if #[cfg(feature = "llvm-sys-140")] {
26+
use llvm_sys_140 as llvm_sys;
2527
} else {
2628
compile_error!("Specify --features llvm13");
2729
}

0 commit comments

Comments
 (0)