Skip to content

Run cargo add in c2rust-instrument --set-runtime to add c2rust-analysis-rt automatically #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analysis/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
22 changes: 22 additions & 0 deletions dynamic_instrumentation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,

/// Add the runtime as an optional dependency to the instrumented crate using `cargo add`.
#[clap(long)]
set_runtime: bool,

/// `cargo` args.
cargo_args: Vec<OsString>,
}
Expand Down Expand Up @@ -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();

Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions scripts/pdg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -52,6 +53,8 @@ main() {

time "${c2rust_instrument}" \
--metadata "${metadata}" \
--set-runtime \
--runtime-path "${runtime}" \
-- run "${profile_args[@]}" \
-- "${args[@]}" \
1> instrument.out.log
Expand Down