Skip to content
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

fix: cfg-gate the #![crate_name] and #![crate_type] attributes #4170

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

Conversation

aatifsyed
Copy link

Description

I was vendoring libc as part of a C codebase that uses the meson build system.
This involved renaming the crate:

rust3p_libc = library('rust3p_libc', ...)

But these attributes clash with meson passing the --crate-name argument to rustc.

rustc -C linker=cc --color=always -C debug-assertions=yes -C overflow-checks=no --crate-type rlib -C opt-level=3 --crate-name rust3p_libc --emit dep-info=rust3p/rust3p_libc.d --emit link=rust3p/librust3p_libc.rlib --out-dir rust3p/librust3p_libc.rlib.p -C metadata=46de84a@@rust3p_libc@sta --edition=2015 --cfg 'feature="std"' ../rust3p/vendor/libc/src/lib.rs
error: `--crate-name` and `#[crate_name]` are required to match, but `rust3p_libc` != `libc`
 --> ../rust3p/vendor/libc/src/lib.rs:2:1
  |
2 | #![crate_name = "libc"]
  | ^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

It looks like this attribute was added to support "rustc-dep-of-std" in #28
Considering the rest of that code is #[cfg(feature = ...)] gated, moving this seems like the right the to do.

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI
    ^ I can't run this on `main` locally :S
    

@rustbot
Copy link
Collaborator

rustbot commented Dec 2, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @JohnTitor (or someone else) some time within the next two weeks.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants