Skip to content

Commit

Permalink
Clarify how cargo::metadata env var is selected (#14842)
Browse files Browse the repository at this point in the history
### What does this PR try to resolve?

At least for me, the explanation of how to use `cargo::metadata` is
confusing. It seems to imply that the `X` in `DEP_X_KEY` is derived from
the crate name, but it is actually derived from the `links` value in the
package. This PR tries to rephrase the explanation to make this less
confusing.
  • Loading branch information
weihanglo authored Nov 20, 2024
2 parents 66221ab + 17ba198 commit fbbc176
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/doc/src/reference/build-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,12 @@ key-value pairs. This metadata is set with the `cargo::metadata=KEY=VALUE`
instruction.

The metadata is passed to the build scripts of **dependent** packages. For
example, if the package `bar` depends on `foo`, then if `foo` generates
`key=value` as part of its build script metadata, then the build script of
`bar` will have the environment variables `DEP_FOO_KEY=value`. See the ["Using
another `sys` crate"][using-another-sys] for an example of how this can be
used.
example, if the package `foo` depends on `bar`, which links `baz`, then if
`bar` generates `key=value` as part of its build script metadata, then the
build script of `foo` will have the environment variables `DEP_BAZ_KEY=value`
(note that the value of the `links` key is used).
See the ["Using another `sys` crate"][using-another-sys] for an example of
how this can be used.

Note that metadata is only passed to immediate dependents, not transitive
dependents.
Expand Down

0 comments on commit fbbc176

Please sign in to comment.