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

Failed to build the Rust Compiler on Apple M1 #1739

Closed
arttet opened this issue Sep 23, 2024 · 4 comments
Closed

Failed to build the Rust Compiler on Apple M1 #1739

arttet opened this issue Sep 23, 2024 · 4 comments
Labels
customer-request Documents customer requests.

Comments

@arttet
Copy link

arttet commented Sep 23, 2024

the trait `FromZeroes` is not implemented for `byteorder::U16`
  error[E0786]: found invalid metadata files for crate `zerocopy_derive`
     --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/lib.rs:285:9
      |
  285 | pub use zerocopy_derive::Unaligned;
      |         ^^^^^^^^^^^^^^^
      |
      = note: no `.rustc` section in '/Users/runner/work/rust-compiler-builder/rust-compiler-builder/rust/build/aarch64-apple-darwin/stage1-rustc/arm64e-apple-darwin/release/deps/libzerocopy_derive-85cad85f9873b5cd.dylib'
  
  error[E0786]: found invalid metadata files for crate `zerocopy_derive`
     --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/lib.rs:293:9
      |
  293 | pub use zerocopy_derive::KnownLayout;
      |         ^^^^^^^^^^^^^^^
      |
      = note: no `.rustc` section in '/Users/runner/work/rust-compiler-builder/rust-compiler-builder/rust/build/aarch64-apple-darwin/stage1-rustc/arm64e-apple-darwin/release/deps/libzerocopy_derive-85cad85f9873b5cd.dylib'
  
  error[E0786]: found invalid metadata files for crate `zerocopy_derive`
      --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/lib.rs:1118:9
       |
  1118 | pub use zerocopy_derive::FromZeroes;
       |         ^^^^^^^^^^^^^^^
       |
       = note: no `.rustc` section in '/Users/runner/work/rust-compiler-builder/rust-compiler-builder/rust/build/aarch64-apple-darwin/stage1-rustc/arm64e-apple-darwin/release/deps/libzerocopy_derive-85cad85f9873b5cd.dylib'
  
  error[E0786]: found invalid metadata files for crate `zerocopy_derive`
      --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/lib.rs:1733:9
       |
  1733 | pub use zerocopy_derive::FromBytes;
       |         ^^^^^^^^^^^^^^^
       |
       = note: no `.rustc` section in '/Users/runner/work/rust-compiler-builder/rust-compiler-builder/rust/build/aarch64-apple-darwin/stage1-rustc/arm64e-apple-darwin/release/deps/libzerocopy_derive-85cad85f9873b5cd.dylib'
  
  error[E0786]: found invalid metadata files for crate `zerocopy_derive`
      --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/lib.rs:2599:9
       |
  2599 | pub use zerocopy_derive::AsBytes;
       |         ^^^^^^^^^^^^^^^
       |
       = note: no `.rustc` section in '/Users/runner/work/rust-compiler-builder/rust-compiler-builder/rust/build/aarch64-apple-darwin/stage1-rustc/arm64e-apple-darwin/release/deps/libzerocopy_derive-85cad85f9873b5cd.dylib'
  
  error[E0432]: unresolved import `crate::KnownLayout`
    --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/util.rs:21:34
     |
  21 |     use crate::{util::AsAddress, KnownLayout, _CastType};
     |                                  ^^^^^^^^^^^
  
  error[E0277]: the trait bound `byteorder::U16<O>: FromZeroes` is not satisfied
     --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/byteorder.rs:292:49
      |
  236 | / macro_rules! define_type {
  237 | |     ($article:ident,
  238 | |         $name:ident,
  239 | |         $native:ident,
  ...   |
  292 | |             impl_or_verify!(O => FromZeroes for $name<O>);
      | |                                                 ^^^^^^^^ the trait `FromZeroes` is not implemented for `byteorder::U16<O>`
  ...   |
  462 | |     };
  463 | | }
      | |_- in this expansion of `define_type!`
  464 |
  465 | / define_type!(
  466 | |     A,
  467 | |     U16,
  468 | |     u16,
  ...   |
  477 | |     [U32, U64, U128]
  478 | | );
      | |_- in this macro invocation
      |
      = help: the following other types implement trait `FromZeroes`:
                ()
                *const T
                *mut T
                ManuallyDrop<T>
                MaybeUninit<T>
                Option<&T>
                Option<&mut T>
                Option<NonNull<T>>
              and 103 others
  note: required by a bound in `byteorder::_::_::Subtrait`
     --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/macros.rs:323:29
      |
  28  | / macro_rules! safety_comment {
  29  | |     (#[doc = r" SAFETY:"] $($(#[$attr:meta])* $macro:ident!$args:tt;)*) => {
  30  | |         #[allow(clippy::undocumented_unsafe_blocks, unused_attributes)]
  31  | |         const _: () = { $($(#[$attr])* $macro!$args;)* };
      | |                                        ------------ in this macro invocation (#3)
  32  | |     }
  33  | | }
      | |_- in this expansion of `safety_comment!` (#2)
  ...
  279 | / macro_rules! impl_or_verify {
  280 | |     // The following two match arms follow the same pattern as their
  281 | |     // counterparts in `unsafe_impl!`; see the documentation on those arms for
  282 | |     // more details.
  ...   |
  302 | /         impl_or_verify!(@verify $trait, {
  303 |               impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {}
  304 | |         });
      | |__________- in this macro invocation (#4)
  ...
  323 | |             trait Subtrait: $trait {}
      | |                             ^^^^^^ required by this bound in `Subtrait`
  ...   |
  326 | |     };
  327 | | }
      | | -
      | |_|
      | |_in this expansion of `impl_or_verify!` (#3)
      |   in this expansion of `impl_or_verify!` (#4)
      |
     ::: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/byteorder.rs:236:1
      |
  236 | / macro_rules! define_type {
  237 | |     ($article:ident,
  238 | |         $name:ident,
  239 | |         $native:ident,
  ...   |
  287 | /         safety_comment! {
  288 |               /// SAFETY:
  289 |               /// `$name<O>` is `repr(transparent)`, and so it has the same layout
  290 |               /// as its only non-zero field, which is a `u8` array. `u8` arrays
  ...
  295 |               impl_or_verify!(O => Unaligned for $name<O>);
  296 | |         }
      | |_________- in this macro invocation (#2)
  ...
  462 | |     };
  463 | | }
      | |_- in this expansion of `define_type!` (#1)
  464 |
  465 | / define_type!(
  466 | |     A,
  467 | |     U16,
  468 | |     u16,
  ...   |
  477 | |     [U32, U64, U128]
  478 | | );
      | |_- in this macro invocation (#1)
  
  error[E0277]: the trait bound `byteorder::U16<O>: FromBytes` is not satisfied
     --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/byteorder.rs:293:48
      |
  236 | / macro_rules! define_type {
  237 | |     ($article:ident,
  238 | |         $name:ident,
  239 | |         $native:ident,
  ...   |
  293 | |             impl_or_verify!(O => FromBytes for $name<O>);
      | |                                                ^^^^^^^^ the trait `FromBytes` is not implemented for `byteorder::U16<O>`
  ...   |
  462 | |     };
  463 | | }
      | |_- in this expansion of `define_type!`
  464 |
  465 | / define_type!(
  466 | |     A,
  467 | |     U16,
  468 | |     u16,
  ...   |
  477 | |     [U32, U64, U128]
  478 | | );
      | |_- in this macro invocation
      |
      = help: the following other types implement trait `FromBytes`:
                ()
                ManuallyDrop<T>
                MaybeUninit<T>
                Option<NonZero<i128>>
                Option<NonZero<i16>>
                Option<NonZero<i32>>
                Option<NonZero<i64>>
                Option<NonZero<i8>>
              and 69 others
  note: required by a bound in `byteorder::_::_::Subtrait`
     --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/macros.rs:323:29
      |
  28  | / macro_rules! safety_comment {
  29  | |     (#[doc = r" SAFETY:"] $($(#[$attr:meta])* $macro:ident!$args:tt;)*) => {
  30  | |         #[allow(clippy::undocumented_unsafe_blocks, unused_attributes)]
  31  | |         const _: () = { $($(#[$attr])* $macro!$args;)* };
      | |                                        ------------ in this macro invocation (#3)
  32  | |     }
  33  | | }
      | |_- in this expansion of `safety_comment!` (#2)
  ...
  279 | / macro_rules! impl_or_verify {
  280 | |     // The following two match arms follow the same pattern as their
  281 | |     // counterparts in `unsafe_impl!`; see the documentation on those arms for
  282 | |     // more details.
  ...   |
  302 | /         impl_or_verify!(@verify $trait, {
  303 |               impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {}
  304 | |         });
      | |__________- in this macro invocation (#4)
  ...
  323 | |             trait Subtrait: $trait {}
      | |                             ^^^^^^ required by this bound in `Subtrait`
  ...   |
  326 | |     };
  327 | | }
      | | -
      | |_|
      | |_in this expansion of `impl_or_verify!` (#3)
      |   in this expansion of `impl_or_verify!` (#4)
      |
     ::: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/byteorder.rs:236:1
      |
  236 | / macro_rules! define_type {
  237 | |     ($article:ident,
  238 | |         $name:ident,
  239 | |         $native:ident,
  ...   |
  287 | /         safety_comment! {
  288 |               /// SAFETY:
  289 |               /// `$name<O>` is `repr(transparent)`, and so it has the same layout
  290 |               /// as its only non-zero field, which is a `u8` array. `u8` arrays
  ...
  295 |               impl_or_verify!(O => Unaligned for $name<O>);
  296 | |         }
      | |_________- in this macro invocation (#2)
  ...
  462 | |     };
  463 | | }
      | |_- in this expansion of `define_type!` (#1)
  464 |
  465 | / define_type!(
  466 | |     A,
  467 | |     U16,
  468 | |     u16,
  ...   |
  477 | |     [U32, U64, U128]
  478 | | );
      | |_- in this macro invocation (#1)
  
  error[E0277]: the trait bound `byteorder::U16<O>: AsBytes` is not satisfied
     --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/byteorder.rs:294:46
      |
  236 | / macro_rules! define_type {
  237 | |     ($article:ident,
  238 | |         $name:ident,
  239 | |         $native:ident,
  ...   |
  294 | |             impl_or_verify!(O => AsBytes for $name<O>);
      | |                                              ^^^^^^^^ the trait `AsBytes` is not implemented for `byteorder::U16<O>`
  ...   |
  462 | |     };
  463 | | }
      | |_- in this expansion of `define_type!`
  464 |
  465 | / define_type!(
  466 | |     A,
  467 | |     U16,
  468 | |     u16,
  ...   |
  477 | |     [U32, U64, U128]
  478 | | );
      | |_- in this macro invocation
      |
      = help: the following other types implement trait `AsBytes`:
                ()
                ManuallyDrop<T>
                NonZero<i128>
                NonZero<i16>
                NonZero<i32>
                NonZero<i64>
                NonZero<i8>
                NonZero<isize>
              and 83 others
  note: required by a bound in `byteorder::_::_::Subtrait`
     --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/macros.rs:323:29
      |
  28  | / macro_rules! safety_comment {
  29  | |     (#[doc = r" SAFETY:"] $($(#[$attr:meta])* $macro:ident!$args:tt;)*) => {
  30  | |         #[allow(clippy::undocumented_unsafe_blocks, unused_attributes)]
  31  | |         const _: () = { $($(#[$attr])* $macro!$args;)* };
      | |                                        ------------ in this macro invocation (#3)
  32  | |     }
  33  | | }
      | |_- in this expansion of `safety_comment!` (#2)
  ...
  279 | / macro_rules! impl_or_verify {
  280 | |     // The following two match arms follow the same pattern as their
  281 | |     // counterparts in `unsafe_impl!`; see the documentation on those arms for
  282 | |     // more details.
  ...   |
  302 | /         impl_or_verify!(@verify $trait, {
  303 |               impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> Subtrait for $ty {}
  304 | |         });
      | |__________- in this macro invocation (#4)
  ...
  323 | |             trait Subtrait: $trait {}
      | |                             ^^^^^^ required by this bound in `Subtrait`
  ...   |
  326 | |     };
  327 | | }
      | | -
      | |_|
      | |_in this expansion of `impl_or_verify!` (#3)
      |   in this expansion of `impl_or_verify!` (#4)
      |
     ::: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/byteorder.rs:236:1
      |
  236 | / macro_rules! define_type {
  237 | |     ($article:ident,
  238 | |         $name:ident,
  239 | |         $native:ident,
  ...   |
  287 | /         safety_comment! {
  288 |               /// SAFETY:
  289 |               /// `$name<O>` is `repr(transparent)`, and so it has the same layout
  290 |               /// as its only non-zero field, which is a `u8` array. `u8` arrays
  ...
  295 |               impl_or_verify!(O => Unaligned for $name<O>);
  296 | |         }
      | |_________- in this macro invocation (#2)
  ...
  462 | |     };
  463 | | }
      | |_- in this expansion of `define_type!` (#1)
  464 |
  465 | / define_type!(
  466 | |     A,
  467 | |     U16,
  468 | |     u16,
  ...   |
  477 | |     [U32, U64, U128]
  478 | | );
      | |_- in this macro invocation (#1)
  
  error[E0277]: the trait bound `byteorder::U16<O>: Unaligned` is not satisfied
     --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/byteorder.rs:295:48
      |
  236 | / macro_rules! define_type {
  237 | |     ($article:ident,
  238 | |         $name:ident,
  239 | |         $native:ident,
  ...   |
  295 | |             impl_or_verify!(O => Unaligned for $name<O>);
      | |                                                ^^^^^^^^ the trait `Unaligned` is not implemented for `byteorder::U16<O>`
  ...   |
  462 | |     };
  463 | | }
      | |_- in this expansion of `define_type!`
  464 |
  465 | / define_type!(
  466 | |     A,
  467 | |     U16,
  468 | |     u16,
  ...   |
  477 | |     [U32, U64, U128]
  478 | | );
      | |_- in this macro invocation
      |
      = help: the following other types implement trait `Unaligned`:
                ()
                ManuallyDrop<T>
                MaybeUninit<T>
                NonZero<i8>
                NonZero<u8>
                Option<NonZero<i8>>
                Option<NonZero<u8>>
                PhantomData<T>
              and 7 others
  note: required by a bound in `byteorder::_::_::Subtrait`
     --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/macros.rs:323:29

How to reproduce

How to build the Rust Compiler
./configure \
		--enable-option-checking \
		--enable-verbose-configure \
		--enable-sccache \
		--enable-ninja \
		--enable-verbose-tests \
		--enable-codegen-tests \
		--enable-dist-src \
		--enable-optimize-llvm \
		--enable-full-tools \
		--enable-sanitizers \
		--host=arm64e-apple-darwin \
		--target=arm64e-apple-ios \
		--set llvm.download-ci-llvm=false \
		--set llvm.targets="AArch64;X86" \
		--set llvm.experimental-targets="" \
		--set llvm.static-libstdcpp \
		--set llvm.tests=true \
		--set build.verbose=0 \
		--set rust.channel=dev \
		--set rust.jemalloc \
		--set rust.lto=thin \
		--set rust.codegen-units=1 \
		--set rust.codegen-backends=llvm \
		--set rust.use-lld=false \
		--set rust.omit-git-hash=true \
		--dist-compression-formats=xz \
		--prefix=install \
		 --set change-id=99999999
@arttet arttet added the customer-request Documents customer requests. label Sep 23, 2024
@joshlf
Copy link
Member

joshlf commented Sep 23, 2024

Hi @arttet , can you point us to the source code you're trying to build? A repository and a commit ID would be ideal so we can reproduce this.

@arttet
Copy link
Author

arttet commented Sep 23, 2024

Hey @joshlf,

I have a repo to build 3 tier Rust targets. Here is my experimental commit which can reproduce this issue. Here is my build with this fault.

@joshlf
Copy link
Member

joshlf commented Sep 23, 2024

Okay I think what's happening is actually that this error:

  error[E0786]: found invalid metadata files for crate `zerocopy_derive`
     --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.35/src/lib.rs:285:9
      |
  285 | pub use zerocopy_derive::Unaligned;
      |         ^^^^^^^^^^^^^^^
      |
      = note: no `.rustc` section in '/Users/runner/work/rust-compiler-builder/rust-compiler-builder/rust/build/aarch64-apple-darwin/stage1-rustc/arm64e-apple-darwin/release/deps/libzerocopy_derive-85cad85f9873b5cd.dylib'
  

...means that zerocopy-derive isn't usable from zerocopy. That, in turn, means that this derive isn't working:

zerocopy/src/byteorder.rs

Lines 279 to 281 in 7c8358e

#[cfg_attr(any(feature = "derive", test), derive(KnownLayout, FromZeroes, FromBytes, AsBytes, Unaligned))]
#[repr(transparent)]
pub struct $name<O>([u8; $bytes], PhantomData<O>);

As a consequence, those traits are not implemented for any of the types in the byteorder module, including U16. That's causing this subsequent code to fail:

zerocopy/src/byteorder.rs

Lines 287 to 296 in 7c8358e

safety_comment! {
/// SAFETY:
/// `$name<O>` is `repr(transparent)`, and so it has the same layout
/// as its only non-zero field, which is a `u8` array. `u8` arrays
/// are `FromZeroes`, `FromBytes`, `AsBytes`, and `Unaligned`.
impl_or_verify!(O => FromZeroes for $name<O>);
impl_or_verify!(O => FromBytes for $name<O>);
impl_or_verify!(O => AsBytes for $name<O>);
impl_or_verify!(O => Unaligned for $name<O>);
}

Zerocopy supports using zerocopy-derive optionally. That means that we have to be able to implement our traits for our own internal types without support from zerocopy-derive if it's disabled. We use impl_or_verify! to confirm that the impl emitted by our derive has the same bounds as the one we write by hand.

In other words, when the derive feature is enabled, impl_or_verify!(O => FromZeroes for $name<O>) is supposed to fail compilation if FromZeroes is not implemented for $name<O>.

TL;DR: The issue is actually the "invalid metadata files for zerocopy-derive" errors that you're seeing at the top, and the U16 failures further down are just a symptom of that.

@joshlf
Copy link
Member

joshlf commented Sep 23, 2024

I'm gonna close this since it seems like it's not actually a zerocopy issue, but feel free to reopen or file another issue if you encounter anything else!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-request Documents customer requests.
Projects
None yet
Development

No branches or pull requests

2 participants