Skip to content

Introduce CARGO_PKG_EDITION env var #14873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nyurik
Copy link
Contributor

@nyurik nyurik commented Nov 29, 2024

Add CARGO_PKG_EDITION environment variable, allowing build scripts to determine the language edition of the crate being compiled.

Fixes #14872

TBD - EnvVar Name

  • CARGO_PKG_EDITION
  • CARGO_PKG_RUST_EDITION
  • CARGO_PKG_LANG_EDITION
  • CARGO_PKG_LANGUAGE_EDITION
  • ...?

@rustbot
Copy link
Collaborator

rustbot commented Nov 29, 2024

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-documenting-cargo-itself Area: Cargo's documentation S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 29, 2024
@nyurik nyurik force-pushed the pkg-lang-edition branch 3 times, most recently from a759287 to e7f96b4 Compare November 29, 2024 22:13
@epage
Copy link
Contributor

epage commented Nov 29, 2024

As a heads up, our contribution process asks that issues be accepted before moving on to PRs. There are two directions to go and this direction has non-obvious problems to work through. We should work through this first before looking at the implementation.

@bors
Copy link
Contributor

bors commented Dec 6, 2024

☔ The latest upstream changes (presumably 2560340) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot

This comment has been minimized.

@epage epage added the T-cargo Team: Cargo label Apr 11, 2025
@@ -239,6 +239,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.

@nyurik nyurik force-pushed the pkg-lang-edition branch from e7f96b4 to 1548a7e Compare April 11, 2025 18:10
@rustbot rustbot added the A-build-scripts Area: build.rs scripts label Apr 11, 2025
@nyurik
Copy link
Contributor Author

nyurik commented Apr 11, 2025

@epage i rebased this PR. WRT your MSRV comments --- what kind of message do you think would be needed, and which version? Thx!

@rustbot

This comment has been minimized.

@nyurik nyurik force-pushed the pkg-lang-edition branch 3 times, most recently from 4774130 to cb33b41 Compare August 18, 2025 05:03
@nyurik
Copy link
Contributor Author

nyurik commented Aug 18, 2025

It seems the smoke test does not work until after this change is released as part of cargo, so commenting it out. Otherwise seems to work ok? I updated the MSRV message, but not certain about @epage's "deprecated behavior" comment

#[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?

Comment on lines +54 to +55
// FIXME: enable once released?
// dbg!(cargo_pkg_edition());
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-build-scripts Area: build.rs scripts A-documenting-cargo-itself Area: Cargo's documentation S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cargo Team: Cargo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export CARGO_PKG_EDITION variable to build environment
4 participants