diff --git a/analysis/test/Cargo.toml b/analysis/test/Cargo.toml index 838e8ce06e..5055716415 100644 --- a/analysis/test/Cargo.toml +++ b/analysis/test/Cargo.toml @@ -7,4 +7,4 @@ edition = "2021" [dependencies] libc = "0.2" -c2rust-analysis-rt = { path = "../../analysis/runtime", optional = true } +c2rust-analysis-rt = { path = "../runtime", optional = true, version = "0.1.0" } diff --git a/dynamic_instrumentation/src/main.rs b/dynamic_instrumentation/src/main.rs index 9667f0613b..aa25d85ed6 100644 --- a/dynamic_instrumentation/src/main.rs +++ b/dynamic_instrumentation/src/main.rs @@ -48,6 +48,15 @@ struct Args { #[clap(long, value_parser)] metadata: PathBuf, + /// Path to the `c2rust-analysis-rt` crate if you want to use a local version of it (vs. the crates.io one). + /// This is not used unless `--set-runtime` is also passed. + #[clap(long, value_parser)] + runtime_path: Option, + + /// Add the runtime as an optional dependency to the instrumented crate using `cargo add`. + #[clap(long)] + set_runtime: bool, + /// `cargo` args. cargo_args: Vec, } @@ -286,6 +295,8 @@ fn set_rust_toolchain() -> anyhow::Result<()> { fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> { let Args { metadata, + runtime_path, + set_runtime, mut cargo_args, } = Args::parse(); @@ -312,6 +323,17 @@ fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> { cmd.args(&["clean", "--package", root_package.name.as_str()]); })?; + if set_runtime { + cargo.run(|cmd| { + cmd.args(&["add", "--optional", "c2rust-analysis-rt"]); + if let Some(runtime) = runtime_path { + // Since it's a local path, we don't need the internet, + // and running it offline saves a slow index sync. + cmd.args(&["--offline", "--path"]).arg(runtime); + } + })?; + } + // Create and truncate the metadata file for the [`rustc_wrapper`]s to append to. OpenOptions::new() .create(true) diff --git a/scripts/pdg.sh b/scripts/pdg.sh index 55fdf90a28..78f99a3df4 100755 --- a/scripts/pdg.sh +++ b/scripts/pdg.sh @@ -41,6 +41,7 @@ main() { local c2rust="${CWD}/${profile_dir}/c2rust" local c2rust_instrument="${CWD}/${profile_dir}/${instrument}" local metadata="${CWD}/${test_dir}/metadata.bc" + local runtime="${CWD}/analysis/runtime" (cd "${test_dir}" unset RUSTFLAGS # transpiled code has tons of warnings; don't allow `-D warnings` @@ -52,6 +53,8 @@ main() { time "${c2rust_instrument}" \ --metadata "${metadata}" \ + --set-runtime \ + --runtime-path "${runtime}" \ -- run "${profile_args[@]}" \ -- "${args[@]}" \ 1> instrument.out.log