Repository navigation
Option to disable skeleton formatting with rustfmt - #1465
Conversation
a47e37b to
a11509b
Compare
| - Added ability to skip running `rustfmt` on the skeleton Rust source entirely in `libbpf-cargo`. | ||
| In the crate, `SkeletonBuilder::rustfmt()` changed signature to take parameter `Option<PathBuf>`. | ||
| The CLI gained flag `--disable-rustfmt`. |
There was a problem hiding this comment.
Please stick to existing format; no sentences.
| let rustfmt_path = if disable_rustfmt { | ||
| None | ||
| } else { | ||
| Some(rustfmt_path.unwrap_or("rustfmt".into())) |
There was a problem hiding this comment.
Clearly we don't want to have three copies of the string "rustfmt" floating around everywhere. Introduce a constant?
| Command::new(r) | ||
| } else { | ||
| Command::new("rustfmt") | ||
| return Ok(Cow::Borrowed(s.as_bytes())); |
There was a problem hiding this comment.
This function is directly reachable from the public generate and you are changing semantics of said function subtly, for the worse, and for no good reason, from what I gather.
There was a problem hiding this comment.
Would skipping try_rustfmt() at caller side be better in your view when rustfmt_path is None (two occasions)?
There was a problem hiding this comment.
If you question the change of semantics of the rustfmt argument itself: this was intentional, the fallback is resolved now as early as possible (in main and in SkeletonBuilder) which I thought is cleaner.
Otherwise one would have to deal with something like Option<Option<PathBuf>> where the outer option is resolved to the fallback "rustfmt" executable and the inner one let's it skip or something like that.
That was a pattern I was not comfortable with.
There was a problem hiding this comment.
Nested Option is a way, but I tend to agree it's not ideal. My main gripe is that there is effectively no breaking change and yet semantics change, so users won't notice.
Personally, given how niche this entire rustfmt infrastructure is, I'd say we just special case Some("") to map to "skip". I'd think then we can also remove the public "private" constant.
There was a problem hiding this comment.
Ok, I have changed it to do that.
| /// Default searches `$PATH` for `rustfmt` | ||
| pub fn rustfmt<P: AsRef<Path>>(&mut self, rustfmt: P) -> &mut Self { | ||
| self.rustfmt = rustfmt.as_ref().to_path_buf(); | ||
| pub fn rustfmt(&mut self, rustfmt: Option<PathBuf>) -> &mut Self { |
There was a problem hiding this comment.
Why are we dropping the P generic?
There was a problem hiding this comment.
This is a change to avoid that users have to supply None::<PathBuf>.
Since it is a breaking change anyway, I thought this makes the public API more ergonomic.
There was a problem hiding this comment.
It penalizes usage of .rustfmt("xxxx"), though, which now requires an explicit PathBuf conversion first.
I'd think something like .rustfmt::<PathBuf>(None) is quite acceptable.
There was a problem hiding this comment.
Ok, with the latest change this is untouched.
| /// Whether to disable applying rustfmt to the generated skeleton Rust source. | ||
| #[arg(long)] | ||
| disable_rustfmt: bool, |
There was a problem hiding this comment.
IMO this is bad in many ways. For one, at the very least it should be mutually exclusive with rustfmt_path. But also, it seems icky to have a separate argument like that to begin with. Can we fold that into rustfmt_path?
There was a problem hiding this comment.
I wondered how to approach this in a better way as well - the reason I opted for this implementation is to avoid breakage as much as possible.
Users that keep invoking the CLI in the same way still fall back to rustfmt, while users that explicitly want to opt out of formatting can do so with the new flag.
I will apply that both arguments are mutually exclusive, for the rest I did not find a better pattern - I'm open to suggestions.
There was a problem hiding this comment.
When both options are supplied, the CLI now reports the following error:
$ cargo run -p libbpf-cargo -- libbpf gen --rustfmt-path some_path --disable-rustfmt
error: the argument '--rustfmt-path <RUSTFMT_PATH>' cannot be used with '--disable-rustfmt'
There was a problem hiding this comment.
Can we map --rustfmt-path="" to None?
Or plumb it through as per earlier comment and then special case where needed.
There was a problem hiding this comment.
I have changed it accordingly.
802ee6b to
ef77273
Compare
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()`.
d-e-s-o
left a comment
There was a problem hiding this comment.
Seems fine to me, thanks.
Improve the CHANGELOG message for #1465 and the style of some code comments. Signed-off-by: Daniel Müller <deso@posteo.net>
Added ability to skip running
rustfmton the skeleton Rust source entirelyin
libbpf-cargo.SkeletonBuilder::rustfmt()changed signature to take parameterOption<PathBuf>.--disable-rustfmt.closes #1404