Skip to main content

canic_testkit/artifacts/
workspace.rs

1use std::{
2    env,
3    path::{Path, PathBuf},
4};
5
6/// Resolve the workspace root from a crate manifest directory.
7#[must_use]
8pub fn workspace_root_for(crate_manifest_dir: &str) -> PathBuf {
9    PathBuf::from(crate_manifest_dir)
10        .parent()
11        .and_then(|path| path.parent())
12        .map(PathBuf::from)
13        .expect("workspace root")
14}
15
16/// Resolve an optional prebuilt wasm directory override from the environment.
17#[must_use]
18pub fn prebuilt_wasm_dir(env_var: &str) -> Option<PathBuf> {
19    env::var(env_var).ok().map(PathBuf::from)
20}
21
22/// Return a stable target directory for host-side wasm test artifacts.
23#[must_use]
24pub fn test_target_dir(workspace_root: &Path, name: &str) -> PathBuf {
25    workspace_root.join("target").join(name)
26}