Skip to content

Commit fe99fa1

Browse files
committed
ebpf: run clippy with target=bpf
This build warnings from integration tests and makes `aya-ebpf`'s build script stricter.
1 parent 552b693 commit fe99fa1

File tree

7 files changed

+49
-20
lines changed

7 files changed

+49
-20
lines changed

aya-log-common/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#![cfg_attr(
2+
target_arch = "bpf",
3+
expect(unused_crate_dependencies, reason = "compiler_builtins")
4+
)]
15
#![no_std]
26

37
use core::{

clippy.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
set -eux
44

5+
cargo +nightly hack clippy \
6+
--target bpfel-unknown-none -Zbuild-std=core \
7+
--package aya-ebpf-bindings \
8+
--package aya-ebpf \
9+
--package aya-log-ebpf \
10+
--package integration-ebpf \
11+
--feature-powerset \
12+
-- --deny warnings
13+
514
# `-C panic=abort` because "unwinding panics are not supported without std"; integration-ebpf
615
# contains `#[no_std]` binaries.
716
#
@@ -11,4 +20,9 @@ set -eux
1120
# unwinding behavior.
1221
#
1322
# `+nightly` because "the option `Z` is only accepted on the nightly compiler".
14-
cargo +nightly hack clippy "$@" --all-targets --feature-powerset -- --deny warnings -C panic=abort -Zpanic_abort_tests
23+
cargo +nightly hack clippy "$@" \
24+
--all-targets \
25+
--feature-powerset \
26+
-- --deny warnings \
27+
-C panic=abort \
28+
-Zpanic_abort_tests

ebpf/aya-ebpf-bindings/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#![cfg_attr(
2+
target_arch = "bpf",
3+
expect(unused_crate_dependencies, reason = "compiler_builtins")
4+
)]
15
#![expect(
26
clippy::all,
37
clippy::cast_lossless,

ebpf/aya-ebpf/build.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
use std::env;
2-
31
fn main() {
4-
check_rust_version();
52
println!("cargo:rerun-if-env-changed=CARGO_CFG_BPF_TARGET_ARCH");
6-
if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") {
7-
println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
8-
} else {
9-
let arch = env::var("HOST").unwrap();
10-
let mut arch = arch.split_once('-').map_or(&*arch, |x| x.0);
11-
if arch.starts_with("riscv64") {
12-
arch = "riscv64";
13-
}
14-
println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
15-
}
3+
println!("cargo:rerun-if-env-changed=HOST");
4+
165
print!("cargo::rustc-check-cfg=cfg(bpf_target_arch, values(");
176
for arch in [
187
"aarch64",
@@ -28,7 +17,20 @@ fn main() {
2817
}
2918
println!("))");
3019

20+
if let Some(arch) = std::env::var_os("CARGO_CFG_BPF_TARGET_ARCH") {
21+
let arch = arch.to_str().unwrap();
22+
println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
23+
} else if let Some(host) = std::env::var_os("HOST") {
24+
let host = host.to_str().unwrap();
25+
let mut arch = host.split_once('-').map_or(host, |(arch, _rest)| arch);
26+
if arch.starts_with("riscv64") {
27+
arch = "riscv64";
28+
}
29+
println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
30+
}
31+
3132
println!("cargo::rustc-check-cfg=cfg(generic_const_exprs)");
33+
check_rust_version();
3234
}
3335

3436
#[rustversion::nightly]

ebpf/aya-ebpf/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88
html_logo_url = "https://aya-rs.dev/assets/images/crabby.svg",
99
html_favicon_url = "https://aya-rs.dev/assets/images/crabby.svg"
1010
)]
11-
// TODO(https://github.com/rust-lang/rust/issues/141492): reenable this.
1211
#![cfg_attr(
1312
generic_const_exprs,
1413
expect(incomplete_features),
14+
expect(unstable_features),
1515
feature(generic_const_exprs)
1616
)]
17-
#![cfg_attr(target_arch = "bpf", feature(asm_experimental_arch))]
17+
#![cfg_attr(
18+
target_arch = "bpf",
19+
expect(unused_crate_dependencies, reason = "compiler_builtins"),
20+
expect(unstable_features),
21+
feature(asm_experimental_arch)
22+
)]
1823
#![warn(clippy::cast_lossless, clippy::cast_sign_loss)]
1924
#![no_std]
2025

@@ -65,7 +70,6 @@ pub trait EbpfContext {
6570
}
6671
}
6772

68-
#[cfg_attr(target_arch = "bpf", expect(clippy::missing_safety_doc))]
6973
mod intrinsics {
7074
use super::cty::c_int;
7175

ebpf/aya-log-ebpf/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,3 @@ workspace = true
1717
aya-ebpf = { version = "^0.1.1", path = "../aya-ebpf" }
1818
aya-log-common = { version = "^0.1.15", path = "../../aya-log-common" }
1919
aya-log-ebpf-macros = { version = "^0.1.0", path = "../../aya-log-ebpf-macros" }
20-
21-
[lib]
22-
path = "src/lib.rs"

ebpf/aya-log-ebpf/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#![cfg_attr(
2+
target_arch = "bpf",
3+
expect(unused_crate_dependencies, reason = "compiler_builtins")
4+
)]
15
#![no_std]
26
#![warn(clippy::cast_lossless, clippy::cast_sign_loss)]
37

0 commit comments

Comments
 (0)