Skip to content

Commit dd5f89e

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 55e0e5f commit dd5f89e

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
@@ -48,6 +48,10 @@ struct Args {
4848
#[clap(long, value_parser)]
4949
metadata: PathBuf,
5050

51+
/// Path to the `c2rust-analysis-rt` crate.
52+
#[clap(long, value_parser)]
53+
runtime: Option<PathBuf>,
54+
5155
/// `cargo` args.
5256
cargo_args: Vec<OsString>,
5357
}
@@ -286,6 +290,7 @@ fn set_rust_toolchain() -> anyhow::Result<()> {
286290
fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> {
287291
let Args {
288292
metadata,
293+
runtime,
289294
mut cargo_args,
290295
} = Args::parse();
291296

@@ -312,6 +317,23 @@ fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> {
312317
cmd.args(&["clean", "--package", root_package.name.as_str()]);
313318
})?;
314319

320+
// TODO(kkysen) Once we upgrade to 1.62, we can just use `cargo` and not specify `+stable`.
321+
// The problem currently is that `+stable` doesn't work on a resolved `$CARGO`,
322+
// which happens when this runs inside of `cargo test`,
323+
// and our current nightly is 1.60, which is before `cargo add` got added
324+
// (though it's been in `cargo-edit` for a while).
325+
Cargo {
326+
path: "cargo".into(),
327+
}
328+
.run(|cmd| {
329+
cmd.args(&["+stable", "add", "--optional", "c2rust-analysis-rt"]);
330+
if let Some(runtime) = runtime {
331+
// Since it's a local path, we don't need the internet,
332+
// and running it offline saves a slow index sync.
333+
cmd.args(&["--offline", "--path"]).arg(runtime);
334+
}
335+
})?;
336+
315337
// Create and truncate the metadata file for the [`rustc_wrapper`]s to append to.
316338
OpenOptions::new()
317339
.create(true)

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
unset RUSTFLAGS # transpiled code has tons of warnings; don't allow `-D warnings`
@@ -52,6 +53,7 @@ main() {
5253

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

0 commit comments

Comments
 (0)