Skip to content

Commit

Permalink
Update minimum required Apple versions
Browse files Browse the repository at this point in the history
The versions supported by Rust was updated in rust-lang/rust#104385 to:
- macOS: 10.12 Sierra
- iOS: 10.0
- tvOS: 10.0
- watchOS: 5.0

Additionally, the armv7-apple-ios target was removed.

Finally, since v1.0.84 of `cc` (has been yanked, but 1.0.85 will include it as well), there is much better support for specifying the deployment target for Apple targets, so I've removed the corresponding code from objc-sys.
  • Loading branch information
madsmtm committed Nov 23, 2023
1 parent b9fc9f3 commit 90ecad0
Show file tree
Hide file tree
Showing 29 changed files with 55 additions and 3,488 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ env:
# Faster compilation, error on warnings and only document current crate
RUSTFLAGS: "--codegen=debuginfo=0 --deny=warnings"
RUSTDOCFLAGS: "--deny=warnings"
# Minimum deployment target
MACOSX_DEPLOYMENT_TARGET: 10.7
IPHONEOS_DEPLOYMENT_TARGET: 7.0
# Minimum deployment targets.
# Follows `rustc --target=x86_64-apple-darwin --print deployment-target`
MACOSX_DEPLOYMENT_TARGET: 10.12
# Follows `rustc --target=x86_64-apple-ios --print deployment-target`
IPHONEOS_DEPLOYMENT_TARGET: 10.0
# We only support compiling Objective-C code with clang
CC: clang
CXX: clang++
Expand Down Expand Up @@ -102,7 +104,7 @@ jobs:
--features=$INTERESTING_FEATURES
--features=unstable-frameworks-macos-12
- name: iOS 32bit
target: armv7-apple-ios
target: armv7s-apple-ios
build-std: true
args: >-
-Zbuild-std
Expand Down Expand Up @@ -362,7 +364,7 @@ jobs:
frameworks: macos-11
- name: Test macOS old SDK
# Oldest macOS version we support
sdk: "10.7"
sdk: "10.12"
frameworks: macos-10-7
- name: Test macOS nightly
nightly: true
Expand All @@ -380,11 +382,6 @@ jobs:
- name: Build iOS ARM64
target: aarch64-apple-ios
frameworks: ios
- name: Build iOS ARMv7
target: armv7-apple-ios
nightly: true
build-std: true
frameworks: ios
- name: Build iOS ARMv7s
target: armv7s-apple-ios
nightly: true
Expand Down
1 change: 0 additions & 1 deletion crates/block-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ targets = [
# iOS
"aarch64-apple-ios",
"x86_64-apple-ios",
# "armv7-apple-ios",
# "i386-apple-ios",
# GNUStep
"x86_64-unknown-linux-gnu",
Expand Down
1 change: 0 additions & 1 deletion crates/block2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ targets = [
# iOS
"aarch64-apple-ios",
"x86_64-apple-ios",
# "armv7-apple-ios",
# "i386-apple-ios",
# GNUStep
"x86_64-unknown-linux-gnu",
Expand Down
1 change: 0 additions & 1 deletion crates/header-translator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ fn main() -> Result<(), BoxError> {
],
Platform::IPhoneOs => &[
// "arm64-apple-ios7.0.0",
// "armv7-apple-ios7.0.0",
// "armv7s-apple-ios",
// "arm64-apple-ios14.0-macabi",
// "x86_64-apple-ios13.0-macabi",
Expand Down
1 change: 0 additions & 1 deletion crates/icrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ targets = [
# iOS
"aarch64-apple-ios",
"x86_64-apple-ios",
# "armv7-apple-ios",
# "i386-apple-ios",
# GNUStep
"x86_64-unknown-linux-gnu",
Expand Down
8 changes: 4 additions & 4 deletions crates/icrate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ These bindings are automatically generated from the SDKs in Xcode 14.3.1 (will
be periodically updated).

Currently supports:
- macOS: `10.7-13.1`
- iOS/iPadOS: `7.0-16.2` (WIP)
- tvOS: `9.0-16.1` (WIP)
- watchOS: `1.0-9.1` (WIP)
- macOS: `10.12-13.1`
- iOS/iPadOS: `10.0-16.2` (WIP)
- tvOS: `10.0-16.1` (WIP)
- watchOS: `5.0-9.1` (WIP)
3 changes: 1 addition & 2 deletions crates/objc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ unstable-exception = ["cc"]
unstable-docsrs = []

[build-dependencies]
cc = { version = "1", optional = true }
cc = { version = "1.0.80", optional = true }

[package.metadata.docs.rs]
default-target = "x86_64-apple-darwin"
Expand All @@ -76,7 +76,6 @@ targets = [
# iOS
"aarch64-apple-ios",
"x86_64-apple-ios",
# "armv7-apple-ios",
# "i386-apple-ios",
# GNUStep
"x86_64-unknown-linux-gnu",
Expand Down
24 changes: 8 additions & 16 deletions crates/objc-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,14 @@ This is used by default, and has the highest support priority (all of
The supported runtime version (higher versions lets the compiler enable newer
optimizations, at the cost of not supporting older operating systems) can be
chosen using the standard `X_DEPLOYMENT_TARGET` environment variables:
- macOS: `MACOSX_DEPLOYMENT_TARGET`
- Default: `10.7`, `11.0` on Aarch64
- Minimum: `10.7`
- iOS / iPadOS: `IPHONEOS_DEPLOYMENT_TARGET`
- Default: `7.0`
- Minimum: `5.0` (theoretically)
- tvOS: `TVOS_DEPLOYMENT_TARGET`
- Default: `7.0`
- Minimum: `5.0` (theoretically)
- watchOS: `WATCHOS_DEPLOYMENT_TARGET`
- Default: `5.0`
- Minimum: `1.0` (theoretically)

The default versions are the [same as those Rust itself has][rust-apple-spec].

[rust-apple-spec]: https://github.com/rust-lang/rust/blob/fd815a5091eb4d49cd317f8ad272f17b7a5f550d/compiler/rustc_target/src/spec/apple_base.rs
- macOS: `MACOSX_DEPLOYMENT_TARGET`, default `10.12`, `11.0` on Aarch64.
- iOS / iPadOS: `IPHONEOS_DEPLOYMENT_TARGET`, default `10.0`.
- tvOS: `TVOS_DEPLOYMENT_TARGET`, default `10.0`.
- watchOS: `WATCHOS_DEPLOYMENT_TARGET`, default `5.0`.

The default (and minimum) versions are the [same as those Rust itself has][rust-apple-spec].

[rust-apple-spec]: https://github.com/rust-lang/rust/blob/1.74.0/compiler/rustc_target/src/spec/apple_base.rs


### GNUStep's [`libobjc2`](https://github.com/gnustep/libobjc2)
Expand Down
128 changes: 26 additions & 102 deletions crates/objc-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,13 @@
use std::{env, path::Path};

/// TODO: Better validation of this
///
/// The version is used for providing different behaviour when:
/// - CGException.cpp getObjCPersonality (GNUStep >= 1.7)
/// - Clang.cpp Clang::AddObjCRuntimeArgs (GNUStep >= 2.0)
/// - isLegacyDispatchDefaultForArch (macOS < 10.6, GNUStep < 1.6)
/// - hasNativeARC (macOS < 10.7, iOS < 5)
/// - shouldUseARCFunctionsForRetainRelease (macOS < 10.10, iOS < 8)
/// - shouldUseRuntimeFunctionsForAlloc (macOS < 10.10, iOS < 8)
/// - shouldUseRuntimeFunctionForCombinedAllocInit (macOS >= 10.14.4, iOS >= 12.2, watchOS >= 5.2)
/// - hasOptimizedSetter (macOS >= 10.8, iOS >= 6, GNUStep >= 1.7)
/// - hasSubscripting (macOS < 10.11, iOS < 9)
/// - hasTerminate (macOS < 10.8, iOS < 5)
/// - hasARCUnsafeClaimAutoreleasedReturnValue (macOS >= 10.11, iOS >= 9, watchOS >= 2)
/// - hasEmptyCollections (macOS >= 10.11, iOS >= 9, watchOS >= 2)
/// - ... (incomplete)
///
/// `macosx-fragile` and `gcc` was not considered in this analysis, made on
/// clang version 13's source code:
/// https://github.com/llvm/llvm-project/blob/llvmorg-13.0.0/clang/include/clang/Basic/ObjCRuntime.h
///
/// In short, it's not ultra important, but enables some optimizations if this
/// is specified.
type Version = String;

// For clang "-fobjc-runtime" support
#[allow(clippy::upper_case_acronyms)]
enum AppleRuntime {
MacOS(Version),
IOS(Version),
TvOS(Version),
WatchOS(Version),
Unknown,
// BridgeOS,
}
use AppleRuntime::*;

/// The selected runtime (and runtime version).
enum Runtime {
Apple(AppleRuntime),
Apple,
GNUStep(u8, u8),
WinObjC,
#[allow(dead_code)]
ObjFW(Option<String>),
}
use Runtime::*;

fn get_env(env: &str) -> Option<String> {
println!("cargo:rerun-if-env-changed={env}");
match env::var(env) {
Ok(var) => Some(var),
Err(env::VarError::NotPresent) => None,
Err(env::VarError::NotUnicode(var)) => panic!("Invalid unicode for {env}: {var:?}"),
}
}

fn main() {
// The script doesn't depend on our code
Expand Down Expand Up @@ -102,39 +56,28 @@ fn main() {

let runtime = match (apple, gnustep, objfw) {
// Same logic as in https://github.com/rust-lang/rust/blob/1.63.0/compiler/rustc_target/src/spec/apple_base.rs
(true, false, false) => Apple(match &*target_os {
"macos" if target_arch == "aarch64" => {
MacOS(get_env("MACOSX_DEPLOYMENT_TARGET").unwrap_or_else(|| "11.0".into()))
}
"macos" => MacOS(get_env("MACOSX_DEPLOYMENT_TARGET").unwrap_or_else(|| "10.7".into())),
"ios" => IOS(get_env("IPHONEOS_DEPLOYMENT_TARGET").unwrap_or_else(|| "7.0".into())),
"tvos" => TvOS(get_env("TVOS_DEPLOYMENT_TARGET").unwrap_or_else(|| "7.0".into())),
"watchos" => {
WatchOS(get_env("WATCHOS_DEPLOYMENT_TARGET").unwrap_or_else(|| "5.0".into()))
}
_ => Unknown,
}),
(true, false, false) => Runtime::Apple,
(false, true, false) => {
// Choose defaults when generating docs
if cfg!(feature = "unstable-docsrs") {
if "windows" == target_os {
WinObjC
Runtime::WinObjC
} else {
GNUStep(1, 7)
Runtime::GNUStep(1, 7)
}
} else if env::var_os("CARGO_FEATURE_UNSTABLE_WINOBJC").is_some() {
WinObjC
Runtime::WinObjC
} else if env::var_os("CARGO_FEATURE_GNUSTEP_2_1").is_some() {
GNUStep(2, 1)
Runtime::GNUStep(2, 1)
} else if env::var_os("CARGO_FEATURE_GNUSTEP_2_0").is_some() {
GNUStep(2, 0)
Runtime::GNUStep(2, 0)
} else if env::var_os("CARGO_FEATURE_GNUSTEP_1_9").is_some() {
GNUStep(1, 9)
Runtime::GNUStep(1, 9)
} else if env::var_os("CARGO_FEATURE_GNUSTEP_1_8").is_some() {
GNUStep(1, 8)
Runtime::GNUStep(1, 8)
} else {
// CARGO_FEATURE_GNUSTEP_1_7
GNUStep(1, 7)
Runtime::GNUStep(1, 7)
}
}
(false, false, true) => {
Expand All @@ -148,50 +91,37 @@ fn main() {

// Add `#[cfg(RUNTIME)]` directive
let runtime_cfg = match runtime {
Apple(_) => "apple",
Runtime::Apple => "apple",
// WinObjC can be treated like GNUStep 1.8
GNUStep(_, _) | WinObjC => "gnustep",
ObjFW(_) => "objfw",
Runtime::GNUStep(_, _) | Runtime::WinObjC => "gnustep",
Runtime::ObjFW(_) => "objfw",
};
println!("cargo:rustc-cfg={runtime_cfg}");

if let Apple(runtime) = &runtime {
if let Runtime::Apple = &runtime {
// A few things are defined differently depending on the __OBJC2__
// variable, which is set for all platforms except 32-bit macOS.
if let (MacOS(_), "x86") = (runtime, &*target_arch) {
if target_os == "macos" && target_arch == "x86" {
println!("cargo:rustc-cfg=apple_old");
} else {
println!("cargo:rustc-cfg=apple_new");
}
}

let clang_runtime = match &runtime {
Apple(runtime) => {
match (runtime, &*target_arch) {
// The fragile runtime is expected on i686-apple-darwin, see:
// https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/Driver/ToolChains/Darwin.h#L228-L231
// https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/Driver/ToolChains/Clang.cpp#L3639-L3640
// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtVersionsPlatforms.html
(MacOS(version), "x86") => format!("macosx-fragile-{version}"),
(MacOS(version), _) => format!("macosx-{version}"),
(IOS(version), _) => format!("ios-{version}"),
(WatchOS(version), _) => format!("watchos-{version}"),
// tvOS doesn't have its own -fobjc-runtime string
(TvOS(version), _) => format!("ios-{version}"),
// Choose a sensible default for other platforms that
// specified `apple`; this is likely not going to work anyhow
(Unknown, _) => "macosx".into(),
}
}
let clang_objc_runtime = match &runtime {
// Default to `clang`'s own heuristics.
//
// Note that the `cc` crate forwards the correct deployment target to clang as well.
Runtime::Apple => "".into(),
// Default in clang is 1.6
// GNUStep's own default is 1.8
GNUStep(major, minor) => format!("gnustep-{major}.{minor}"),
Runtime::GNUStep(major, minor) => format!(" -fobjc-runtime=gnustep-{major}.{minor}"),
// WinObjC's libobjc2 is a fork of gnustep's from version 1.8
WinObjC => "gnustep-1.8".into(),
ObjFW(version) => {
Runtime::WinObjC => " -fobjc-runtime=gnustep-1.8".into(),
Runtime::ObjFW(version) => {
// Default in clang
let version = version.as_deref().unwrap_or("0.8");
format!("objfw-{version}")
format!(" -fobjc-runtime=objfw-{version}")
}
};

Expand All @@ -204,14 +134,8 @@ fn main() {
// Assume the compiler is clang; if it isn't, this is probably going to
// fail anyways, since we're using newer runtimes than GCC supports.
//
// TODO: Should add we these, or is it someone else's responsibility?
// - `-mios-simulator-version-min={}`
// - `-miphoneos-version-min={}`
// - `-mmacosx-version-min={}`
// - ...
//
// TODO: -fobjc-weak ?
let mut cc_args = format!("-fobjc-exceptions -fobjc-runtime={clang_runtime}");
let mut cc_args = format!("-fobjc-exceptions{clang_objc_runtime}");

if let Runtime::ObjFW(_) = &runtime {
// Add compability headers to make `#include <objc/objc.h>` work.
Expand Down
1 change: 0 additions & 1 deletion crates/objc2-encode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ targets = [
# iOS
"aarch64-apple-ios",
"x86_64-apple-ios",
# "armv7-apple-ios",
# "i386-apple-ios",
# GNUStep
"x86_64-unknown-linux-gnu",
Expand Down
1 change: 0 additions & 1 deletion crates/objc2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ targets = [
# iOS
"aarch64-apple-ios",
"x86_64-apple-ios",
# "armv7-apple-ios",
# "i386-apple-ios",
# GNUStep
"x86_64-unknown-linux-gnu",
Expand Down

This file was deleted.

Loading

0 comments on commit 90ecad0

Please sign in to comment.