diff --git a/libbpf-cargo/CHANGELOG.md b/libbpf-cargo/CHANGELOG.md index da8eda1b..3330ffd9 100644 --- a/libbpf-cargo/CHANGELOG.md +++ b/libbpf-cargo/CHANGELOG.md @@ -1,3 +1,10 @@ +Unreleased +---------- +- Added ability to skip running `rustfmt` on the skeleton Rust source entirely + in `libbpf-cargo` by setting `rustfmt-path` to an empty string for the CLI or + passing an empty path to `SkeletonBuilder::rustfmt()`. + + 0.27.2 ------ - Added `_data` skeleton members for accessing `__arena` diff --git a/libbpf-cargo/src/gen/mod.rs b/libbpf-cargo/src/gen/mod.rs index 6b8f59a1..bcf34261 100644 --- a/libbpf-cargo/src/gen/mod.rs +++ b/libbpf-cargo/src/gen/mod.rs @@ -224,10 +224,14 @@ pub(crate) enum OutputDest<'a> { /// Try running `rustfmt` over `s` and return result. /// -/// If no `rustfmt` binary could be found the content is left untouched, as -/// it's only meant as a cosmetic brush up, without change of semantics. +/// If no `rustfmt` binary could be found, or an empty path is supplied, +/// the content is left untouched, as it's only meant as a cosmetic brush up, +/// without change of semantics. fn try_rustfmt<'code>(s: &'code str, rustfmt_path: Option<&Path>) -> Result> { let result = if let Some(r) = rustfmt_path { + if r.as_os_str().is_empty() { + return Ok(Cow::Borrowed(s.as_bytes())); + } Command::new(r) } else { Command::new("rustfmt") diff --git a/libbpf-cargo/src/lib.rs b/libbpf-cargo/src/lib.rs index 6a1c657f..30691453 100644 --- a/libbpf-cargo/src/lib.rs +++ b/libbpf-cargo/src/lib.rs @@ -180,9 +180,10 @@ impl SkeletonBuilder { self } - /// Specify which `rustfmt` binary to use + /// Specify which `rustfmt` binary to use. /// - /// Default searches `$PATH` for `rustfmt` + /// Default searches `$PATH` for `rustfmt`. + /// To skip formatting, an empty path can be supplied. pub fn rustfmt>(&mut self, rustfmt: P) -> &mut Self { self.rustfmt = rustfmt.as_ref().to_path_buf(); self diff --git a/libbpf-cargo/src/main.rs b/libbpf-cargo/src/main.rs index 28546a1e..cbd9e26b 100644 --- a/libbpf-cargo/src/main.rs +++ b/libbpf-cargo/src/main.rs @@ -78,7 +78,8 @@ enum Command { /// Path to top level Cargo.toml manifest_path: Option, #[arg(long, value_parser)] - /// Path to rustfmt binary + /// Path to rustfmt binary. + /// If set to an empty path, formatting will be skipped. rustfmt_path: Option, #[arg(long, value_parser)] /// Generate skeleton for the specified object file and print results to stdout