rust-lang / cc-rs

Rust library for build scripts to compile C/C++ code into a Rust library
https://docs.rs/cc
Apache License 2.0
1.81k stars 438 forks source link

Unable to build aarch64-apple-ios-macabi and x86_64-apple-ios-macabi targets using clang 13.1 and above #726

Closed kgrech closed 4 months ago

kgrech commented 1 year ago

I am trying to compile the ring crate for the targets mentioned in the target:

cargo +nightly build -Z build-std --release --target aarch64-apple-ios-macabi -vv
cargo +nightly build -Z build-std --release --target x86_64-apple-ios-macabi -vv

Both builds fail with the same error:

clang: error: invalid version number in '--target=arm64-apple-ios13.0-macabi'

I am using M1 mac and my clang version is the following:

clang -v
Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: arm64-apple-darwin21.6.0

I was trying to solve this problem by downgrading the clang. It starts working if I downgrade to 13.0. Version 13.1 and above are failing.

I see the same problem on my x64 mac as well.

kgrech commented 1 year ago

I've found a simple solution, see PR #727, but I have some concerns. I've outlined them in the PR and would be happy to discuss it there

thomcc commented 1 year ago

I think the support for catalyst upstream in rustc_target is kind of broken here, we should figure out a fix there before doing too much here...

... That said, I've merged #727 in the meantime, since it seems like a reasonable approach that we wouldn't be upset about no matter how we resolve that.

imWildCat commented 1 year ago

@thomcc @kgrech I created another PR to fix in the rust compiler: https://github.com/rust-lang/rust/pull/106925

madsmtm commented 4 months ago

All of the mentioned PRs have been merged, so I believe this can be closed.

NobodyXu commented 4 months ago

I tried cargo +nightly build -Z build-std --release --target aarch64-apple-ios-macabi and it still failed:

   Compiling ring v0.17.8 (/private/tmp/ring)
   Compiling addr2line v0.21.0
   Compiling std v0.0.0 (/Users/nobodyxu/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std)
The following warnings were emitted during compilation:

warning: ring@0.17.8: clang: error: argument unused during compilation: '-L/usr/lib' [-Werror,-Wunused-command-line-argument]

error: failed to run custom build command for `ring v0.17.8 (/private/tmp/ring)`

Caused by:
  process didn't exit successfully: `/private/tmp/ring/target/release/build/ring-f5376eacf2ad17e2/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=CARGO_MANIFEST_DIR
  cargo:rerun-if-env-changed=CARGO_PKG_NAME
  cargo:rerun-if-env-changed=CARGO_PKG_VERSION_MAJOR
  cargo:rerun-if-env-changed=CARGO_PKG_VERSION_MINOR
  cargo:rerun-if-env-changed=CARGO_PKG_VERSION_PATCH
  cargo:rerun-if-env-changed=CARGO_PKG_VERSION_PRE
  cargo:rerun-if-env-changed=CARGO_MANIFEST_LINKS
  cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  cargo:rerun-if-env-changed=OUT_DIR
  cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH
  cargo:rerun-if-env-changed=CARGO_CFG_TARGET_OS
  cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ENV
  cargo:rerun-if-env-changed=DEBUG
  cargo:rerun-if-env-changed=PERL_EXECUTABLE
  OPT_LEVEL = Some("3")
  TARGET = Some("aarch64-apple-ios-macabi")
  HOST = Some("aarch64-apple-darwin")
  cargo:rerun-if-env-changed=CC_aarch64-apple-ios-macabi
  CC_aarch64-apple-ios-macabi = None
  cargo:rerun-if-env-changed=CC_aarch64_apple_ios_macabi
  CC_aarch64_apple_ios_macabi = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  Detecting iOS SDK path for macosx
  cargo:rerun-if-env-changed=CFLAGS_aarch64-apple-ios-macabi
  CFLAGS_aarch64-apple-ios-macabi = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_apple_ios_macabi
  CFLAGS_aarch64_apple_ios_macabi = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:warning=clang: error: argument unused during compilation: '-L/usr/lib' [-Werror,-Wunused-command-line-argument]

  --- stderr
  running "perl" "//private/tmp/ring/crypto/fipsmodule/aes/asm/aesv8-armx.pl" "ios64" "//private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out/aesv8-armx-ios64.S"
  running "perl" "//private/tmp/ring/crypto/fipsmodule/modes/asm/ghashv8-armx.pl" "ios64" "//private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out/ghashv8-armx-ios64.S"
  running "perl" "//private/tmp/ring/crypto/chacha/asm/chacha-armv8.pl" "ios64" "//private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out/chacha-armv8-ios64.S"
  running "perl" "//private/tmp/ring/crypto/cipher_extra/asm/chacha20_poly1305_armv8.pl" "ios64" "//private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out/chacha20_poly1305_armv8-ios64.S"
  running "perl" "//private/tmp/ring/crypto/fipsmodule/aes/asm/vpaes-armv8.pl" "ios64" "//private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out/vpaes-armv8-ios64.S"
  running "perl" "//private/tmp/ring/crypto/fipsmodule/bn/asm/armv8-mont.pl" "ios64" "//private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out/armv8-mont-ios64.S"
  running "perl" "//private/tmp/ring/crypto/fipsmodule/ec/asm/p256-armv8-asm.pl" "ios64" "//private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out/p256-armv8-asm-ios64.S"
  running "perl" "//private/tmp/ring/crypto/fipsmodule/modes/asm/ghash-neon-armv8.pl" "ios64" "//private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out/ghash-neon-armv8-ios64.S"
  running "perl" "//private/tmp/ring/crypto/fipsmodule/modes/asm/aesv8-gcm-armv8.pl" "ios64" "//private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out/aesv8-gcm-armv8-ios64.S"
  running "perl" "//private/tmp/ring/crypto/fipsmodule/sha/asm/sha512-armv8.pl" "ios64" "//private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out/sha512-armv8-ios64.S"
  running "perl" "//private/tmp/ring/crypto/fipsmodule/sha/asm/sha512-armv8.pl" "ios64" "//private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out/sha256-armv8-ios64.S"

  error occurred: Command "clang" "-O3" "-fPIC" "--target=arm64-apple-ios-macabi" "-isysroot" "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" "-isystem" "/usr/include" "-iframework" "/System/Library/Frameworks" "-L/usr/lib" "-F/System/Library/Frameworks" "-I" "/private/tmp/ring/include" "-I" "/private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-Wall" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-g3" "-DNDEBUG" "-Werror" "-o" "/private/tmp/ring/target/aarch64-apple-ios-macabi/release/build/ring-62b3b7fcfc0d3429/out/7eef37ad3802d723-curve25519.o" "-c" "/private/tmp/ring/crypto/curve25519/curve25519.c" with args clang did not execute successfully (status code exit status: 1).

warning: build failed, waiting for other jobs to finish...
NobodyXu commented 4 months ago

It seems like a different error this time due to -Werror:

  cargo:warning=clang: error: argument unused during compilation: '-L/usr/lib' [-Werror,-Wunused-command-line-argument]
NobodyXu commented 4 months ago

Turns out that ring enables -Werror if .git is present. After disabling it, I can compile ring on these targets.

Closing this as completed.