rust icon indicating copy to clipboard operation
rust copied to clipboard

Update Mac Catalyst support for Clang 13

Open imWildCat opened this issue 3 years ago • 24 comments

LLVM 13 (bundled in Xcode 13.3+) bumped the minimal x86_64 Catalyst version.

➜  temp clang -target x86_64-apple-ios13.1-macabi i.c
➜  temp clang -target x86_64-apple-ios13.0-macabi i.c
clang-13: error: invalid version number in '-target x86_64-apple-ios13.0-macabi'
➜  temp clang --version
Homebrew clang version 13.0.1
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /opt/homebrew/bin
➜  temp cat i.c

int main() {
	return 0;
}
➜  temp

In this case, we'd better provide a way to change the minimal version number.

This would also work:

$ clang -target x86_64-apple-ios-macabi -miphoneos-version-min=13.1 i.c

Similar PR: https://github.com/conan-io/conan/pull/10880

imWildCat avatar Apr 25 '22 13:04 imWildCat

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @davidtwco (or someone else) soon.

Please see the contribution instructions for more information.

rust-highfive avatar Apr 25 '22 13:04 rust-highfive

:warning: Warning :warning:

rust-highfive avatar Apr 25 '22 13:04 rust-highfive

~~QQ: How to build the nightly channel locally? (resolved)~~

https://users.rust-lang.org/t/how-to-build-the-nightly-channel-locally-x-py-b-always-pick-the-beta-channel/74756

My change needs to be tested using the nightly channel because it is related to Mac Catalyst.

imWildCat avatar Apr 26 '22 07:04 imWildCat

New question: Should I use stage 2 or stage 3 to test my change locally?

I cannot build stage 3 locally.

When I use stage 2 to test my change:

# project: https://github.com/BLAKE3-team/BLAKE3.git
$ cargo +stage2 build -Z build-std --release --target x86_64-apple-ios-macabi

   Compiling rustc-std-workspace-core v1.99.0 (/Volumes/SharedVol/rust-projects/rust/build/aarch64-apple-darwin/stage2/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling blake3 v1.3.1 (/Volumes/SharedVol/rust-projects/BLAKE3)
The following warnings were emitted during compilation:

warning: The C compiler "clang" does not support -mavx512f and -mavx512vl.
warning: clang-13: error: invalid version number in '--target=x86_64-apple-ios13.0-macabi'

error: failed to run custom build command for `blake3 v1.3.1 (/Volumes/SharedVol/rust-projects/BLAKE3)`

Caused by:
  process didn't exit successfully: `/Volumes/SharedVol/rust-projects/BLAKE3/target/release/build/blake3-ac5c6dee5cd36567/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=CARGO_FEATURE_PURE
  cargo:rerun-if-env-changed=CARGO_FEATURE_NO_NEON
  TARGET = Some("x86_64-apple-ios-macabi")
  HOST = Some("aarch64-apple-darwin")
  CC_x86_64-apple-ios-macabi = None
  CC_x86_64_apple_ios_macabi = None
  TARGET_CC = None
  CC = None
  CFLAGS_x86_64-apple-ios-macabi = None
  CFLAGS_x86_64_apple_ios_macabi = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  Detecting iOS SDK path for macosx
  running: "xcrun" "--show-sdk-path" "--sdk" "macosx"
  exit status: 0
  OPT_LEVEL = Some("3")
  CC_x86_64-apple-ios-macabi = None
  CC_x86_64_apple_ios_macabi = None
  TARGET_CC = None
  CC = None
  CFLAGS_x86_64-apple-ios-macabi = None
  CFLAGS_x86_64_apple_ios_macabi = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  Detecting iOS SDK path for macosx
  running: "xcrun" "--show-sdk-path" "--sdk" "macosx"
  exit status: 0
  cargo:warning=The C compiler "clang" does not support -mavx512f and -mavx512vl.
  cargo:rerun-if-env-changed=BLAKE3_CI
  cargo:rerun-if-env-changed=CARGO_FEATURE_PREFER_INTRINSICS
  cargo:rerun-if-env-changed=CARGO_FEATURE_PURE
  cargo:rustc-cfg=blake3_sse2_ffi
  cargo:rustc-cfg=blake3_sse41_ffi
  cargo:rustc-cfg=blake3_avx2_ffi
  TARGET = Some("x86_64-apple-ios-macabi")
  OPT_LEVEL = Some("3")
  HOST = Some("aarch64-apple-darwin")
  CC_x86_64-apple-ios-macabi = None
  CC_x86_64_apple_ios_macabi = None
  TARGET_CC = None
  CC = None
  CFLAGS_x86_64-apple-ios-macabi = None
  CFLAGS_x86_64_apple_ios_macabi = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  Detecting iOS SDK path for macosx
  running: "xcrun" "--show-sdk-path" "--sdk" "macosx"
  exit status: 0
  running: "clang" "-O3" "-fPIC" "--target=x86_64-apple-ios13.0-macabi" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk" "-fembed-bitcode" "-Wall" "-Wextra" "-std=c11" "-o" "/Volumes/SharedVol/rust-projects/BLAKE3/target/x86_64-apple-ios-macabi/release/build/blake3-4be9cc78c36efcbd/out/c/blake3_sse2_x86-64_unix.o" "-c" "c/blake3_sse2_x86-64_unix.S"
  cargo:warning=clang-13: error: invalid version number in '--target=x86_64-apple-ios13.0-macabi'
  exit status: 1

  --- stderr


  error occurred: Command "clang" "-O3" "-fPIC" "--target=x86_64-apple-ios13.0-macabi" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk" "-fembed-bitcode" "-Wall" "-Wextra" "-std=c11" "-o" "/Volumes/SharedVol/rust-projects/BLAKE3/target/x86_64-apple-ios-macabi/release/build/blake3-4be9cc78c36efcbd/out/c/blake3_sse2_x86-64_unix.o" "-c" "c/blake3_sse2_x86-64_unix.S" with args "clang" did not execute successfully (status code exit status: 1).

It does not change anything:

imWildCat avatar Apr 26 '22 12:04 imWildCat

I have no experience with Apple platforms so I'll reassign this.

r? rust-lang/compiler

davidtwco avatar Apr 27 '22 05:04 davidtwco

r? rust-lang/compiler

lcnr avatar Apr 27 '22 05:04 lcnr

@rust-lang/compiler who's the resident mac expert?

estebank avatar Apr 27 '22 06:04 estebank

Hi @terhechte! Could you please share more insights about how to test this compiler change manually?

I followed the README of https://github.com/terhechte/rust-catalyst-example with this project (https://github.com/BLAKE3-team/BLAKE3.git) but it didn't work:

(Toggle to see the output) ``` ➜ BLAKE3 git:(master) ✗ cargo +stage2 build -Z build-std --target x86_64-apple-ios-macabi Compiling rustc-std-workspace-core v1.99.0 (/Volumes/SharedVol/rust-projects/rust/build/aarch64-apple-darwin/stage2/lib/rustlib/src/rust/library/rustc-std-workspace-core) Compiling blake3 v1.3.1 (/Volumes/SharedVol/rust-projects/BLAKE3) Compiling compiler_builtins v0.1.71 Compiling libc v0.2.121 The following warnings were emitted during compilation:

warning: The C compiler "clang" does not support -mavx512f and -mavx512vl. warning: clang-13: error: invalid version number in '--target=x86_64-apple-ios13.0-macabi'

error: failed to run custom build command for blake3 v1.3.1 (/Volumes/SharedVol/rust-projects/BLAKE3)

Caused by: process didn't exit successfully: /Volumes/SharedVol/rust-projects/BLAKE3/target/debug/build/blake3-b58207ab56af61ae/build-script-build (exit status: 1) --- stdout cargo:rustc-env=TARGET=x86_64-apple-ios14.0-macabi cargo:rustc-env=IPHONEOS_DEPLOYMENT_TARGET=14.0 cargo:rerun-if-env-changed=CARGO_FEATURE_PURE cargo:rerun-if-env-changed=CARGO_FEATURE_NO_NEON TARGET = Some("x86_64-apple-ios-macabi") HOST = Some("aarch64-apple-darwin") CC_x86_64-apple-ios-macabi = None CC_x86_64_apple_ios_macabi = None TARGET_CC = None CC = None CFLAGS_x86_64-apple-ios-macabi = None CFLAGS_x86_64_apple_ios_macabi = None TARGET_CFLAGS = None CFLAGS = None CRATE_CC_NO_DEFAULTS = None Detecting iOS SDK path for macosx running: "xcrun" "--show-sdk-path" "--sdk" "macosx" exit status: 0 OPT_LEVEL = Some("0") CC_x86_64-apple-ios-macabi = None CC_x86_64_apple_ios_macabi = None TARGET_CC = None CC = None CFLAGS_x86_64-apple-ios-macabi = None CFLAGS_x86_64_apple_ios_macabi = None TARGET_CFLAGS = None CFLAGS = None CRATE_CC_NO_DEFAULTS = None DEBUG = Some("true") Detecting iOS SDK path for macosx running: "xcrun" "--show-sdk-path" "--sdk" "macosx" exit status: 0 cargo:warning=The C compiler "clang" does not support -mavx512f and -mavx512vl. cargo:rerun-if-env-changed=BLAKE3_CI cargo:rerun-if-env-changed=CARGO_FEATURE_PREFER_INTRINSICS cargo:rerun-if-env-changed=CARGO_FEATURE_PURE cargo:rustc-cfg=blake3_sse2_ffi cargo:rustc-cfg=blake3_sse41_ffi cargo:rustc-cfg=blake3_avx2_ffi TARGET = Some("x86_64-apple-ios-macabi") OPT_LEVEL = Some("0") HOST = Some("aarch64-apple-darwin") CC_x86_64-apple-ios-macabi = None CC_x86_64_apple_ios_macabi = None TARGET_CC = None CC = None CFLAGS_x86_64-apple-ios-macabi = None CFLAGS_x86_64_apple_ios_macabi = None TARGET_CFLAGS = None CFLAGS = None CRATE_CC_NO_DEFAULTS = None DEBUG = Some("true") Detecting iOS SDK path for macosx running: "xcrun" "--show-sdk-path" "--sdk" "macosx" exit status: 0 running: "clang" "-O0" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=x86_64-apple-ios13.0-macabi" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk" "-fembed-bitcode" "-Wall" "-Wextra" "-std=c11" "-o" "/Volumes/SharedVol/rust-projects/BLAKE3/target/x86_64-apple-ios-macabi/debug/build/blake3-5c91a7166ed285cc/out/c/blake3_sse2_x86-64_unix.o" "-c" "c/blake3_sse2_x86-64_unix.S" cargo:warning=clang-13: error: invalid version number in '--target=x86_64-apple-ios13.0-macabi' exit status: 1

--- stderr

error occurred: Command "clang" "-O0" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=x86_64-apple-ios13.0-macabi" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk" "-fembed-bitcode" "-Wall" "-Wextra" "-std=c11" "-o" "/Volumes/SharedVol/rust-projects/BLAKE3/target/x86_64-apple-ios-macabi/debug/build/blake3-5c91a7166ed285cc/out/c/blake3_sse2_x86-64_unix.o" "-c" "c/blake3_sse2_x86-64_unix.S" with args "clang" did not execute successfully (status code exit status: 1).

warning: build failed, waiting for other jobs to finish...

</details>

imWildCat avatar Apr 28 '22 11:04 imWildCat

@imWildCat Sorry for the delay! It has been some time since I last looked into this topic. I just checked my notes and can only offer some guesses:

  • Did you try with variations of the target (such as x86_64-apple-ios-macabi) instead of x86_64-apple-ios13.0-macabi)?
  • I don't know much about BLAKE3 but something I ran into from time to time when building Rust for other targets (such as iOS) is that crates that just provide a wrapper for C sometimes include additional LLVM based steps and those would regularly fail because it would assume the wrong host. There's a nightly setting for this now: https://doc.rust-lang.org/cargo/reference/unstable.html#target-applies-to-host
  • The error you're seeing is related to AVX/SSE on Intel CPUs. Maybe Catalyst (being just iOS shoehorned into macOS) doesn't support that? You could try disabling SSE. Based on some Googling it seems you can do that via -Ctarget-feature=+soft-float (https://www.reddit.com/r/rust/comments/e0735l/disable_sse_on_libstd/) - but I'm way out of my weeds here.
  • Can you try with something other than Blake3 (something that doesn't have a C dependency) and see if that works?
  • Also, thanks for working on this! <3

terhechte avatar May 25 '22 06:05 terhechte

Thanks @terhechte!

I tried Rust libs without C and found that: without the change of this PR, everything is fine with Xcode 13.3 or 13.4. This makes me doubt the necessity of this PR.

Did you try with variations of the target (such as x86_64-apple-ios-macabi) instead of x86_64-apple-ios13.0-macabi)?

Good point! For clang, I think we can drop ios13.0 in the middle.

➜  temp cat i.c
int main() {
  return 0;
}
➜  temp clang -target x86_64-apple-ios-macabi i.c
➜  temp echo $?
0

imWildCat avatar May 26 '22 10:05 imWildCat

r? rust-lang/compiler

estebank avatar May 26 '22 18:05 estebank

I'm raising this to discuss this PR next thursday meeting so we can assign someone with expertise with this platform

estebank avatar May 26 '22 18:05 estebank

good idea, because highfive bot chose me, but I am also not an expert :^)

compiler-errors avatar May 26 '22 18:05 compiler-errors

@rustbot ping macos

thomcc avatar May 26 '22 18:05 thomcc

Error: This team (macos) cannot be pinged via this command; it may need to be added to triagebot.toml on the master branch.

Please let @rust-lang/release know if you're having trouble with this bot.

rustbot avatar May 26 '22 18:05 rustbot

That should be fixed (since macos is basically for this purpose) but I don't have time to do it.

Also, even though I'm in the ping group, I've never used catalyst. So I'll just CC @hkratz, @inflation, @shepmaster, @nvzqz manually. Thanks.

thomcc avatar May 26 '22 18:05 thomcc

:umbrella: The latest upstream changes (presumably #98075) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Jun 14 '22 02:06 bors

@hkratz or @shepmaster, would either of you have time look at this and give us a 👍/👎 if this looks ok to you?

Thanks! 🙂

wesleywiser avatar Jun 23 '22 14:06 wesleywiser

@wesleywiser Actually, I'm not confident about this change as pure Rust libs can compile targeting Catalyst using Clang 13+ without this PR.

imWildCat avatar Jun 23 '22 22:06 imWildCat

I'll remove the I-compiler-nominated as I think it was handled

@rustbot label -I-compiler-nominated

apiraino avatar Jun 30 '22 08:06 apiraino

I am unsure about that status of this PR. IIUC by reading the last comment, I infer its status to be "iffy" i.e. not really necessary, am I reading it correctly? I'll reassign to the author for evaluation (or perhaps closing?). Thanks for an update on this.

@rustbot author

apiraino avatar Jul 06 '22 13:07 apiraino

I'm having trouble building for Mac Catalyst - and my research has taken me back to this issue. It looks like the minimum version did get moved to 13.1. @imWildCat - Not sure why you're able to build with your configuration, but on Xcode 13.4 I am seeing: clang: error: invalid version number in '--target=arm64-apple-ios13.0-macabi'

When attempting to build the std lib.

colincornaby avatar Aug 05 '22 16:08 colincornaby

Another odd thing is that error is from the aarch64 version of Catalyst, but from what I can see in the source, that aarch64 version specifically should be set to 14.0, not 13.0. So something is weird here: https://github.com/rust-lang/rust/blob/46a9b9f81a1c0050562bf15c37bb5b944a194c07/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs

colincornaby avatar Aug 05 '22 16:08 colincornaby

It looks like my issue is cured by https://github.com/rust-lang/cc-rs/pull/678. The CC tooling is overriding even any change here.

colincornaby avatar Aug 05 '22 19:08 colincornaby

It looks like my issue is cured by rust-lang/cc-rs#678. The CC tooling is overriding even any change here.

Yeah. If it is a pure Rust project, we're good without needing to change the --target.

imWildCat avatar Aug 06 '22 11:08 imWildCat

@imWildCat

ping from triage - can you post your status on this PR? Thanks

FYI: when a PR is ready for review, send a message containing @rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

JohnCSimon avatar Sep 11 '22 05:09 JohnCSimon

Any update on this issue or a workaround how to get past this problem? We're stuck making builds for *-macabi targets.

tmarkovski avatar Dec 02 '22 15:12 tmarkovski