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.
reviewable/pr1204/r1
Tamir Duberstein 1 week ago
parent 2bb2302d1d
commit 56ebe1406e

@ -2,7 +2,6 @@ name: aya-ci
on: on:
push: push:
branches-ignore: 'create-pull-request/**'
pull_request: pull_request:
@ -32,20 +31,15 @@ jobs:
with: with:
tool: cargo-hack,taplo-cli 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 - run: cargo xtask public-api
if: github.event_name == 'pull_request' if: github.event_name == 'pull_request'
@ -161,10 +155,10 @@ jobs:
- uses: Swatinem/rust-cache@v2 - 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 - uses: taiki-e/install-action@cargo-hack
- name: Build - name: Build
env: env:
CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }} CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }}
@ -278,15 +272,13 @@ jobs:
tar -xJ --strip-components 2 -C /tmp/rustc-llvm tar -xJ --strip-components 2 -C /tmp/rustc-llvm
echo /tmp/rustc-llvm/bin >> $GITHUB_PATH 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
# 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.
# --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.
# 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
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: with:
path: test/.tmp path: test/.tmp
key: ${{ runner.arch }}-${{ runner.os }}-test-cache key: ${{ runner.arch }}-${{ runner.os }}-test-cache
@ -329,5 +321,4 @@ jobs:
- run-integration-test - run-integration-test
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Build Complete - run: echo 'Build Complete'
run: echo "Build Complete"

@ -32,6 +32,7 @@ jobs:
- run: cargo xtask codegen - run: cargo xtask codegen
- run: cargo xtask public-api --bless - run: cargo xtask public-api --bless
- run: cargo fmt --all
- run: echo "LIBBPF_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV - run: echo "LIBBPF_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
working-directory: xtask/libbpf working-directory: xtask/libbpf

@ -47,11 +47,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -47,11 +47,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -47,11 +47,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -47,11 +47,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -47,11 +47,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -47,11 +47,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -47,11 +47,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -25,9 +25,6 @@ pub enum Error {
#[error("{stderr}\nbindgen failed with exit code {code}")] #[error("{stderr}\nbindgen failed with exit code {code}")]
BindgenExit { code: i32, stderr: String }, BindgenExit { code: i32, stderr: String },
#[error("rustfmt failed")]
Rustfmt(#[source] io::Error),
#[error("error reading header file")] #[error("error reading header file")]
ReadHeaderFile(#[source] io::Error), ReadHeaderFile(#[source] io::Error),
} }

@ -6,7 +6,6 @@ use std::{
pub mod bindgen; pub mod bindgen;
pub mod generate; pub mod generate;
pub mod rustfmt;
pub use generate::{InputFile, generate}; pub use generate::{InputFile, generate};
@ -21,7 +20,3 @@ pub fn write_to_file<T: AsRef<Path>>(path: T, code: &str) -> Result<(), io::Erro
let mut file = File::create(path)?; let mut file = File::create(path)?;
file.write_all(code.as_bytes()) file.write_all(code.as_bytes())
} }
pub fn write_to_file_fmt<T: AsRef<Path>>(path: T, code: &str) -> Result<(), io::Error> {
write_to_file(path, &rustfmt::format(code)?)
}

@ -1,26 +0,0 @@
use std::{
io::{self, Write},
process::{Command, Output, Stdio},
};
pub fn format(code: &str) -> Result<String, io::Error> {
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())
}

@ -45,11 +45,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -45,11 +45,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -45,11 +45,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -45,11 +45,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -45,11 +45,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -45,11 +45,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -45,11 +45,7 @@ where
index % 8 index % 8
}; };
let mask = 1 << bit_index; let mask = 1 << bit_index;
if val { if val { byte | mask } else { byte & !mask }
byte | mask
} else {
byte & !mask
}
} }
#[inline] #[inline]
pub fn set_bit(&mut self, index: usize, val: bool) { pub fn set_bit(&mut self, index: usize, val: bool) {

@ -6,7 +6,7 @@ use std::{
}; };
use anyhow::{Context as _, Result}; 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 proc_macro2::TokenStream;
use quote::ToTokens; use quote::ToTokens;
use syn::{Item, parse_str}; 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 the bindings, with the original helpers removed
write_to_file_fmt( write_to_file(
generated.join("bindings.rs"), generated.join("bindings.rs"),
&tree.to_token_stream().to_string(), &tree.to_token_stream().to_string(),
)?; )?;
// write the new helpers as expanded by expand_helpers() // write the new helpers as expanded by expand_helpers()
write_to_file_fmt( write_to_file(
generated.join("helpers.rs"), generated.join("helpers.rs"),
&format!("use super::bindings::*; {helpers}"), &format!("use super::bindings::*; {helpers}"),
)?; )?;

Loading…
Cancel
Save