Unclear which environment variables are passed to build.rs #9403
Labels
A-documenting-cargo-itself
Area: Cargo's documentation
A-environment-variables
Area: environment variables
C-bug
Category: bug
E-easy
Experience: Easy
Problem
The Cargo book has a list of environment variables that are passed to
build.rs
(“Environment variables Cargo sets for build scripts”). That list does not mention any variables starting withCARGO_PKG_
. However, in reality, Cargo does set theCARGO_PKG_
variables when callingbuild.rs
. Those variables are only mentioned in “Environment variables Cargo sets for crates”. I initially thought that meant that all variables in the latter section would also be available tobuild.rs
; however, that is also not true:CARGO_CRATE_NAME
,CARGO_BIN_NAME
,CARGO_BIN_EXE_*
, andCARGO_PRIMARY_PACKAGE
are not set whenbuild.rs
runs.Steps
Write a
build.rs
that prints out all environment variables prefixed withcargo:warning=
and runcargo build
.Possible Solution(s)
I don’t know what the behaviour is supposed to be:
build.rs
, then there is a bug becauseCARGO_PKG_
are not in that list so they should be removed from the environment.build.rs
, then there is a bug becauseCARGO_CRATE_NAME
(and probably a few others) are not exposed; also, I did not find it clear from the book that those variables were intended to be exposed tobuild.rs
so perhaps the wording could be cleaned up.CARGO_PKG_
specifically, but not all the variables from “sets for crates”, are supposed to be exposed tobuild.rs
, then the book should say so in the “sets for build scripts” section.Output of
cargo version
: 1.49.0The text was updated successfully, but these errors were encountered: