briansmith / ring

Safe, fast, small crypto using Rust
Other
3.68k stars 693 forks source link

TargetConditionals.h not found building on MacOS #1942

Closed tmpfs closed 3 months ago

tmpfs commented 6 months ago

Hi,

I recently upgraded to XCode 15 and suddenly ring stops compiling for MacOS targets (both aarch64 and x86_64) here is the output:

The following warnings were emitted during compilation:

warning: ring@0.17.7: In file included from crypto/curve25519/curve25519.c:22:
warning: ring@0.17.7: In file included from include/ring-core/mem.h:60:
warning: ring@0.17.7: include/ring-core/base.h:71:10: fatal error: 'TargetConditionals.h' file not found
warning: ring@0.17.7: #include <TargetConditionals.h>
warning: ring@0.17.7:          ^~~~~~~~~~~~~~~~~~~~~~
warning: ring@0.17.7: 1 error generated.

error: failed to run custom build command for `ring v0.17.7`

Caused by:
  process didn't exit successfully: `/Users/muji/git/sos/gui/target/debug/build/ring-fb6cf29cc4ff5269/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_7_
  OPT_LEVEL = Some("0")
  TARGET = Some("aarch64-apple-darwin")
  HOST = Some("aarch64-apple-darwin")
  cargo:rerun-if-env-changed=CC_aarch64-apple-darwin
  CC_aarch64-apple-darwin = None
  cargo:rerun-if-env-changed=CC_aarch64_apple_darwin
  CC_aarch64_apple_darwin = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = Some("/opt/homebrew/opt/llvm/bin/clang")
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  cargo:rerun-if-env-changed=CFLAGS_aarch64-apple-darwin
  CFLAGS_aarch64-apple-darwin = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_apple_darwin
  CFLAGS_aarch64_apple_darwin = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  running: env -u IPHONEOS_DEPLOYMENT_TARGET "/opt/homebrew/opt/llvm/bin/clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "--target=arm64-apple-darwin" "-I" "include" "-I" "/Users/muji/git/sos/gui/target/aarch64-apple-darwin/debug/build/ring-6a83fcdec0c56460/out" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-gfull" "-DNDEBUG" "-o" "/Users/muji/git/sos/gui/target/aarch64-apple-darwin/debug/build/ring-6a83fcdec0c56460/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c"
  cargo:warning=In file included from crypto/curve25519/curve25519.c:22:

  cargo:warning=In file included from include/ring-core/mem.h:60:

  cargo:warning=include/ring-core/base.h:71:10: fatal error: 'TargetConditionals.h' file not found

  cargo:warning=#include <TargetConditionals.h>

  cargo:warning=         ^~~~~~~~~~~~~~~~~~~~~~

  cargo:warning=1 error generated.

  exit status: 1

  --- stderr

  error occurred: Command env -u IPHONEOS_DEPLOYMENT_TARGET "/opt/homebrew/opt/llvm/bin/clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "--target=arm64-apple-darwin" "-I" "include" "-I" "/Users/muji/git/sos/gui/target/aarch64-apple-darwin/debug/build/ring-6a83fcdec0c56460/out" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-gfull" "-DNDEBUG" "-o" "/Users/muji/git/sos/gui/target/aarch64-apple-darwin/debug/build/ring-6a83fcdec0c56460/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c" with args "clang" did not execute successfully (status code exit status: 1).

I was compiling against ring@0.17.5 and have tried updating to ring@0.17.7 and the problem still happens.

I have checked against 6762d656742d7ea431948356760da28e09292b72 and I get the same error with either of:

cargo check --all --target aarch64-apple-darwin
cargo check --all --target x86_64-apple-darwin

Any idea how I can resolve this please?

tmpfs commented 6 months ago

I think it's a problem with the Xcode installation, checking now.

tmpfs commented 6 months ago

I had forgotten to also update the command line tools but that didn't fix it.

The file exists here: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/TargetConditionals.h

So I will try to add that include path and see what happens.

tmpfs commented 6 months ago

This hack fixes the problem right now:

export C_INCLUDE_PATH="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/:$C_INCLUDE_PATH"

But I am curious what the proper fix would be.

briansmith commented 6 months ago

Based on reading https://github.com/rust-lang/cc-rs/issues/902 it looks like the issue could be related to IPHONEOS_DEPLOYMENT_TARGET/MACOS_DEPLOYMENT_TARGET/etc and/or the version of cc-rs in use.

briansmith commented 3 months ago

@tmpfs It seems like cc-rs has had a lot of issues recently regarding Apple targets, and I think this is likely due to them. I think the later cc-rs versions have rectified things. Are things working for you now? If not, please reopen this.

tmpfs commented 3 months ago

Can confirm compilation working for me again on e943bfccd6f8fd77a2ba132ec2997346ed883552, thank you @briansmith :pray: