diff --git a/Cargo.lock b/Cargo.lock index 5a07c6dbd7f..025a57b85ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -267,7 +267,7 @@ dependencies = [ [[package]] name = "build-rs" -version = "0.3.2" +version = "0.3.3" dependencies = [ "unicode-ident", ] diff --git a/Cargo.toml b/Cargo.toml index 30dfc609533..ee2cdb71557 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ anstyle = "1.0.11" anyhow = "1.0.98" base64 = "0.22.1" blake3 = "1.8.2" -build-rs = { version = "0.3.1", path = "crates/build-rs" } +build-rs = { version = "0.3.3", path = "crates/build-rs" } cargo = { path = "" } cargo-credential = { version = "0.4.2", path = "credential/cargo-credential" } cargo-credential-libsecret = { version = "0.5.2", path = "credential/cargo-credential-libsecret" } diff --git a/crates/build-rs-test-lib/build.rs b/crates/build-rs-test-lib/build.rs index 0592a374915..db47b09203b 100644 --- a/crates/build-rs-test-lib/build.rs +++ b/crates/build-rs-test-lib/build.rs @@ -51,6 +51,8 @@ fn smoke_test_inputs() { dbg!(cargo_manifest_links()); dbg!(cargo_pkg_authors()); dbg!(cargo_pkg_description()); + // FIXME: enable once released? + // dbg!(cargo_pkg_edition()); dbg!(cargo_pkg_homepage()); dbg!(cargo_pkg_license()); dbg!(cargo_pkg_license_file()); diff --git a/crates/build-rs/Cargo.toml b/crates/build-rs/Cargo.toml index 093f22cd730..a340cf9436a 100644 --- a/crates/build-rs/Cargo.toml +++ b/crates/build-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "build-rs" -version = "0.3.2" +version = "0.3.3" rust-version.workspace = true edition.workspace = true license.workspace = true diff --git a/crates/build-rs/src/input.rs b/crates/build-rs/src/input.rs index d8a75d41922..bafd371115c 100644 --- a/crates/build-rs/src/input.rs +++ b/crates/build-rs/src/input.rs @@ -580,6 +580,13 @@ pub fn cargo_pkg_description() -> Option { to_opt(var_or_panic("CARGO_PKG_DESCRIPTION")).map(to_string) } +/// The Rust language edition from the manifest of your package. +#[doc = requires_msrv!("1.91")] +#[track_caller] +pub fn cargo_pkg_edition() -> Option { + to_opt(var_or_panic("CARGO_PKG_EDITION")).map(to_string) +} + /// The home page from the manifest of your package. #[track_caller] pub fn cargo_pkg_homepage() -> Option { diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 68b59ba0cac..0e5c8351ec1 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -362,6 +362,7 @@ impl<'gctx> Compilation<'gctx> { // in BuildContext::target_metadata() cmd.env("CARGO_MANIFEST_DIR", pkg.root()) .env("CARGO_MANIFEST_PATH", pkg.manifest_path()) + .env("CARGO_PKG_EDITION", pkg.edition().to_string()) .env("CARGO_PKG_VERSION_MAJOR", &pkg.version().major.to_string()) .env("CARGO_PKG_VERSION_MINOR", &pkg.version().minor.to_string()) .env("CARGO_PKG_VERSION_PATCH", &pkg.version().patch.to_string()) diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index b84df9ae707..e3e3dcf3256 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -22,8 +22,8 @@ use crate::core::dependency::DepKind; use crate::core::resolver::features::ForceAllTargets; use crate::core::resolver::{HasDevUnits, Resolve}; use crate::core::{ - CliUnstable, Dependency, Features, Manifest, PackageId, PackageIdSpec, SerializedDependency, - SourceId, Target, + CliUnstable, Dependency, Edition, Features, Manifest, PackageId, PackageIdSpec, + SerializedDependency, SourceId, Target, }; use crate::core::{Summary, Workspace}; use crate::sources::source::{MaybePackage, SourceMap}; @@ -169,6 +169,10 @@ impl Package { pub fn proc_macro(&self) -> bool { self.targets().iter().any(|target| target.proc_macro()) } + /// Gets the package's language edition + pub fn edition(&self) -> Edition { + self.manifest().edition() + } /// Gets the package's minimum Rust version. pub fn rust_version(&self) -> Option<&RustVersion> { self.manifest().rust_version() diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index 253a16258f8..699311d4535 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -245,6 +245,7 @@ corresponding environment variable is set to the empty string, `""`. * `CARGO_PKG_REPOSITORY` --- The repository from the manifest of your package. * `CARGO_PKG_LICENSE` --- The license from the manifest of your package. * `CARGO_PKG_LICENSE_FILE` --- The license file from the manifest of your package. +* `CARGO_PKG_EDITION` --- The Rust language edition from the manifest of your package. * `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. diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 4c44c8836b8..6896f06cdf3 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -1629,6 +1629,7 @@ fn crate_env_vars() { static LICENSE: &'static str = env!("CARGO_PKG_LICENSE"); static LICENSE_FILE: &'static str = env!("CARGO_PKG_LICENSE_FILE"); static DESCRIPTION: &'static str = env!("CARGO_PKG_DESCRIPTION"); + static EDITION: &'static str = env!("CARGO_PKG_EDITION"); 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");