I've been getting a package's version (for use in build.rs) by parsing the package's Cargo.toml. This became a little more problematic when using the new inheritance feature in 1.64, because the version is no longer stored in the crate's Cargo.toml.
I could simply check for version.workspace = true and if it is set, traverse up the fs tree until a Cargo.toml is found and parse it. That said, is there some plumbing in cargo get the version directly (no matter where it originates from) and/or the path of the workspace's Cargo.toml?
Sorry, I was unclear: I need the version inbuild.rs, because I use it to embed the version (among other things) in the binary (using the embed-resouce crate).
Cargo sets several environment variables when build scripts are run. Because these variables are not yet set when the build script is compiled, the above example using env! won't work and instead you'll need to retrieve the values when the build script is run: [example using std::env::var]
...
CARGO_PKG_<var> - The package information variables, with the same names and values as are provided during crate building.
When the build script itself is compiled, that also gets its version env! matching the package version, but code compiled in a build-dependency would see its own env!.