Cargo DEP environment vars: What am I missing?


In the cargo docs, under Outputs of the build script:

# specially recognized by Cargo
# arbitrary user-defined metadata

Any other element is a user-defined metadata that will be passed to dependents. More information about this can be found in the links section.

Under The links Manifest Key:

As mentioned above in the output format, each build script can generate an arbitrary set of metadata in the form of key-value pairs. This metadata is passed to the build scripts of dependent packages. For example, if libbar depends on libfoo, then if libfoo generates key=value as part of its metadata, then the build script of libbar will have the environment variables DEP_FOO_KEY=value.

Okay then. I shall create two crates where b depends on a. a’s build script will generate metadata, and b’s build script will look for the resulting environment variables:

# in an impty directory...

cargo new a
cargo new b

# b depends on a
cat >>b/Cargo.toml <<EOF

# I tried this also with [dependencies], but that seems
# to allow b's build script to run before a's build script,
# in which case the env passing clearly could not work.
a = { path = "../a" }

# a's build script emits custom metadata...
cat >a/ <<EOF
fn main() {
    // examples straight from the cargo docs

# b's build script should see it.
cat >b/ <<EOF
fn main() {
        .filter(|&(ref key, _)| key.starts_with("DEP"))
        .next().expect("no env vars begin with 'DEP'!");

# ...right?
(cd b; cargo build)


     Created library `a` project
     Created library `b` project
   Compiling a v0.1.0 (file:///home/exp/dev/test/cargo-build-dep/a)
   Compiling b v0.1.0 (file:///home/exp/dev/test/cargo-build-dep/b)
error: failed to run custom build command for `b v0.1.0 (file:///home/exp/dev/test/cargo-build-dep/b)`
process didn't exit successfully: `/home/exp/dev/test/cargo-build-dep/b/target/debug/build/b-6e6e15905d151499/build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'no env vars begin with 'DEP'!', /checkout/src/libcore/

It seems to me these environment variables simply are not there. Please let me know what I’m doing wrong.