Skip to content

[DONT MERGE] fix(libstd): switch to -Zpublic-dependency cargo flag#121710

Closed
weihanglo wants to merge 2 commits intorust-lang:masterfrom
weihanglo:public-dependency
Closed

[DONT MERGE] fix(libstd): switch to -Zpublic-dependency cargo flag#121710
weihanglo wants to merge 2 commits intorust-lang:masterfrom
weihanglo:public-dependency

Conversation

@weihanglo
Copy link
Copy Markdown
Member

rust-lang/cargo#13340 switches the feature gate for public-dependency from cargo-features in Cargo.toml to CLI flag -Zpublic-dependency.

cargo-features will continue working for 1 to 2 release cycles as a transition period, to make sure that it doesn't break self-rebuilds.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Feb 27, 2024

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 27, 2024
@weihanglo
Copy link
Copy Markdown
Member Author

Need to wait for rust-lang/cargo#13340 getting into beta, and then we can merge this.

@rust-log-analyzer

This comment has been minimized.

@weihanglo
Copy link
Copy Markdown
Member Author

Got these warnings. There might be more placing needing to change.

warning: /projects/dev/rust/library/std/Cargo.toml: Ignoring `public` on dependency alloc.  Pass `-Zpublic-dependency` to enable support for it
warning: /projects/dev/rust/library/std/Cargo.toml: Ignoring `public` on dependency core.  Pass `-Zpublic-dependency` to enable support for it
warning: /projects/dev/rust/library/std/Cargo.toml: Ignoring `public` on dependency libc.  Pass `-Zpublic-dependency` to enable support for it
warning: /projects/rust/library/std/Cargo.toml: Ignoring `public` on dependency hermit-abi.  Pass `-Zpublic-dependency` to enable support for it
warning: /projects/rust/library/std/Cargo.toml: Ignoring `public` on dependency fortanix-sgx-abi.  Pass `-Zpublic-dependency` to enable support for it

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2024
rust-lang/cargo#13340 switches the featurte gate for public-dependency
from `cargo-features` in Cargo.toml to CLI flag `-Zpublic-dependency`.

`cargo-features` will continue working for 1 to 2 release cycles as a
transition period, to make sure that it doesn't break self-rebuilds.
@weihanglo
Copy link
Copy Markdown
Member Author

Okay. Everything relies on std so every crate is streaming when -Zpublic-dependency Cargo flag is missing.

I have checked with cargo tree -i std. Indeed everything uses std. If I added this:

diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs
index 7f93fdc72ef..8e0d2a0820e 100644
--- a/src/bootstrap/src/core/builder.rs
+++ b/src/bootstrap/src/core/builder.rs
@@ -1799,6 +1799,9 @@ fn cargo(
 
         // Enable usage of unstable features
         cargo.env("RUSTC_BOOTSTRAP", "1");
+        // In addition, we enable Cargo's `-Zpublic-dependency` so that every
+        // build runs `exported-private-dependencies` and suppress unstable warnings.
+        cargo.arg("-Zpublic-dependency");
 
         if self.config.dump_bootstrap_shims {
             prepare_behaviour_dump_dir(self.build);

They every crate then screams like this:

error: trait `core::alloc::Allocator` from private dependency 'core' in public interface
    --> library/alloc/src/vec/mod.rs:2691:1
     |
2691 | pub fn from_elem_in<T: Clone, A: Allocator>(elem: T, n: usize, alloc: A) -> Vec<T, A> {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I cannot even compile stuff unless turning the lint off... (I dunno how in x.py though)

In Cargo we cap-lints dependencies, so those diagnostics wouldn't flood in to users' terminals. However, I wonder the potential performance hit it might cause if public-dependency becomes the default in edition 2024.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Checking cfg-if v1.0.0
    Checking adler v1.0.2
    Checking unwind v0.0.0 (/checkout/library/unwind)
    Checking rustc-demangle v0.1.23
error: type `c_void` from private dependency 'core' in public interface
   |
24 | pub type _Unwind_Trace_Fn =
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   |
   = note: `-D exported-private-dependencies` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(exported_private_dependencies)]`

error: type `Option<extern "C" fn(_Unwind_Reason_Code, *mut _Unwind_Exception)>` from private dependency 'core' in public interface
   |
   |
87 |     pub exception_cleanup: _Unwind_Exception_Cleanup_Fn,


error: type `Option<extern "C" fn(_Unwind_Reason_Code, *mut _Unwind_Exception)>` from private dependency 'core' in public interface
   |
   |
93 | pub type _Unwind_Exception_Cleanup_Fn =


error: type `c_void` from private dependency 'core' in public interface
    |
    |
119 |     pub fn _Unwind_GetLanguageSpecificData(ctx: *mut _Unwind_Context) -> *mut c_void;


error: type `c_void` from private dependency 'core' in public interface
    |
    |
150 |         pub fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void;


error: type `c_void` from private dependency 'core' in public interface
    |
    |
275 | /         pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn,
276 | |                                  trace_argument: *mut c_void)
277 | |                                  -> _Unwind_Reason_Code;

error: could not compile `unwind` (lib) due to 6 previous errors
warning: build failed, waiting for other jobs to finish...
warning: build failed, waiting for other jobs to finish...
error: type `core::alloc::Layout` from private dependency 'core' in public interface
   |
   |
94 | pub unsafe fn alloc(layout: Layout) -> *mut u8 {
   |
   = note: `-D exported-private-dependencies` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(exported_private_dependencies)]`


error: type `core::alloc::Layout` from private dependency 'core' in public interface
    |
    |
118 | pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {


error: type `core::alloc::Layout` from private dependency 'core' in public interface
    |
    |
137 | pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {


error: type `core::alloc::Layout` from private dependency 'core' in public interface
    |
    |
171 | pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {


error: type `core::alloc::Layout` from private dependency 'core' in public interface
    |
    |
242 |     fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {


error: type `Result<NonNull<[u8]>, core::alloc::AllocError>` from private dependency 'core' in public interface
    |
    |
242 |     fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {


error: type `NonNull<[u8]>` from private dependency 'core' in public interface
    |
    |
242 |     fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {


error: type `core::alloc::AllocError` from private dependency 'core' in public interface
    |
    |
242 |     fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {


error: type `core::alloc::Layout` from private dependency 'core' in public interface
    |
    |
247 |     fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {


error: type `Result<NonNull<[u8]>, core::alloc::AllocError>` from private dependency 'core' in public interface
    |
    |
247 |     fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {


error: type `NonNull<[u8]>` from private dependency 'core' in public interface
    |
    |
247 |     fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {


error: type `core::alloc::AllocError` from private dependency 'core' in public interface
    |
    |
247 |     fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {


error: type `NonNull<u8>` from private dependency 'core' in public interface
    |
    |
252 |     unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {


error: type `core::alloc::Layout` from private dependency 'core' in public interface
    |
    |
252 |     unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {


error: type `NonNull<u8>` from private dependency 'core' in public interface
    |
261 | /     unsafe fn grow(
262 | |         &self,
263 | |         ptr: NonNull<u8>,
263 | |         ptr: NonNull<u8>,
264 | |         old_layout: Layout,
265 | |         new_layout: Layout,
266 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `core::alloc::Layout` from private dependency 'core' in public interface
    |
261 | /     unsafe fn grow(
262 | |         &self,
263 | |         ptr: NonNull<u8>,
263 | |         ptr: NonNull<u8>,
264 | |         old_layout: Layout,
265 | |         new_layout: Layout,
266 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `Result<NonNull<[u8]>, core::alloc::AllocError>` from private dependency 'core' in public interface
    |
261 | /     unsafe fn grow(
262 | |         &self,
263 | |         ptr: NonNull<u8>,
263 | |         ptr: NonNull<u8>,
264 | |         old_layout: Layout,
265 | |         new_layout: Layout,
266 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `NonNull<[u8]>` from private dependency 'core' in public interface
    |
261 | /     unsafe fn grow(
262 | |         &self,
263 | |         ptr: NonNull<u8>,
263 | |         ptr: NonNull<u8>,
264 | |         old_layout: Layout,
265 | |         new_layout: Layout,
266 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `core::alloc::AllocError` from private dependency 'core' in public interface
    |
261 | /     unsafe fn grow(
262 | |         &self,
263 | |         ptr: NonNull<u8>,
263 | |         ptr: NonNull<u8>,
264 | |         old_layout: Layout,
265 | |         new_layout: Layout,
266 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `NonNull<u8>` from private dependency 'core' in public interface
    |
    |
272 | /     unsafe fn grow_zeroed(
274 | |         ptr: NonNull<u8>,
275 | |         old_layout: Layout,
276 | |         new_layout: Layout,
276 | |         new_layout: Layout,
277 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `core::alloc::Layout` from private dependency 'core' in public interface
    |
    |
272 | /     unsafe fn grow_zeroed(
274 | |         ptr: NonNull<u8>,
275 | |         old_layout: Layout,
276 | |         new_layout: Layout,
276 | |         new_layout: Layout,
277 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `Result<NonNull<[u8]>, core::alloc::AllocError>` from private dependency 'core' in public interface
    |
    |
272 | /     unsafe fn grow_zeroed(
274 | |         ptr: NonNull<u8>,
275 | |         old_layout: Layout,
276 | |         new_layout: Layout,
276 | |         new_layout: Layout,
277 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `NonNull<[u8]>` from private dependency 'core' in public interface
    |
    |
272 | /     unsafe fn grow_zeroed(
274 | |         ptr: NonNull<u8>,
275 | |         old_layout: Layout,
276 | |         new_layout: Layout,
276 | |         new_layout: Layout,
277 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `core::alloc::AllocError` from private dependency 'core' in public interface
    |
    |
272 | /     unsafe fn grow_zeroed(
274 | |         ptr: NonNull<u8>,
275 | |         old_layout: Layout,
276 | |         new_layout: Layout,
276 | |         new_layout: Layout,
277 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `NonNull<u8>` from private dependency 'core' in public interface
    |
283 | /     unsafe fn shrink(
284 | |         &self,
285 | |         ptr: NonNull<u8>,
285 | |         ptr: NonNull<u8>,
286 | |         old_layout: Layout,
287 | |         new_layout: Layout,
288 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `core::alloc::Layout` from private dependency 'core' in public interface
    |
283 | /     unsafe fn shrink(
284 | |         &self,
285 | |         ptr: NonNull<u8>,
285 | |         ptr: NonNull<u8>,
286 | |         old_layout: Layout,
287 | |         new_layout: Layout,
288 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `Result<NonNull<[u8]>, core::alloc::AllocError>` from private dependency 'core' in public interface
    |
283 | /     unsafe fn shrink(
284 | |         &self,
285 | |         ptr: NonNull<u8>,
285 | |         ptr: NonNull<u8>,
286 | |         old_layout: Layout,
287 | |         new_layout: Layout,
288 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `NonNull<[u8]>` from private dependency 'core' in public interface
    |
283 | /     unsafe fn shrink(
284 | |         &self,
285 | |         ptr: NonNull<u8>,
285 | |         ptr: NonNull<u8>,
286 | |         old_layout: Layout,
287 | |         new_layout: Layout,
288 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `core::alloc::AllocError` from private dependency 'core' in public interface
    |
283 | /     unsafe fn shrink(
284 | |         &self,
285 | |         ptr: NonNull<u8>,
285 | |         ptr: NonNull<u8>,
286 | |         old_layout: Layout,
287 | |         new_layout: Layout,
288 | |     ) -> Result<NonNull<[u8]>, AllocError> {


error: type `core::alloc::Layout` from private dependency 'core' in public interface
    |
377 | pub const fn handle_alloc_error(layout: Layout) -> ! {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


error: trait `Sized` from private dependency 'core' in public interface
   |
50 | impl<T> ThinBox<T> {
   | ^^^^^^^^^^^^^^^^^^


error: type `Result<ThinBox<T>, core::alloc::AllocError>` from private dependency 'core' in public interface
   |
   |
86 |     pub fn try_new(value: T) -> Result<Self, core::alloc::AllocError> {


error: type `core::alloc::AllocError` from private dependency 'core' in public interface
   |
   |
86 |     pub fn try_new(value: T) -> Result<Self, core::alloc::AllocError> {


error: trait `Sized` from private dependency 'core' in public interface
    |
    |
108 | /     pub fn new_unsize<T>(value: T) -> Self
109 | |     where
110 | |         T: Unsize<Dyn>,


error: trait `Unsize<Dyn>` from private dependency 'core' in public interface
    |
    |
108 | /     pub fn new_unsize<T>(value: T) -> Self
109 | |     where
110 | |         T: Unsize<Dyn>,


error: type `Formatter<'_>` from private dependency 'core' in public interface
    |
    |
120 |     fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {


error: type `Result<(), core::fmt::Error>` from private dependency 'core' in public interface
    |
    |
120 |     fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {


error: type `core::fmt::Error` from private dependency 'core' in public interface
    |
    |
120 |     fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {


error: type `Formatter<'_>` from private dependency 'core' in public interface
    |
    |
127 |     fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {


error: type `Result<(), core::fmt::Error>` from private dependency 'core' in public interface
    |
    |
127 |     fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {


error: type `core::fmt::Error` from private dependency 'core' in public interface
    |
    |
127 |     fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {


error: type `Option<&(dyn core::error::Error + 'static)>` from private dependency 'core' in public interface
    |
    |
363 |     fn source(&self) -> Option<&(dyn Error + 'static)> {


error: trait `core::error::Error` from private dependency 'core' in public interface
    |
    |
363 |     fn source(&self) -> Option<&(dyn Error + 'static)> {


error: trait `Sized` from private dependency 'core' in public interface
    |
196 | / pub struct Box<
196 | / pub struct Box<
197 | |     T: ?Sized,
198 | |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
199 | | >(Unique<T>, A);


error: trait `core::alloc::Allocator` from private dependency 'core' in public interface
    |
196 | / pub struct Box<
196 | / pub struct Box<
197 | |     T: ?Sized,
198 | |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
199 | | >(Unique<T>, A);


error: trait `Sized` from private dependency 'core' in public interface
    |
201 | impl<T> Box<T> {
    | ^^^^^^^^^^^^^^


error: type `MaybeUninit<T>` from private dependency 'core' in public interface
    |
243 |     pub fn new_uninit() -> Box<mem::MaybeUninit<T>> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


error: type `MaybeUninit<T>` from private dependency 'core' in public interface
    |
    |
269 |     pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {


error: type `Pin<Box<T>>` from private dependency 'core' in public interface
    |
    |
284 |     pub fn pin(x: T) -> Pin<Box<T>> {


error: type `Result<Box<T>, core::alloc::AllocError>` from private dependency 'core' in public interface
    |
    |
303 |     pub fn try_new(x: T) -> Result<Self, AllocError> {


error: type `core::alloc::AllocError` from private dependency 'core' in public interface
    |
    |
303 |     pub fn try_new(x: T) -> Result<Self, AllocError> {


error: type `Result<Box<MaybeUninit<T>>, core::alloc::AllocError>` from private dependency 'core' in public interface
    |
330 |     pub fn try_new_uninit() -> Result<Box<mem::MaybeUninit<T>>, AllocError> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


error: type `MaybeUninit<T>` from private dependency 'core' in public interface
    |
330 |     pub fn try_new_uninit() -> Result<Box<mem::MaybeUninit<T>>, AllocError> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


error: type `core::alloc::AllocError` from private dependency 'core' in public interface
    |
330 |     pub fn try_new_uninit() -> Result<Box<mem::MaybeUninit<T>>, AllocError> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


error: type `Result<Box<MaybeUninit<T>>, core::alloc::AllocError>` from private dependency 'core' in public interface
    |
    |
356 |     pub fn try_new_zeroed() -> Result<Box<mem::MaybeUninit<T>>, AllocError> {


error: type `MaybeUninit<T>` from private dependency 'core' in public interface
    |
    |
356 |     pub fn try_new_zeroed() -> Result<Box<mem::MaybeUninit<T>>, AllocError> {


error: type `core::alloc::AllocError` from private dependency 'core' in public interface
    |
    |
356 |     pub fn try_new_zeroed() -> Result<Box<mem::MaybeUninit<T>>, AllocError> {


error: trait `Sized` from private dependency 'core' in public interface
    |
    |
361 | impl<T, A: Allocator> Box<T, A> {


error: trait `core::alloc::Allocator` from private dependency 'core' in public interface
    |
    |
361 | impl<T, A: Allocator> Box<T, A> {


error: trait `core::alloc::Allocator` from private dependency 'core' in public interface
    |
    |
379 | /     pub fn new_in(x: T, alloc: A) -> Self
381 | |         A: Allocator,
    | |_____________________^


error: trait `core::alloc::Allocator` from private dependency 'core' in public interface
    |
    |

@weihanglo
Copy link
Copy Markdown
Member Author

Close as we plan to keep both ways for enabling the public-dependency feature.

@weihanglo weihanglo closed this May 24, 2024
@weihanglo weihanglo deleted the public-dependency branch May 24, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants