From 56ebe1406e088dc52d7c796be725df74356fcad8 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 4 Mar 2025 11:20:06 -0500 Subject: [PATCH] aya-tool: do not attempt to run rustfmt This can be done externally. Do so in CI. This is an attempt to resolve the inconsistency between CI and local rustfmt in the generated bindings. Restore running CI on generated branches; the presence of a PR is apparently not enough. --- .github/workflows/ci.yml | 37 +++++++------------ .github/workflows/gen.yml | 1 + .../src/generated/linux_bindings_aarch64.rs | 6 +-- aya-obj/src/generated/linux_bindings_armv7.rs | 6 +-- aya-obj/src/generated/linux_bindings_mips.rs | 6 +-- .../src/generated/linux_bindings_powerpc64.rs | 6 +-- .../src/generated/linux_bindings_riscv64.rs | 6 +-- aya-obj/src/generated/linux_bindings_s390x.rs | 6 +-- .../src/generated/linux_bindings_x86_64.rs | 6 +-- aya-tool/src/generate.rs | 3 -- aya-tool/src/lib.rs | 5 --- aya-tool/src/rustfmt.rs | 26 ------------- .../aya-ebpf-bindings/src/aarch64/bindings.rs | 6 +-- ebpf/aya-ebpf-bindings/src/armv7/bindings.rs | 6 +-- ebpf/aya-ebpf-bindings/src/mips/bindings.rs | 6 +-- .../src/powerpc64/bindings.rs | 6 +-- .../aya-ebpf-bindings/src/riscv64/bindings.rs | 6 +-- ebpf/aya-ebpf-bindings/src/s390x/bindings.rs | 6 +-- ebpf/aya-ebpf-bindings/src/x86_64/bindings.rs | 6 +-- xtask/src/codegen/aya_ebpf_bindings.rs | 6 +-- 20 files changed, 32 insertions(+), 130 deletions(-) delete mode 100644 aya-tool/src/rustfmt.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21324c83..99bbeb0c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,6 @@ name: aya-ci on: push: - branches-ignore: 'create-pull-request/**' pull_request: @@ -32,20 +31,15 @@ jobs: with: tool: cargo-hack,taplo-cli - - name: Check C formatting - run: git ls-files -- '*.c' '*.h' | xargs clang-format --dry-run --Werror + - run: git ls-files -- '*.c' '*.h' | xargs clang-format --dry-run --Werror - - name: Check Markdown - uses: DavidAnson/markdownlint-cli2-action@v19 + - uses: DavidAnson/markdownlint-cli2-action@v19 - - name: Check TOML formatting - run: taplo fmt --check + - run: taplo fmt --check - - name: Check formatting - run: cargo +nightly fmt --all -- --check + - run: cargo +nightly fmt --all -- --check - - name: Run clippy - run: ./clippy.sh + - run: ./clippy.sh - run: cargo xtask public-api if: github.event_name == 'pull_request' @@ -161,10 +155,10 @@ jobs: - uses: Swatinem/rust-cache@v2 - - name: bpf-linker - run: cargo install --git https://github.com/aya-rs/bpf-linker.git + - run: cargo install --git https://github.com/aya-rs/bpf-linker.git - uses: taiki-e/install-action@cargo-hack + - name: Build env: CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }} @@ -278,15 +272,13 @@ jobs: tar -xJ --strip-components 2 -C /tmp/rustc-llvm echo /tmp/rustc-llvm/bin >> $GITHUB_PATH - - name: bpf-linker - # NB: rustc doesn't ship libLLVM.so on macOS, so disable proxying (default feature). We also - # --force so that bpf-linker gets always relinked against the latest LLVM downloaded above. - # - # Do this on all system (not just macOS) to avoid relying on rustc-provided libLLVM.so. - run: cargo install --git https://github.com/aya-rs/bpf-linker.git --no-default-features --force + # NB: rustc doesn't ship libLLVM.so on macOS, so disable proxying (default feature). We also + # --force so that bpf-linker gets always relinked against the latest LLVM downloaded above. + # + # Do this on all system (not just macOS) to avoid relying on rustc-provided libLLVM.so. + - run: cargo install --git https://github.com/aya-rs/bpf-linker.git --no-default-features --force - - name: Cache test cache - uses: actions/cache@v4 + - uses: actions/cache@v4 with: path: test/.tmp key: ${{ runner.arch }}-${{ runner.os }}-test-cache @@ -329,5 +321,4 @@ jobs: - run-integration-test runs-on: ubuntu-latest steps: - - name: Build Complete - run: echo "Build Complete" + - run: echo 'Build Complete' diff --git a/.github/workflows/gen.yml b/.github/workflows/gen.yml index 4bd0b65c..10e79c86 100644 --- a/.github/workflows/gen.yml +++ b/.github/workflows/gen.yml @@ -32,6 +32,7 @@ jobs: - run: cargo xtask codegen - run: cargo xtask public-api --bless + - run: cargo fmt --all - run: echo "LIBBPF_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV working-directory: xtask/libbpf diff --git a/aya-obj/src/generated/linux_bindings_aarch64.rs b/aya-obj/src/generated/linux_bindings_aarch64.rs index 322e41a2..d480cbdb 100644 --- a/aya-obj/src/generated/linux_bindings_aarch64.rs +++ b/aya-obj/src/generated/linux_bindings_aarch64.rs @@ -47,11 +47,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/aya-obj/src/generated/linux_bindings_armv7.rs b/aya-obj/src/generated/linux_bindings_armv7.rs index aca260bb..27b72036 100644 --- a/aya-obj/src/generated/linux_bindings_armv7.rs +++ b/aya-obj/src/generated/linux_bindings_armv7.rs @@ -47,11 +47,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/aya-obj/src/generated/linux_bindings_mips.rs b/aya-obj/src/generated/linux_bindings_mips.rs index 5a8b7d28..8ffc7bfc 100644 --- a/aya-obj/src/generated/linux_bindings_mips.rs +++ b/aya-obj/src/generated/linux_bindings_mips.rs @@ -47,11 +47,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/aya-obj/src/generated/linux_bindings_powerpc64.rs b/aya-obj/src/generated/linux_bindings_powerpc64.rs index 95b943b9..1da9d586 100644 --- a/aya-obj/src/generated/linux_bindings_powerpc64.rs +++ b/aya-obj/src/generated/linux_bindings_powerpc64.rs @@ -47,11 +47,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/aya-obj/src/generated/linux_bindings_riscv64.rs b/aya-obj/src/generated/linux_bindings_riscv64.rs index 322e41a2..d480cbdb 100644 --- a/aya-obj/src/generated/linux_bindings_riscv64.rs +++ b/aya-obj/src/generated/linux_bindings_riscv64.rs @@ -47,11 +47,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/aya-obj/src/generated/linux_bindings_s390x.rs b/aya-obj/src/generated/linux_bindings_s390x.rs index 322e41a2..d480cbdb 100644 --- a/aya-obj/src/generated/linux_bindings_s390x.rs +++ b/aya-obj/src/generated/linux_bindings_s390x.rs @@ -47,11 +47,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/aya-obj/src/generated/linux_bindings_x86_64.rs b/aya-obj/src/generated/linux_bindings_x86_64.rs index 322e41a2..d480cbdb 100644 --- a/aya-obj/src/generated/linux_bindings_x86_64.rs +++ b/aya-obj/src/generated/linux_bindings_x86_64.rs @@ -47,11 +47,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/aya-tool/src/generate.rs b/aya-tool/src/generate.rs index bd55a6e0..2d5b2a9c 100644 --- a/aya-tool/src/generate.rs +++ b/aya-tool/src/generate.rs @@ -25,9 +25,6 @@ pub enum Error { #[error("{stderr}\nbindgen failed with exit code {code}")] BindgenExit { code: i32, stderr: String }, - #[error("rustfmt failed")] - Rustfmt(#[source] io::Error), - #[error("error reading header file")] ReadHeaderFile(#[source] io::Error), } diff --git a/aya-tool/src/lib.rs b/aya-tool/src/lib.rs index 0f35973d..a132ac19 100644 --- a/aya-tool/src/lib.rs +++ b/aya-tool/src/lib.rs @@ -6,7 +6,6 @@ use std::{ pub mod bindgen; pub mod generate; -pub mod rustfmt; pub use generate::{InputFile, generate}; @@ -21,7 +20,3 @@ pub fn write_to_file>(path: T, code: &str) -> Result<(), io::Erro let mut file = File::create(path)?; file.write_all(code.as_bytes()) } - -pub fn write_to_file_fmt>(path: T, code: &str) -> Result<(), io::Error> { - write_to_file(path, &rustfmt::format(code)?) -} diff --git a/aya-tool/src/rustfmt.rs b/aya-tool/src/rustfmt.rs deleted file mode 100644 index b89ea32d..00000000 --- a/aya-tool/src/rustfmt.rs +++ /dev/null @@ -1,26 +0,0 @@ -use std::{ - io::{self, Write}, - process::{Command, Output, Stdio}, -}; - -pub fn format(code: &str) -> Result { - let mut child = Command::new("rustfmt") - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn()?; - let stdin = child.stdin.as_mut().unwrap(); - stdin.write_all(code.as_bytes())?; - - let Output { - status, - stdout, - stderr, - } = child.wait_with_output()?; - if !status.success() { - let stderr = String::from_utf8(stderr).unwrap(); - return Err(io::Error::other(format!( - "rustfmt failed: {status:?}\n{stderr}" - ))); - } - Ok(String::from_utf8(stdout).unwrap()) -} diff --git a/ebpf/aya-ebpf-bindings/src/aarch64/bindings.rs b/ebpf/aya-ebpf-bindings/src/aarch64/bindings.rs index 293868f1..a2b920ee 100644 --- a/ebpf/aya-ebpf-bindings/src/aarch64/bindings.rs +++ b/ebpf/aya-ebpf-bindings/src/aarch64/bindings.rs @@ -45,11 +45,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/ebpf/aya-ebpf-bindings/src/armv7/bindings.rs b/ebpf/aya-ebpf-bindings/src/armv7/bindings.rs index cd13c213..33124867 100644 --- a/ebpf/aya-ebpf-bindings/src/armv7/bindings.rs +++ b/ebpf/aya-ebpf-bindings/src/armv7/bindings.rs @@ -45,11 +45,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/ebpf/aya-ebpf-bindings/src/mips/bindings.rs b/ebpf/aya-ebpf-bindings/src/mips/bindings.rs index 4bc8f8fe..93bc0b79 100644 --- a/ebpf/aya-ebpf-bindings/src/mips/bindings.rs +++ b/ebpf/aya-ebpf-bindings/src/mips/bindings.rs @@ -45,11 +45,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/ebpf/aya-ebpf-bindings/src/powerpc64/bindings.rs b/ebpf/aya-ebpf-bindings/src/powerpc64/bindings.rs index f94e3b0c..9d9481ca 100644 --- a/ebpf/aya-ebpf-bindings/src/powerpc64/bindings.rs +++ b/ebpf/aya-ebpf-bindings/src/powerpc64/bindings.rs @@ -45,11 +45,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/ebpf/aya-ebpf-bindings/src/riscv64/bindings.rs b/ebpf/aya-ebpf-bindings/src/riscv64/bindings.rs index 6b42a2be..8011f07a 100644 --- a/ebpf/aya-ebpf-bindings/src/riscv64/bindings.rs +++ b/ebpf/aya-ebpf-bindings/src/riscv64/bindings.rs @@ -45,11 +45,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/ebpf/aya-ebpf-bindings/src/s390x/bindings.rs b/ebpf/aya-ebpf-bindings/src/s390x/bindings.rs index bc5f3fa6..02e1a27d 100644 --- a/ebpf/aya-ebpf-bindings/src/s390x/bindings.rs +++ b/ebpf/aya-ebpf-bindings/src/s390x/bindings.rs @@ -45,11 +45,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/ebpf/aya-ebpf-bindings/src/x86_64/bindings.rs b/ebpf/aya-ebpf-bindings/src/x86_64/bindings.rs index b0cab6d7..6d4abd9e 100644 --- a/ebpf/aya-ebpf-bindings/src/x86_64/bindings.rs +++ b/ebpf/aya-ebpf-bindings/src/x86_64/bindings.rs @@ -45,11 +45,7 @@ where index % 8 }; let mask = 1 << bit_index; - if val { - byte | mask - } else { - byte & !mask - } + if val { byte | mask } else { byte & !mask } } #[inline] pub fn set_bit(&mut self, index: usize, val: bool) { diff --git a/xtask/src/codegen/aya_ebpf_bindings.rs b/xtask/src/codegen/aya_ebpf_bindings.rs index 2b7f51d0..d9f5c338 100644 --- a/xtask/src/codegen/aya_ebpf_bindings.rs +++ b/xtask/src/codegen/aya_ebpf_bindings.rs @@ -6,7 +6,7 @@ use std::{ }; use anyhow::{Context as _, Result}; -use aya_tool::{bindgen, write_to_file_fmt}; +use aya_tool::{bindgen, write_to_file}; use proc_macro2::TokenStream; use quote::ToTokens; use syn::{Item, parse_str}; @@ -148,13 +148,13 @@ pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<()> { } // write the bindings, with the original helpers removed - write_to_file_fmt( + write_to_file( generated.join("bindings.rs"), &tree.to_token_stream().to_string(), )?; // write the new helpers as expanded by expand_helpers() - write_to_file_fmt( + write_to_file( generated.join("helpers.rs"), &format!("use super::bindings::*; {helpers}"), )?;