Workspace root environment variable?

in compiling a macro crate it seems that OUT_DIR is not
set, and indeed the reference says it is for a build script
only. in the absence of a user build script does cargo create a default/minimal one anyway?
and if OUT_DIR is not available, what is there for the workspace
root to which I can add "target/debug" or "target/release"?
none from Environment Variables - The Cargo Book look suitable...
"$CARGO_MANIFEST_DIR/.." is my workaround but that's assuming a particular directory structure.

What does your proc macro need OUT_DIR for? That a proc macro needs access to the target directory is quite suspicious. I.e. read this comment on GitHub by Eric Huss on why OUT_DIR is not set for anything else but the build script:

2 Likes

I've gone off-piste with hot-lib-reloader which needs to locate the dynlibs. the examples have a particular layout that
allows "$CARGO_MANIFEST_DIR/target/debug" to work
but this is no good for any other layout and using that envar seems to be a compromise.

For your direct question, CARGO_WORKSPACE_DIR is being discussed in Environment variable for Cargo Workspace · Issue #3946 · rust-lang/cargo · GitHub though it looks like that isn't what is actually needed for most use cases, and the rest of the use cases break down when publishing a package.

1 Like