Skip to content

Commit

Permalink
Put stuff in the right spots
Browse files Browse the repository at this point in the history
  • Loading branch information
zgrannan committed Dec 1, 2023
1 parent d1e704a commit d94e63e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
32 changes: 19 additions & 13 deletions prusti-contracts-build/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
use std::{path::PathBuf, process::Command};

use prusti_utils::launch::get_prusti_contracts_build_destination_dir;
use prusti_utils::launch::get_prusti_contracts_build_target_dir;

fn executable_name(name: &str) -> String {
#[cfg(windows)]
let name = format!("{}.exe", name);

#[cfg(not(windows))]
let name = name.to_string();

name
}

fn main() {
// Rerun if running with e.g. cargo clippy
Expand All @@ -16,30 +26,26 @@ fn main() {
let target: PathBuf = ["..", "target"].iter().collect();
force_reexport_specs(target.join("verify").as_path());

let bin_dir = get_prusti_contracts_build_destination_dir(&target);

let target = get_prusti_contracts_build_target_dir(&target);
let bin_dir = target.join("bin");
std::fs::create_dir_all(&bin_dir).unwrap();

// Copies all files into `bin_dir`. `cargo_prusti` cannot be run directly
// from std::env::var("CARGO_BIN_FILE_PRUSTI_LAUNCH_cargo-prusti")
// because it requires `prusti-rustc` and `prusti-driver` to be in the same
// path.
for (krate, file) in [
("PRUSTI_LAUNCH", "cargo-prusti"),
("PRUSTI_LAUNCH", "prusti-rustc"),
("PRUSTI", "prusti-driver"),
] {
let file_from = std::env::var(format!("CARGO_BIN_FILE_{krate}_{file}")).unwrap();
let file_to = &format!("{file}{}", if cfg!(windows) { ".exe" } else { "" });
let file_to = executable_name(file);
let file_to = bin_dir.join(file_to);
std::fs::copy(file_from, file_to).unwrap();
}

// Run `cargo-prusti`
let cargo_prusti = format!("cargo-prusti{}", if cfg!(windows) { ".exe" } else { "" });
let cargo_prusti = bin_dir.join(cargo_prusti);

// In theory we should build to here (i.e. set `CARGO_TARGET_DIR` to this),
// but this is hard to find for linking. So instead build to the `prusti-contracts` dir.
// let out_dir = std::env::var("OUT_DIR").unwrap();
// println!("cargo:warning=out_dir: {}", out_dir);

let cargo_prusti = bin_dir.join(executable_name("cargo-prusti"));
let mut cmd = Command::new(cargo_prusti);
cmd.env("CARGO_TARGET_DIR", target.as_os_str());
cmd.current_dir(&prusti_contracts);
Expand Down
12 changes: 6 additions & 6 deletions prusti-utils/src/launch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ pub fn get_target_dir(exe_dir: &Path) -> PathBuf {
root_dir.to_path_buf()
}

pub fn get_prusti_contracts_build_destination_dir(target_dir: &Path) -> PathBuf {
let target_dir = target_dir.join("prusti-contracts");
target_dir.join("verify").join(BUILD_MODE)
pub fn get_prusti_contracts_build_target_dir(target_dir: &Path) -> PathBuf {
target_dir.join("prusti-contracts").join(BUILD_MODE)
}

pub fn get_prusti_contracts_dir(exe_dir: &Path) -> Option<PathBuf> {
Expand All @@ -54,10 +53,11 @@ pub fn get_prusti_contracts_dir(exe_dir: &Path) -> Option<PathBuf> {
let target_dir = get_target_dir(exe_dir);
let candidates = [
// Libraries in the Prusti artifact will show up here
get_prusti_contracts_build_destination_dir(&target_dir),
get_prusti_contracts_build_target_dir(&target_dir),
// Libraries when building Prusti will show up here
target_dir.join("verify").join(BUILD_MODE),
];
target_dir,
]
.map(|path| path.join("verify").join(BUILD_MODE));
candidates
.into_iter()
.find(|candidate| candidate.join(&a_prusti_contracts_file).exists())
Expand Down

0 comments on commit d94e63e

Please sign in to comment.