rust-cross / cargo-zigbuild

Compile Cargo project with zig as linker
MIT License
1.55k stars 57 forks source link

Cross compiling to OSX from Linux can error if a crate sets a -march flag #130

Closed j-baker closed 1 year ago

j-baker commented 1 year ago

When I try to compile the sha2 crate with feature asm, this errors, with an error log looking like:

  cargo:warning=info: available CPUs for architecture 'aarch64':
  cargo:warning= a64fx
  cargo:warning= ampere1
  cargo:warning= apple_a10
  cargo:warning= apple_a11
  cargo:warning= apple_a12
  cargo:warning= apple_a13
  cargo:warning= apple_a14
  cargo:warning= apple_a7
  cargo:warning= apple_a8
  cargo:warning= apple_a9
  cargo:warning= apple_latest
  cargo:warning= apple_m1
  cargo:warning= apple_s4
  cargo:warning= apple_s5
  cargo:warning= carmel
  cargo:warning= cortex_a34
... lots more...
  cargo:warning= thunderxt88
  cargo:warning= tsv110
  cargo:warning= xgene1
  cargo:warning=
  cargo:warning=error: unknown CPU: 'armv8'

This happens due to https://github.com/RustCrypto/asm-hashes/blob/1ea2ff7172a3a7e3cbab6e0014cebcb1a85366a4/sha2/build.rs#L13, which I think is filed as https://github.com/ziglang/zig/issues/4911.

This error appears to come from Zig, in here: https://github.com/ziglang/zig/blob/8e9c9f6fdc76bcb6ea0eb4b73a6683041c7a08ad/lib/std/Build.zig#L999

While cargo-zigbuild has a workaround, here: https://github.com/rust-cross/cargo-zigbuild/pull/58/files, it doesn't seem to be triggering.

I'm wondering, should this line: https://github.com/rust-cross/cargo-zigbuild/pull/58/files#diff-49b1f98d9d763bc0e0db9c28ba3dc79ca7413959f017924bc333f7a086d16189R77 be .starts_with("arm") or "aarch64"?