Entry point's crate directory

⚓ Rust    📅 2025-08-24    👤 surdeus    👁️ 6      

surdeus

I've found out I can do one of the following to get the directory of the entry point crate being compiled:

// Option 1
let project_directory = std::env::current_dir().unwrap();

// Option 2
let project_directory = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());

But neither are perfect. I want to be able to get the entry point's directory (not the workspace unless it's a workspace+package) from a third-party crate, and I want to support Cargo -p... --manifest-path...

7 posts - 2 participants

Read full topic

🏷️ Rust_feed