Skip to content

Commit 1548a7e

Browse files
committed
Introduce CARGO_PKG_EDITION env var
Solves #14872
1 parent 27366fd commit 1548a7e

File tree

8 files changed

+18
-5
lines changed

8 files changed

+18
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ anstyle = "1.0.10"
2424
anyhow = "1.0.95"
2525
base64 = "0.22.1"
2626
blake3 = "1.5.5"
27-
build-rs = { version = "0.3.0", path = "crates/build-rs" }
27+
build-rs = { version = "0.3.1", path = "crates/build-rs" }
2828
cargo = { path = "" }
2929
cargo-credential = { version = "0.4.2", path = "credential/cargo-credential" }
3030
cargo-credential-libsecret = { version = "0.4.13", path = "credential/cargo-credential-libsecret" }

crates/build-rs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "build-rs"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
rust-version.workspace = true
55
edition.workspace = true
66
license.workspace = true

crates/build-rs/src/input.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,12 @@ pub fn cargo_pkg_license_file() -> Option<PathBuf> {
604604
to_opt(var_or_panic("CARGO_PKG_LICENSE_FILE")).map(to_path)
605605
}
606606

607+
/// The Rust language edition from the manifest of your package.
608+
#[track_caller]
609+
pub fn cargo_pkg_edition() -> Option<String> {
610+
to_opt(var_or_panic("CARGO_PKG_EDITION")).map(to_string)
611+
}
612+
607613
/// The Rust version from the manifest of your package. Note that this is the
608614
/// minimum Rust version supported by the package, not the current Rust version.
609615
#[track_caller]

src/cargo/core/compiler/compilation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ impl<'gctx> Compilation<'gctx> {
360360
// in BuildContext::target_metadata()
361361
cmd.env("CARGO_MANIFEST_DIR", pkg.root())
362362
.env("CARGO_MANIFEST_PATH", pkg.manifest_path())
363+
.env("CARGO_PKG_EDITION", pkg.edition().to_string())
363364
.env("CARGO_PKG_VERSION_MAJOR", &pkg.version().major.to_string())
364365
.env("CARGO_PKG_VERSION_MINOR", &pkg.version().minor.to_string())
365366
.env("CARGO_PKG_VERSION_PATCH", &pkg.version().patch.to_string())

src/cargo/core/package.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use crate::core::dependency::DepKind;
2222
use crate::core::resolver::features::ForceAllTargets;
2323
use crate::core::resolver::{HasDevUnits, Resolve};
2424
use crate::core::{
25-
CliUnstable, Dependency, Features, Manifest, PackageId, PackageIdSpec, SerializedDependency,
26-
SourceId, Target,
25+
CliUnstable, Dependency, Edition, Features, Manifest, PackageId, PackageIdSpec,
26+
SerializedDependency, SourceId, Target,
2727
};
2828
use crate::core::{Summary, Workspace};
2929
use crate::sources::source::{MaybePackage, SourceMap};
@@ -167,6 +167,10 @@ impl Package {
167167
pub fn proc_macro(&self) -> bool {
168168
self.targets().iter().any(|target| target.proc_macro())
169169
}
170+
/// Gets the package's language edition
171+
pub fn edition(&self) -> Edition {
172+
self.manifest().edition()
173+
}
170174
/// Gets the package's minimum Rust version.
171175
pub fn rust_version(&self) -> Option<&RustVersion> {
172176
self.manifest().rust_version()

src/doc/src/reference/environment-variables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ corresponding environment variable is set to the empty string, `""`.
239239
* `CARGO_PKG_REPOSITORY` --- The repository from the manifest of your package.
240240
* `CARGO_PKG_LICENSE` --- The license from the manifest of your package.
241241
* `CARGO_PKG_LICENSE_FILE` --- The license file from the manifest of your package.
242+
* `CARGO_PKG_EDITION` --- The Rust language edition from the manifest of your package.
242243
* `CARGO_PKG_RUST_VERSION` --- The Rust version from the manifest of your package.
243244
Note that this is the minimum Rust version supported by the package, not the
244245
current Rust version.

tests/testsuite/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,7 @@ fn crate_env_vars() {
16261626
static LICENSE: &'static str = env!("CARGO_PKG_LICENSE");
16271627
static LICENSE_FILE: &'static str = env!("CARGO_PKG_LICENSE_FILE");
16281628
static DESCRIPTION: &'static str = env!("CARGO_PKG_DESCRIPTION");
1629+
static EDITION: &'static str = env!("CARGO_PKG_EDITION");
16291630
static RUST_VERSION: &'static str = env!("CARGO_PKG_RUST_VERSION");
16301631
static README: &'static str = env!("CARGO_PKG_README");
16311632
static BIN_NAME: &'static str = env!("CARGO_BIN_NAME");

0 commit comments

Comments
 (0)