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

[wip] Update Mac Catalyst support for Clang 13 #96392

Closed

Conversation

imWildCat
Copy link
Contributor

@imWildCat imWildCat commented Apr 25, 2022

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: conan-io/conan#10880

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 25, 2022
@rust-highfive
Copy link
Collaborator

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
Copy link
Collaborator

⚠️ Warning ⚠️

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 25, 2022

pub fn macabi_llvm_target(arch: &str) -> String {
let (major, minor) = ios_deployment_target();
format!("{}-apple-ios{}.{}.0-macabi", arch, major, minor)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether this is suitable for the catalyst use case...

Please feel free to give hints.

@imWildCat
Copy link
Contributor Author

imWildCat commented Apr 26, 2022

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
Copy link
Contributor Author

imWildCat commented Apr 26, 2022

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:

@davidtwco
Copy link
Member

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

r? rust-lang/compiler

@rust-highfive rust-highfive assigned lcnr and unassigned davidtwco Apr 27, 2022
@lcnr
Copy link
Contributor

lcnr commented Apr 27, 2022

r? rust-lang/compiler

@rust-highfive rust-highfive assigned estebank and unassigned lcnr Apr 27, 2022
@estebank
Copy link
Contributor

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

@imWildCat
Copy link
Contributor Author

imWildCat commented Apr 28, 2022

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>

@@ -114,3 +114,8 @@ pub fn ios_sim_llvm_target(arch: &str) -> String {
let (major, minor) = ios_deployment_target();
format!("{}-apple-ios{}.{}.0-simulator", arch, major, minor)
}

pub fn macabi_llvm_target(arch: &str) -> String {
let (major, minor) = ios_deployment_target();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether it is a good way. But as an iOS developer, I believe it looks good. Because in Xcode, Mac Catalyst minimal version is highly related to minimal iOS version. For example, if I choose iOS 14.0, I can only pick macOS 11+ for this situation:

image

image

(Copied from rust-lang/cc-rs#678)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good solution!

@terhechte
Copy link
Contributor

terhechte commented May 25, 2022

@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

@thomcc thomcc added the O-macos Operating system: macOS label May 25, 2022
@imWildCat
Copy link
Contributor Author

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

@estebank
Copy link
Contributor

r? rust-lang/compiler

@estebank estebank added the I-compiler-nominated Nominated for discussion during a compiler team meeting. label May 26, 2022
@estebank
Copy link
Contributor

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

@compiler-errors
Copy link
Member

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

@thomcc
Copy link
Member

thomcc commented May 26, 2022

@rustbot ping macos

@rustbot
Copy link
Collaborator

rustbot commented May 26, 2022

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.

@thomcc
Copy link
Member

thomcc commented May 26, 2022

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.

compiler-errors added a commit to compiler-errors/rust that referenced this pull request May 27, 2022
…k-Simulacrum

Update `triagebot.toml` for macos ping group

idk what i'm doing but i saw rust-lang#96392 (comment)

cc: `@thomcc`
@bors
Copy link
Contributor

bors commented Jun 14, 2022

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

@wesleywiser
Copy link
Member

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

Thanks! 🙂

@imWildCat
Copy link
Contributor Author

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

@apiraino
Copy link
Contributor

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

@rustbot label -I-compiler-nominated

@rustbot rustbot removed the I-compiler-nominated Nominated for discussion during a compiler team meeting. label Jun 30, 2022
@apiraino
Copy link
Contributor

apiraino commented Jul 6, 2022

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

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 6, 2022
@colincornaby
Copy link

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
Copy link

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
Copy link

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

@imWildCat
Copy link
Contributor Author

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.

@JohnCSimon
Copy link
Member

@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.

@imWildCat imWildCat changed the title Update Mac Catalyst support for Clang 13 [wip] Update Mac Catalyst support for Clang 13 Sep 11, 2022
@imWildCat imWildCat marked this pull request as draft September 11, 2022 14:42
@tmarkovski
Copy link

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

@imWildCat imWildCat closed this Jan 16, 2023
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Feb 2, 2023
…ed-ios-macbi-target-version, r=wesleywiser

Remove hardcoded iOS version of clang target for Mac Catalyst

## Background

From `clang` 13.x, `-target x86_64-apple-ios13.0-macabi` fails while linking:

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

<details>
<summary>Verbose output</summary>

```
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="[removed]" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-Wl,-exported_symbols_list,/var/folders/p8/qpmzbsdn07g5gxykwfxxw7y40000gn/T/rustci8tkvp/list" "-target" "x86_64-apple-ios13.0-macabi" "/var/folders/p8/qpmzbsdn07g5gxykwfxxw7y40000gn/T/rustci8tkvp/symbols.o" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/deps/[user].[user].a2ccc648-cgu.0.rcgu.o" "-L" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/deps" "-L" "/path/to/my/[project]/[user]/target/release/deps" "-L" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/build/blake3-74e6ba91506ce712/out" "-L" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/build/blake3-74e6ba91506ce712/out" "-L" "/Users/[user]/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-apple-ios-macabi/lib" "/var/folders/p8/qpmzbsdn07g5gxykwfxxw7y40000gn/T/rustci8tkvp/libblake3-343c1616c8f62c66.rlib" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/deps/libcompiler_builtins-15d4f20b641cf9ef.rlib" "-framework" "Security" "-framework" "CoreFoundation" "-framework" "Security" "-liconv" "-lSystem" "-lobjc" "-framework" "Security" "-framework" "Foundation" "-lc" "-lm" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk" "-Wl,-syslibroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk" "-L" "/Users/[user]/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-apple-ios-macabi/lib" "-o" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/deps/lib[user].dylib" "-Wl,-dead_strip" "-dynamiclib" "-Wl,-dylib" "-nodefaultlibs"
  = note: clang: error: invalid version number in '-target x86_64-apple-ios13.0-macabi'

warning: `[user]` (lib) generated 6 warnings
error: could not compile `[user]` due to previous error; 6 warnings emitted
```
</details>

### Minimal example

C code:

```c
#include <stdio.h>
void main() {
    int a = 1;
    int b = 2;
    int c = a + b;
    printf("%d", c);
}
```

`clang` command sample:

```
➜  202301 clang -target x86_64-apple-ios13.0-macabi main.c
clang: error: invalid version number in '-target x86_64-apple-ios13.0-macabi'
➜  202301 clang -target x86_64-apple-ios14.0-macabi main.c
main.c:2:1: warning: return type of 'main' is not 'int' [-Wmain-return-type]
void main() {
^
main.c:2:1: note: change return type to 'int'
void main() {
^~~~
int
1 warning generated.
➜  202301 clang -target x86_64-apple-ios15.0-macabi main.c
main.c:2:1: warning: return type of 'main' is not 'int' [-Wmain-return-type]
void main() {
^
main.c:2:1: note: change return type to 'int'
void main() {
^~~~
int
1 warning generated.
➜  202301 clang -target x86_64-apple-ios-macabi main.c
main.c:2:1: warning: return type of 'main' is not 'int' [-Wmain-return-type]
void main() {
^
main.c:2:1: note: change return type to 'int'
void main() {
^~~~
int
1 warning generated.

➜  202301 clang --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```

This PR is a simplified version of rust-lang#96392, inspired by rust-lang/cc-rs#727
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 2, 2023
…-ios-macbi-target-version, r=wesleywiser

Remove hardcoded iOS version of clang target for Mac Catalyst

## Background

From `clang` 13.x, `-target x86_64-apple-ios13.0-macabi` fails while linking:

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

<details>
<summary>Verbose output</summary>

```
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="[removed]" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-Wl,-exported_symbols_list,/var/folders/p8/qpmzbsdn07g5gxykwfxxw7y40000gn/T/rustci8tkvp/list" "-target" "x86_64-apple-ios13.0-macabi" "/var/folders/p8/qpmzbsdn07g5gxykwfxxw7y40000gn/T/rustci8tkvp/symbols.o" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/deps/[user].[user].a2ccc648-cgu.0.rcgu.o" "-L" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/deps" "-L" "/path/to/my/[project]/[user]/target/release/deps" "-L" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/build/blake3-74e6ba91506ce712/out" "-L" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/build/blake3-74e6ba91506ce712/out" "-L" "/Users/[user]/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-apple-ios-macabi/lib" "/var/folders/p8/qpmzbsdn07g5gxykwfxxw7y40000gn/T/rustci8tkvp/libblake3-343c1616c8f62c66.rlib" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/deps/libcompiler_builtins-15d4f20b641cf9ef.rlib" "-framework" "Security" "-framework" "CoreFoundation" "-framework" "Security" "-liconv" "-lSystem" "-lobjc" "-framework" "Security" "-framework" "Foundation" "-lc" "-lm" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk" "-Wl,-syslibroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk" "-L" "/Users/[user]/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-apple-ios-macabi/lib" "-o" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/deps/lib[user].dylib" "-Wl,-dead_strip" "-dynamiclib" "-Wl,-dylib" "-nodefaultlibs"
  = note: clang: error: invalid version number in '-target x86_64-apple-ios13.0-macabi'

warning: `[user]` (lib) generated 6 warnings
error: could not compile `[user]` due to previous error; 6 warnings emitted
```
</details>

### Minimal example

C code:

```c
#include <stdio.h>
void main() {
    int a = 1;
    int b = 2;
    int c = a + b;
    printf("%d", c);
}
```

`clang` command sample:

```
➜  202301 clang -target x86_64-apple-ios13.0-macabi main.c
clang: error: invalid version number in '-target x86_64-apple-ios13.0-macabi'
➜  202301 clang -target x86_64-apple-ios14.0-macabi main.c
main.c:2:1: warning: return type of 'main' is not 'int' [-Wmain-return-type]
void main() {
^
main.c:2:1: note: change return type to 'int'
void main() {
^~~~
int
1 warning generated.
➜  202301 clang -target x86_64-apple-ios15.0-macabi main.c
main.c:2:1: warning: return type of 'main' is not 'int' [-Wmain-return-type]
void main() {
^
main.c:2:1: note: change return type to 'int'
void main() {
^~~~
int
1 warning generated.
➜  202301 clang -target x86_64-apple-ios-macabi main.c
main.c:2:1: warning: return type of 'main' is not 'int' [-Wmain-return-type]
void main() {
^
main.c:2:1: note: change return type to 'int'
void main() {
^~~~
int
1 warning generated.

➜  202301 clang --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```

This PR is a simplified version of rust-lang#96392, inspired by rust-lang/cc-rs#727
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-macos Operating system: macOS S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.