Skip to content

Rust adapter: literal paths anchored at the workspace root (CARGO_WORKSPACE_DIR) don't become dependencies #223

Closed

Description

@FredApps

A literal path in Rust code becomes a dependency on the crate it reaches. The adapter resolves it relative to the crate directory (the working directory under cargo test) and to the file's directory. But paths are also resolved relative to the workspace root:

  • an [env] entry with relative = true in .cargo/config.toml, such as the common CARGO_WORKSPACE_DIR = { value = "", relative = true }. [env] doesn't block, which is right.
  • rustc runs from the workspace root, so a proc macro that reads a relative path reads it from there.

Repro: a workspace with crates/app, crates/other and the [env] entry above. crates/app/src/lib.rs has:

#[test]
fn header() {
    let p = std::path::Path::new(env!("CARGO_WORKSPACE_DIR")).join("crates/other/src/lib.rs");
    assert!(std::fs::read_to_string(p).unwrap().starts_with("//"));
}

There's no blocker and no app → other edge, so a change to other skips this test. The literal is only tried as crates/app/crates/other/... and crates/app/src/crates/other/....

Fix: also resolve each literal from the workspace root. A literal that resolves to the root itself ("/", "{}/{}", ".") is skipped, so it doesn't make every crate depend on everything. A path that only makes sense inside the crate (tests/data/input.bin) reaches nothing new in a virtual workspace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions