cc-rs icon indicating copy to clipboard operation
cc-rs copied to clipboard

Mac Catalyst: Read `IPHONEOS_DEPLOYMENT_TARGET` from environment variable to support Clang 13

Open imWildCat opened this issue 3 years ago • 1 comments

Background

Clang 13 removed the x86_64-apple-ios13.0-macabi target, where 13.0 is hardcoded in cc-rs.

Proof:

➜  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

This PR is to remove this hardcoded version and read it from IPHONEOS_DEPLOYMENT_TARGET.

Credits

@ehuss helped me found this reason: https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Update.20Mac.20Catalyst.20support.20for.20Clang.2013/near/280745037

How to test

In this commit https://github.com/imWildCat/BLAKE3/commit/f7bfd7786dedbad7be3e263ee3282f2b36cacd1a, I changed cc-rs to my branch.

The build command and its output is like

➜  BLAKE3 git:(clang-13-mac-catalyst-demo) ✗ IPHONEOS_DEPLOYMENT_TARGET=13.1 cargo +nightly build -Z build-std --target x86_64-apple-ios-macabi
   Compiling compiler_builtins v0.1.71
   Compiling core v0.0.0 (/Users/wildcat/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.121
   Compiling cc v1.0.69
   Compiling memchr v2.4.1
   Compiling std v0.0.0 (/Users/wildcat/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std)
   Compiling version_check v0.9.4
   Compiling typenum v1.15.0
   Compiling cc v1.0.73 (https://github.com/imWildCat/cc-rs?branch=clang-13-mac-catalyst#310a43a5)
   Compiling generic-array v0.14.5
   Compiling blake3 v1.3.1 (/Volumes/SharedVol/rust-projects/BLAKE3)
   Compiling unwind v0.0.0 (/Users/wildcat/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/unwind)
   Compiling rustc-std-workspace-core v1.99.0 (/Users/wildcat/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/Users/wildcat/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v0.1.10
   Compiling adler v0.2.3
   Compiling rustc-demangle v0.1.21
   Compiling rustc-std-workspace-alloc v1.99.0 (/Users/wildcat/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-alloc)
   Compiling panic_unwind v0.0.0 (/Users/wildcat/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/panic_unwind)
   Compiling panic_abort v0.0.0 (/Users/wildcat/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/panic_abort)
   Compiling gimli v0.25.0
   Compiling std_detect v0.1.5 (/Users/wildcat/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/stdarch/crates/std_detect)
   Compiling object v0.26.2
   Compiling hashbrown v0.12.0
   Compiling miniz_oxide v0.4.0
   Compiling addr2line v0.16.0
   Compiling proc_macro v0.0.0 (/Users/wildcat/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/proc_macro)
   Compiling subtle v2.4.1
   Compiling arrayref v0.3.6
   Compiling arrayvec v0.7.2
   Compiling constant_time_eq v0.1.5
   Compiling cfg-if v1.0.0
   Compiling block-buffer v0.10.2
   Compiling crypto-common v0.1.3
   Compiling digest v0.10.3
    Finished dev [unoptimized + debuginfo] target(s) in 12.88s

imWildCat avatar May 01 '22 02:05 imWildCat

This is one of the things I'm suggesting to address differently in #664.

dot-asm avatar May 01 '22 14:05 dot-asm

So we no longer hardcode this as of https://github.com/rust-lang/cc-rs/pull/727. But I also think rustc itself is probably broken WRT how it handles catalyst, and would like to figure out the right fix there before doing too much in cc.

thomcc avatar Oct 26 '22 04:10 thomcc

@thomcc sure, thanks for the update!

imWildCat avatar Oct 26 '22 05:10 imWildCat