Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 2 additions & 0 deletions crates/build-rs-test-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Comment on lines +54 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If only we had cfg_version...

How do we plan to track addressing this?

dbg!(cargo_pkg_homepage());
dbg!(cargo_pkg_license());
dbg!(cargo_pkg_license_file());
Expand Down
2 changes: 1 addition & 1 deletion crates/build-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions crates/build-rs/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,13 @@ pub fn cargo_pkg_description() -> Option<String> {
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<String> {
to_opt(var_or_panic("CARGO_PKG_EDITION")).map(to_string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this using to_opt? Won;t the edition always have a non-empty value, like cargo_pkg_name?

}

/// The home page from the manifest of your package.
#[track_caller]
pub fn cargo_pkg_homepage() -> Option<String> {
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
8 changes: 6 additions & 2 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/doc/src/reference/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also warn people about the deprecated behavior?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but not certain about @epage's "deprecated behavior"

That this would be insufficient for projects using the deprecated cargo test editions.

Unsure how important that would be considering it is deprecated, its use was very low, etc.

* `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.
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading