Skip to content

Static evaluation of CARGO_WORKSPACE_DIR env var leaks to consumers. #41

Open
@rcgoodfellow

Description

@rcgoodfellow

In the following code

falcon/ztest/src/lib.rs

Lines 298 to 337 in 29deea1

pub fn copy_bin_to_zone(&self, name: &str, bin: &str) -> Result<()> {
let profile = if cfg!(debug_assertions) {
"debug"
} else {
"release"
};
let from = match env!("CARGO_WORKSPACE_DIR") {
"" => format!("target/{}/{}", profile, bin),
path => format!("{}target/{}/{}", path, profile, bin),
};
let to = format!("opt/{}", bin);
self.copy_to_zone(name, &from, &to)
}
pub fn copy_workspace_to_zone(
&self,
name: &str,
from: &str,
to: &str,
) -> Result<()> {
let from = match env!("CARGO_WORKSPACE_DIR") {
"" => from.into(),
path => format!("{}{}", path, from),
};
self.copy_to_zone(name, &from, to)
}
pub fn copy_workspace_to_zone_recursive(
&self,
name: &str,
from: &str,
to: &str,
) -> Result<()> {
let from = match env!("CARGO_WORKSPACE_DIR") {
"" => from.into(),
path => format!("{}{}", path, from),
};
self.copy_to_zone_recursive(name, &from, to)
}
}

the falcon ztest library is evaluating CARGO_WORKSPACE_DIR at compile time. This check also happens in any crate that consumes ztest and then goes on to transitively impact all crates in a dependency tree involving ztest. This is highly undesirable behavior. Figure out a better way to find workspace binaries than the current approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions