cargo icon indicating copy to clipboard operation
cargo copied to clipboard

cargo: prevent dashes in lib.name

Open dvdhrm opened this issue 8 months ago • 11 comments

The TOML parser of Cargo currently refuses lib.name entries that contain dashes. Unfortunately, it uses the package-name as default if no explicit lib.name entry is specified. This package-name, however, can contain dashes.

Cargo documentation states that the package name is converted first, yet this was never implemented by the code-base.

Fix this inconsistency and convert the package name to a suitable crate-name first.

This fixes #12780. It is an alternative to #12640.

dvdhrm avatar Oct 06 '23 13:10 dvdhrm

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @weihanglo (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

rustbot avatar Oct 06 '23 13:10 rustbot

(update: fixed rustfmt complaints)

dvdhrm avatar Oct 06 '23 13:10 dvdhrm

@rfcbot fcp merge

When auto-filling lib.name, cargo has a discrepancy

  • documentation: says lib.name will use _
  • implementation: any - -> _ conversion happens later in the process, missing some areas like cargo metadata and environment variables set for artifact dependencies

We talked in the cargo team meeting about leaning towards making the code match the documentation. This FCP is a strawpoll to confirm that.

In stable rust, this only affects the lib name in cargo metadata. I've been looking for any other way this may manifest, including our environment variables and haven't seen any so far.

epage avatar Oct 06 '23 13:10 epage

Team member @epage has proposed to merge this. The next step is review by the rest of the tagged team members:

  • [x] @Eh2406
  • [ ] @Muscraft
  • [x] @arlosi
  • [x] @ehuss
  • [x] @epage
  • [ ] @joshtriplett
  • [x] @weihanglo

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

rfcbot avatar Oct 06 '23 13:10 rfcbot

Hm, I didn't think about the consequence of this impacting the artifact-dependency environment variables, which appears to be a breaking change. For example, I did a quick code search and found https://github.com/lf-/clipper/blob/dd1caf13191e0fa58afbc3680fb83782c20e63d2/fixtures/dlopen-openssl-fixture/src/main.rs#L9 which would break with this change.

I'm not sure what to do about that. Perhaps one option is to set both environment variables for backwards compatibility?

ehuss avatar Oct 07 '23 19:10 ehuss

The RFC says the env-var is named after the "crate", so this is actually a fix. But that is more of a theoretical argument, it is still a breaking change.

dvdhrm avatar Oct 08 '23 08:10 dvdhrm

. Perhaps one option is to set both environment variables for backwards compatibility?

If that works, it seems reasonable.

epage avatar Oct 09 '23 18:10 epage

(update: we now remember whether target-names were inferred, which in turn allows us to keep setting the previously used artifact env-vars)

dvdhrm avatar Oct 13 '23 11:10 dvdhrm

The bindeps and multidep features of Cargo are unstable, but the new revision of this PR tries to avoid breakage in the env-vars of these features. Unfortunately, dash->underscore conversion is lossy, so we cannot reliably tell whether compatibility-mode is required. Therefore, I extended the Cargo-internal manifest state to remember whether a target-name was inferred, or whether it is explicit. Now we know whether a target-name used to be different in the past, and we can use this information to keep backwards-compatibility.

Note that I think the stripped env-var of bindeps is quite confusing, since changing the dep-name locally will affect which env-var becomes the stripped one. I think I did my best to retain this behavior, so this should be fine.

dvdhrm avatar Oct 13 '23 11:10 dvdhrm

(update: rebase to master to fix CI failures)

dvdhrm avatar Oct 17 '23 11:10 dvdhrm

(Any update on this?)

dvdhrm avatar Dec 21 '23 13:12 dvdhrm

@Eh2406, @Muscraft, @joshtriplett do you think you can check the FCP above? Do you have any questions or concerns? Anything that can help you understand this change?

ehuss avatar Mar 01 '24 23:03 ehuss

Sorry for the delay in ✔️

Eh2406 avatar Mar 05 '24 19:03 Eh2406

:bell: This is now entering its final comment period, as per the review above. :bell:

rfcbot avatar Mar 05 '24 19:03 rfcbot

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

rfcbot avatar Mar 15 '24 19:03 rfcbot

Thanks! Will merge now that the FCP has passed.

@bors r+

ehuss avatar Mar 16 '24 20:03 ehuss

:pushpin: Commit 3ca04e261e1abde062b1c58a31a0ae622547d972 has been approved by ehuss

It is now in the queue for this repository.

bors avatar Mar 16 '24 20:03 bors

:hourglass: Testing commit 3ca04e261e1abde062b1c58a31a0ae622547d972 with merge 69726309bf12443a618643cc86125ef60dcbecfb...

bors avatar Mar 16 '24 20:03 bors

:sunny: Test successful - checks-actions Approved by: ehuss Pushing 69726309bf12443a618643cc86125ef60dcbecfb to master...

bors avatar Mar 16 '24 21:03 bors