1use std::{path::PathBuf, sync::LazyLock};
2
3
4pub fn workspace_dir() -> PathBuf {
10 metadata::CARGO
11 .workspace_root
12 .clone()
13 .into_std_path_buf()
14}
15
16pub fn target_dir() -> PathBuf {
20 metadata::CARGO
21 .target_directory
22 .clone()
23 .into_std_path_buf()
24}
25
26pub static USER_WORKSPACE_CARGO_TOML: LazyLock<PathBuf> = LazyLock::new(|| {
27 let output = std::process::Command::new(env!("CARGO"))
28 .arg("locate-project")
29 .arg("--workspace")
30 .arg("--message-format=plain")
31 .output()
32 .unwrap()
33 .stdout;
34
35 let output = std::str::from_utf8(&output).unwrap()
36 .trim();
37
38 PathBuf::from(output)
39});
40
41
42pub mod metadata {
43 use std::sync::LazyLock;
44
45 pub static CARGO: LazyLock<cargo_metadata::Metadata> = LazyLock::new(|| {
46 cargo_metadata::MetadataCommand::new()
47 .manifest_path(super::USER_WORKSPACE_CARGO_TOML.as_path())
48 .exec()
49 .expect("Failed to gather Cargo metadata.")
50 });
51}
52
53
54pub mod cicero {
56 use std::path::PathBuf;
57
58 pub fn target() -> PathBuf {
61 super::target_dir().join("cicero")
62 }
63
64 pub fn internal() -> PathBuf {
66 target().join(".internal")
67 }
68}