Skip to content

transpile: add --postprocess to run c2rust-postprocess#1626

Merged
kkysen merged 4 commits into
masterfrom
kkysen/transpile-postprocess-arg
Mar 4, 2026
Merged

transpile: add --postprocess to run c2rust-postprocess#1626
kkysen merged 4 commits into
masterfrom
kkysen/transpile-postprocess-arg

Conversation

@kkysen
Copy link
Copy Markdown
Contributor

@kkysen kkysen commented Feb 27, 2026

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.

Comment thread c2rust-transpile/src/lib.rs
Comment thread c2rust-postprocess/c2rust-postprocess
Copy link
Copy Markdown
Contributor

@fw-immunant fw-immunant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kkysen kkysen force-pushed the kkysen/transpile-postprocess-arg branch from 90f8ee6 to 726985b Compare March 3, 2026 17:55
kkysen added 3 commits March 3, 2026 22:14
`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.
@kkysen kkysen force-pushed the kkysen/transpile-postprocess-arg branch from 726985b to 9cbba72 Compare March 4, 2026 06:14
@kkysen kkysen force-pushed the kkysen/transpile-postprocess-arg branch from 9cbba72 to 7ccfb4f Compare March 4, 2026 07:49
@kkysen kkysen merged commit 8b96a17 into master Mar 4, 2026
11 checks passed
@kkysen kkysen deleted the kkysen/transpile-postprocess-arg branch March 4, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants