From 5531cd380684449d6342ada49d1e56fb8ec71067 Mon Sep 17 00:00:00 2001 From: chansuke Date: Sat, 28 Jan 2023 18:47:04 +0900 Subject: [PATCH 1/5] Add new environment variable `CARGO_PKG_README` --- src/cargo/core/compiler/compilation.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index ffd3881dc57..29642f13d79 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -343,6 +343,10 @@ impl<'cfg> Compilation<'cfg> { "CARGO_PKG_RUST_VERSION", &pkg.rust_version().unwrap_or(&String::new()), ) + .env( + "CARGO_PKG_README", + metadata.readme.as_ref().unwrap_or(&String::new()), + ) .cwd(pkg.root()); // Apply any environment variables from the config From ec8aa3e8d50f18cd362dfa16d5f03e6170b89f16 Mon Sep 17 00:00:00 2001 From: chansuke Date: Sat, 28 Jan 2023 18:59:41 +0900 Subject: [PATCH 2/5] Add an explanation of `CARGO_PKG_README` --- src/doc/src/reference/environment-variables.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index 2ed986fb5d2..2a7fe9da26c 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -231,11 +231,12 @@ corresponding environment variable is set to the empty string, `""`. * `CARGO_PKG_RUST_VERSION` --- The Rust version from the manifest of your package. Note that this is the minimum Rust version supported by the package, not the current Rust version. +* `CARGO_PKG_README` — The location of README of your package. * `CARGO_CRATE_NAME` --- The name of the crate that is currently being compiled. It is the name of the [Cargo target] with `-` converted to `_`, such as the name of the library, binary, example, integration test, or benchmark. * `CARGO_BIN_NAME` --- The name of the binary that is currently being compiled. Only set for [binaries] or binary [examples]. This name does not include any file extension, such as `.exe`. -* `OUT_DIR` --- If the package has a build script, this is set to the folder where the build +* `OUT_DIR` — If the package has a build script, this is set to the folder where the build script should place its output. See below for more information. (Only set during compilation.) * `CARGO_BIN_EXE_` --- The absolute path to a binary target's executable. From fb9be455cd55acd30bd17dc207f9367c032a99d6 Mon Sep 17 00:00:00 2001 From: chansuke Date: Sat, 28 Jan 2023 19:05:16 +0900 Subject: [PATCH 3/5] Add tests for `CARGO_PKG_README` --- tests/testsuite/build.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index ca7f669b2e1..743f3612560 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -1370,6 +1370,7 @@ fn crate_env_vars() { license = "MIT OR Apache-2.0" license-file = "license.txt" rust-version = "1.61.0" + readme = "../../README.md" [[bin]] name = "foo-bar" @@ -1395,6 +1396,7 @@ fn crate_env_vars() { static LICENSE_FILE: &'static str = env!("CARGO_PKG_LICENSE_FILE"); static DESCRIPTION: &'static str = env!("CARGO_PKG_DESCRIPTION"); static RUST_VERSION: &'static str = env!("CARGO_PKG_RUST_VERSION"); + static README: &'static str = env!("CARGO_PKG_README"); static BIN_NAME: &'static str = env!("CARGO_BIN_NAME"); static CRATE_NAME: &'static str = env!("CARGO_CRATE_NAME"); @@ -1414,6 +1416,7 @@ fn crate_env_vars() { assert_eq!("license.txt", LICENSE_FILE); assert_eq!("This is foo", DESCRIPTION); assert_eq!("1.61.0", RUST_VERSION); + assert_eq!("../../README.md", README); let s = format!("{}.{}.{}-{}", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_PRE); assert_eq!(s, VERSION); From 8d53dd9e95601df911100fb3e26c9168e795743e Mon Sep 17 00:00:00 2001 From: chansuke Date: Fri, 3 Mar 2023 22:46:32 +0900 Subject: [PATCH 4/5] Update description of CARGO_PKG_README --- src/doc/src/reference/environment-variables.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index 2a7fe9da26c..deb08ab6e4c 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -231,12 +231,12 @@ corresponding environment variable is set to the empty string, `""`. * `CARGO_PKG_RUST_VERSION` --- The Rust version from the manifest of your package. Note that this is the minimum Rust version supported by the package, not the current Rust version. -* `CARGO_PKG_README` — The location of README of your package. +* `CARGO_PKG_README` — Path to the README file of your package. * `CARGO_CRATE_NAME` --- The name of the crate that is currently being compiled. It is the name of the [Cargo target] with `-` converted to `_`, such as the name of the library, binary, example, integration test, or benchmark. * `CARGO_BIN_NAME` --- The name of the binary that is currently being compiled. Only set for [binaries] or binary [examples]. This name does not include any file extension, such as `.exe`. -* `OUT_DIR` — If the package has a build script, this is set to the folder where the build +* `OUT_DIR` --- If the package has a build script, this is set to the folder where the build script should place its output. See below for more information. (Only set during compilation.) * `CARGO_BIN_EXE_` --- The absolute path to a binary target's executable. From 34a17ead18bdca04c63ed393640528ad6bc73bfd Mon Sep 17 00:00:00 2001 From: chansuke Date: Fri, 3 Mar 2023 23:55:39 +0900 Subject: [PATCH 5/5] Fix the dash of description --- src/doc/src/reference/environment-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index deb08ab6e4c..95c4c87fbb9 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -231,7 +231,7 @@ corresponding environment variable is set to the empty string, `""`. * `CARGO_PKG_RUST_VERSION` --- The Rust version from the manifest of your package. Note that this is the minimum Rust version supported by the package, not the current Rust version. -* `CARGO_PKG_README` — Path to the README file of your package. +* `CARGO_PKG_README` --- Path to the README file of your package. * `CARGO_CRATE_NAME` --- The name of the crate that is currently being compiled. It is the name of the [Cargo target] with `-` converted to `_`, such as the name of the library, binary, example, integration test, or benchmark. * `CARGO_BIN_NAME` --- The name of the binary that is currently being compiled. Only set for [binaries] or binary [examples]. This name does not include any