Skip to content

Commit bc2931f

Browse files
committed
Add a --runtime argument, which is used by cargo add c2rust-analysis-rt instead of the user having to manually do it. However, we have to use +stable as cargo add was added in 1.62 (on 1.60 now, but upgrading in #513).
1 parent 434ddcb commit bc2931f

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

analysis/test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ edition = "2021"
77

88
[dependencies]
99
libc = "0.2"
10-
c2rust-analysis-rt = { path = "../../analysis/runtime", optional = true }
10+
c2rust-analysis-rt = { path = "../runtime", optional = true, version = "0.1.0" }

dynamic_instrumentation/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ struct Args {
5252
#[clap(long, value_parser)]
5353
metadata: PathBuf,
5454

55+
/// Path to the `c2rust-analysis-rt` crate.
56+
#[clap(long, value_parser)]
57+
runtime: Option<PathBuf>,
58+
5559
/// `cargo` args.
5660
cargo_args: Vec<OsString>,
5761
}
@@ -218,6 +222,7 @@ fn rustc_wrapper() -> anyhow::Result<()> {
218222
fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> {
219223
let Args {
220224
metadata,
225+
runtime,
221226
mut cargo_args,
222227
} = Args::parse();
223228

@@ -232,6 +237,23 @@ fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> {
232237
cmd.args(&["clean", "--package", root_package.name.as_str()]);
233238
})?;
234239

240+
// TODO(kkysen) Once we upgrade to 1.62, we can just use `cargo` and not specify `+stable`.
241+
// The problem currently is that `+stable` doesn't work on a resolved `$CARGO`,
242+
// which happens when this runs inside of `cargo test`,
243+
// and our current nightly is 1.60, which is before `cargo add` got added
244+
// (though it's been in `cargo-edit` for a while).
245+
Cargo {
246+
path: "cargo".into(),
247+
}
248+
.run(|cmd| {
249+
cmd.args(&["+stable", "add", "--optional", "c2rust-analysis-rt"]);
250+
if let Some(runtime) = runtime {
251+
// Since it's a local path, we don't need the internet,
252+
// and running it offline saves a slow index sync.
253+
cmd.args(&["--offline", "--path"]).arg(runtime);
254+
}
255+
})?;
256+
235257
cargo.run(|cmd| {
236258
add_runtime_feature(&mut cargo_args);
237259
cmd.args(cargo_args)

scripts/pdg.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ main() {
4141
local c2rust="${CWD}/${profile_dir}/c2rust"
4242
local c2rust_instrument="${CWD}/${profile_dir}/${instrument}"
4343
local metadata="${CWD}/${test_dir}/metadata.bc"
44+
local runtime="${CWD}/analysis/runtime"
4445

4546
(cd "${test_dir}"
4647
export RUST_BACKTRACE=1
@@ -51,6 +52,7 @@ main() {
5152

5253
time "${c2rust_instrument}" \
5354
--metadata "${metadata}" \
55+
--runtime "${runtime}" \
5456
-- run "${profile_args[@]}" \
5557
-- "${args[@]}" \
5658
1> instrument.out.log

0 commit comments

Comments
 (0)