Programmatically finding an example binary

2026-10-31来源 Rust Users ForumEnglish
Programmatically finding an example binary

The tests of my library partially use a binary provided by an example. Works on stable for now, but with the recent layout changes, beta/nightly fail because of path issues.

Is there a good way to find where the binary of the example resides (after having called cargo build --example basic)? Right now, I'm doing

PathBuf::from(env::var("OUT_DIR").unwrap()) .join("../../../examples") 

which apparently is not portable between the stable/beta/nightly channels. I could specialise on the cargo version or something, but is there a more programmatic way? I was hoping for an env var like EXAMPLES_BINARY_DIR, but did not find anything that's helping here.

Thanks for any pointers :slight_smile:

1 post - 1 participant

Read full topic

原文:https://www.a8q9.cn/en/article/programmatically-finding-an-example-binary-613716.html

相关文章