However, to release others from handling env vars, I tried cargo::rustc-env=VAR=VALUE instead:
And I ensure getting the right path by checking target/release/build/xx/output.
However, the latter does not compile, and the failing reason is same as if env vars are not set.
Maybe cargo::rustc-env=VAR=VALUE is just for things like producing git commit hash? Or is there any feasible way to achieve export's function in build.rs?
Maybe creating .cargo/config.toml and adding [env] by build.rs can work... But it may not be so graceful for modifying things out of OUT_DIR.
Setting environment variants with buildrs sets it only for build time only for your crate. If it needs needs to be set at any other point (e.g. $LD_LIBRARY_PATH is read as part of program startup by the dynamic library loader) then you need to use a different mechanism.
No matter how I set env vars to simplify development preparation, the user still need to export the dynamic lib path themselves. So it is not me who need to do so!