Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libbpf-cargo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 `<arena-map>_data` skeleton members for accessing `__arena`
Expand Down
8 changes: 6 additions & 2 deletions libbpf-cargo/src/gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cow<'code, [u8]>> {
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")
Expand Down
5 changes: 3 additions & 2 deletions libbpf-cargo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: AsRef<Path>>(&mut self, rustfmt: P) -> &mut Self {
self.rustfmt = rustfmt.as_ref().to_path_buf();
self
Expand Down
3 changes: 2 additions & 1 deletion libbpf-cargo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ enum Command {
/// Path to top level Cargo.toml
manifest_path: Option<PathBuf>,
#[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<PathBuf>,
#[arg(long, value_parser)]
/// Generate skeleton for the specified object file and print results to stdout
Expand Down
Loading