From 042c613f227ae208f393a6401d3ce10eba7b8d1d Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Wed, 31 Dec 2025 10:21:38 +0900 Subject: [PATCH 1/3] feat: Added any-build-script-metadata unstable feature --- src/cargo/core/features.rs | 2 + src/doc/src/reference/unstable.md | 11 ++ tests/testsuite/cargo/z_help/stdout.term.svg | 102 ++++++++++--------- 3 files changed, 65 insertions(+), 50 deletions(-) diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index edf02b00555..793ff378c78 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -844,6 +844,7 @@ unstable_cli_options!( // All other unstable features. // Please keep this list lexicographically ordered. advanced_env: bool, + any_build_script_metadata: bool = ("Allow any build script to specify env vars via cargo::metadata=key=value"), asymmetric_token: bool = ("Allows authenticating with asymmetric tokens"), avoid_dev_deps: bool = ("Avoid installing dev-dependencies if possible"), binary_dep_depinfo: bool = ("Track changes to dependency artifacts"), @@ -1374,6 +1375,7 @@ impl CliUnstable { // Unstable features // Sorted alphabetically: "advanced-env" => self.advanced_env = parse_empty(k, v)?, + "any-build-script-metadata" => self.any_build_script_metadata = parse_empty(k, v)?, "asymmetric-token" => self.asymmetric_token = parse_empty(k, v)?, "avoid-dev-deps" => self.avoid_dev_deps = parse_empty(k, v)?, "binary-dep-depinfo" => self.binary_dep_depinfo = parse_empty(k, v)?, diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 16b5260222c..9c48ac61e8d 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -67,6 +67,7 @@ Each new feature described below should explain how to use it. * Build scripts and linking * [Metabuild](#metabuild) --- Provides declarative build scripts. * [Multiple Build Scripts](#multiple-build-scripts) --- Allows use of multiple build scripts. + * [Any Build Script Metadata](#any-build-script-metadata) --- Allow any build script to specify env vars via `cargo::metadata=key=value` * Resolver and features * [no-index-update](#no-index-update) --- Prevents cargo from updating the index cache. * [avoid-dev-deps](#avoid-dev-deps) --- Prevents the resolver from including dev-dependencies during resolution. @@ -313,6 +314,16 @@ build = ["foo.rs", "bar.rs"] where the `` is the file-stem of the build script, exactly as-is. For example, `bar_OUT_DIR` for script at `foo/bar.rs`. (Only set during compilation, can be accessed via `env!` macro) +## Any Build Script Metadata +* Tracking Issue: [#14903](https://github.com/rust-lang/cargo/issues/3544) + +Allow any build script to specify env vars via `cargo::metadata=key=value` + +Depedant build scripts can access these key/value pair by reading the `CARGO_DEP__` env variable at runtime. +For build scripts of crates with a `links`, both `DEP__` and `CARGO_DEP__` will be set. + +Note that `dep` and `key` in `CARGO_DEP__` are uppercased and hyphens (`-`) replaced with underscores (`_`). + ## public-dependency * Tracking Issue: [#44663](https://github.com/rust-lang/rust/issues/44663) diff --git a/tests/testsuite/cargo/z_help/stdout.term.svg b/tests/testsuite/cargo/z_help/stdout.term.svg index f5a3513c066..20006653417 100644 --- a/tests/testsuite/cargo/z_help/stdout.term.svg +++ b/tests/testsuite/cargo/z_help/stdout.term.svg @@ -1,4 +1,4 @@ - +