Skip to content

Commit

Permalink
c2rust-analyze: Add a cargo wrapper (#1036)
Browse files Browse the repository at this point in the history
* Fixes #709.
* Fixes #708.

This adds an MVP of a `cargo` wrapper for `c2rust-analyze` so that it
can be run on a whole crate like `cargo`. This copies the approach from
`c2rust-instrument`, with some minor adjustments:
* We don't care about the instrumentation and metadata
`c2rust-instrument` need, so that code is gone.
* We still allow `c2rust-analyze` to be called as a `rustc_wrapper`
directly. More specifically, the `cargo` wrapper is supposed to set
`RUST_SYSROOT`. `c2rust-instrument` requires this, while
`c2rust-analyze` will re-calculate it if it wasn't.

This allows us to keep using the `rustc` wrapper in tests,
as the tests are all set up as single files meant to be compiled with
`rustc` directly.
We can change this, but that'll come later. The exception is the
`lighttpd_minimal` and `with_pdg_file` tests, as those run on full
crates. I converted `lighttpd_minimal` to use the `cargo` wrapper as a
proof of concept to show it works. I tried to do the same for
`with_pdg_file`, but it updated some of the hashes or something so now
the PDG binary has out-of-date `DefPathHash`es, and I'm not sure how to
regenerate a new one.
  • Loading branch information
kkysen authored Nov 3, 2023
2 parents d4a09fa + f071ea7 commit 431847a
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ marks.*.json
# Outputs of `c2rust-analyze`
inspect/
*.analysis.txt
analysis.txt
7 changes: 5 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions analysis/tests/lighttpd-minimal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#![allow(unused_variables)]
#![feature(extern_types)]

extern crate libc;

use libc::*;
use std::mem;

Expand Down
6 changes: 5 additions & 1 deletion c2rust-analyze/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories.workspace = true
polonius-engine = "0.13.0"
rustc-hash = "1.1.0"
bitflags = "1.3.2"
c2rust-pdg = { path = "../pdg"}
c2rust-pdg = { path = "../pdg" }
bincode = "1.0"
serde = "1.0"
assert_matches = "1.5.0"
Expand All @@ -25,6 +25,10 @@ log = "0.4.17"
backtrace = "0.3.67"
itertools = "0.10"
libc = "0.2.147"
clap = { version = "4.2.7", features = ["derive"] }
fs-err = "2.9.0"
anyhow = "1.0.75"
toml_edit = "0.19.8"

[build-dependencies]
c2rust-build-paths = { path = "../c2rust-build-paths", version = "0.18.0" }
Expand Down
Loading

0 comments on commit 431847a

Please sign in to comment.