cross icon indicating copy to clipboard operation
cross copied to clipboard

OUT_DIR behavior seems to be different

Open setoelkahfi opened this issue 2 years ago • 2 comments

Hello, I have this pre-commit-hooks crate that reads the OUT_DIR environment variable and then traverses up to the root crate to find the root Cargo.toml. Works well on regular cargo build and cargo test operations, but fails to find the root Cargo.toml when building or testing using cross. Our project is a workspace-based. ~Haven't tried it on a regular single-package crate.~

Single package

Screenshot 2023-06-08 at 10 08 42

Workspace-based Screenshot 2023-06-08 at 09 35 05

My guess is that cross will build the package independently and put all the crates in the same directory level.

Any pointers?

setoelkahfi avatar Jun 08 '23 07:06 setoelkahfi

There is no guarantee that Cargo.toml is in a parent directory of OUT_DIR since you can set any arbitrary target directory with --target-dir.

You likely want to use CARGO_MANIFEST_DIR instead.

reitermarkus avatar Jun 08 '23 08:06 reitermarkus

I believe I tried that one before. I'll try it again.

setoelkahfi avatar Jun 08 '23 08:06 setoelkahfi