Skip to content

Commit

Permalink
feat(cli): use a hax-specific target directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Franceschino committed Jul 2, 2024
1 parent 557f905 commit 338a444
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cli/subcommands/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ annotate-snippets.workspace = true
serde-jsonlines = "0.5.0"
prettyplease = "0.2.20"
syn = { version = "2.*", features = ["full"] }
cargo_metadata.workspace = true
camino = "1.1"

[build-dependencies]
serde.workspace = true
Expand Down
11 changes: 11 additions & 0 deletions cli/subcommands/src/cargo_hax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ fn run_engine(
error
}

/// Uses `cargo metadata` to compute a derived target directory.
fn target_dir(suffix: &str) -> camino::Utf8PathBuf {
let metadata = cargo_metadata::MetadataCommand::new().exec().unwrap();
let mut dir = metadata.target_directory;
dir.push(suffix);
dir
}

/// Calls `cargo` with a custom driver which computes `haxmeta` files
/// in `TARGET`. One `haxmeta` file is produced by crate. Each
/// `haxmeta` file contains the full AST of one crate.
Expand All @@ -298,6 +306,9 @@ fn compute_haxmeta_files(options: &Options) -> (Vec<EmitHaxMetaMessage>, i32) {
cmd.args([COLOR_FLAG, "always"]);
}
cmd.stderr(std::process::Stdio::piped());
if !options.no_custom_target_directory {
cmd.env("CARGO_TARGET_DIR", target_dir("hax"));
};
cmd.env(
"RUSTC_WORKSPACE_WRAPPER",
std::env::var("HAX_RUSTC_DRIVER_BINARY")
Expand Down
7 changes: 7 additions & 0 deletions hax-types/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,13 @@ pub struct Options {
/// options like `-C -p <PKG> ;`).
#[arg(long = "deps")]
pub deps: bool,

/// By default, hax use `$CARGO_TARGET_DIR/hax` as target folder,
/// to avoid recompilation when working both with `cargo hax` and
/// `cargo build` (or, e.g. `rust-analyzer`). This option disables
/// this behavior.
#[arg(long)]
pub no_custom_target_directory: bool,
}

impl NormalizePaths for Command {
Expand Down

0 comments on commit 338a444

Please sign in to comment.