transpile: add --postprocess to run c2rust-postprocess#1626
Merged
Conversation
fw-immunant
reviewed
Mar 2, 2026
fw-immunant
reviewed
Mar 2, 2026
fw-immunant
approved these changes
Mar 2, 2026
Contributor
fw-immunant
left a comment
There was a problem hiding this comment.
LGTM overall, though I would prefer if we could avoid the which dep--it seems like it duplicates exec's PATH lookup and such logic is generally a source of TOCTTOU bugs (though I doubt we expect to run with any concurrency here).
One question inline.
90f8ee6 to
726985b
Compare
`c2rust-postprocess` is run after transpiling and potentially refactoring (if `--reorganize-definitions` and not `--disable-refactoring`). Since `c2rust-postprocess` is not a Rust binary, it's not always a sibling to the `c2rust`/`c2rust-transpile` binary. It's a bash script that runs a Python script with `uv`. Thus, to find it, we look in `$PATH` first and if it's not there, we assume we're in the `c2rust` repo and `cargo build` has been run and find the relative path of `c2rust-postprocess` (i.e., `target/$profile/../../c2rust-postprocess/c2rust-postprocess`). Similarly to `--reorganize-definitions`/`c2rust-refactor`, this requires `--emit-build-files`, as we need the `crate_file` (e.g., `src/lib.rs`) to run `c2rust-postprocess`. `c2rust-postprocess` can be easily set up to run on a single Rust file, though, so we should be able to drop this requirement later.
This ensures `postprocess` shows up in `c2rust --help` and is more discoverable. However, since the existing logic is for running adjacent `c2rust-*` subcommands, I've just left a TODO there for now.
726985b to
9cbba72
Compare
9cbba72 to
7ccfb4f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
c2rust-postprocessis run after transpiling and potentially refactoring (if--reorganize-definitionsand not--disable-refactoring). Sincec2rust-postprocessis not a Rust binary, it's not always a sibling to thec2rust/c2rust-transpilebinary. It's a bash script that runs a Python script withuv. Thus, to find it, we look in$PATHfirst and if it's not there, we assume we're in thec2rustrepo andcargo buildhas been run and find the relative path ofc2rust-postprocess(i.e.,target/$profile/../../c2rust-postprocess/c2rust-postprocess).Similarly to
--reorganize-definitions/c2rust-refactor, this requires--emit-build-files, as we need thecrate_file(e.g.,src/lib.rs) to runc2rust-postprocess.c2rust-postprocesscan be easily set up to run on a single Rust file, though, so we should be able to drop this requirement later.