Skip to content

Commit 079308c

Browse files
committed
Fix various definitions on Mac Catalyst and the Simulator
Fixed APIs: - SSLCipherSuite. - CMBaseClassVersion and CMStructVersion. - MTLCopyAllDevices. - CSSM_TP_APPLE_EVIDENCE_INFO. - UIImageResizingMode, NSImageResizingMode and NSTextAlignment consts. - AudioSampleType and AudioUnitSampleType. - kAudioFormatFlagsCanonical and kAudioFormatFlagsAudioUnitCanonical. Found by searching for TARGET_OS_MACCATALYST and TARGET_OS_SIMULATOR. This uses `target_env` instead of `target_abi`, since that's in our MSRV, although in a bit of a weird way: If we used `target_abi`, we'd be able to have an MSRV of 1.78, while if we use `target_env`, we can have a lower MSRV for most targets, but for Mac Catalyst / Simulator targets, the MSRV is raised to 1.91. This isn't ideal, but it's the best we can do without a build script.
1 parent 902fc7d commit 079308c

File tree

20 files changed

+231
-96
lines changed

20 files changed

+231
-96
lines changed

crates/objc2/src/topics/FRAMEWORKS_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
9292
* Marked some CoreMedia types as `Send + Sync`.
9393
* Fixed the value of `kUSBHostPortPropertyPortNumber`.
9494
* Fixed the value of `SFSpeechErrorCode::Timeout`.
95+
* Fixed the definition of `SSLCipherSuite` on older platforms.
96+
* Fixed the definition of various things on Mac Catalyst.
9597

9698
## [0.3.1] - 2025-04-19
9799
[0.3.1]: https://github.com/madsmtm/objc2/compare/frameworks-0.3.0...frameworks-0.3.1

framework-crates/objc2-app-kit/src/image.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
use objc2::encode::{Encode, Encoding, RefEncode};
2-
use objc2::ffi::NSInteger;
3-
4-
use super::TARGET_ABI_USES_IOS_VALUES;
5-
6-
// NS_ENUM
7-
#[repr(transparent)]
8-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
9-
pub struct NSImageResizingMode(pub NSInteger);
10-
11-
unsafe impl Encode for NSImageResizingMode {
12-
const ENCODING: Encoding = NSInteger::ENCODING;
13-
}
14-
15-
unsafe impl RefEncode for NSImageResizingMode {
16-
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
17-
}
1+
use crate::{NSImageResizingMode, TARGET_ABI_USES_IOS_VALUES};
182

193
#[allow(non_upper_case_globals)]
204
#[allow(clippy::bool_to_int_with_if)]

framework-crates/objc2-app-kit/src/lib.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ extern crate std;
3636
#[cfg_attr(feature = "gnustep-1-7", link(name = "gnustep-gui", kind = "dylib"))]
3737
extern "C" {}
3838

39-
/// (!TARGET_CPU_X86_64 || (TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST))
40-
///
41-
/// <https://github.com/xamarin/xamarin-macios/issues/12111>
42-
// TODO: Make this work with mac catalyst
43-
#[allow(dead_code)]
44-
pub(crate) const TARGET_ABI_USES_IOS_VALUES: bool =
45-
!cfg!(any(target_arch = "x86", target_arch = "x86_64")) || cfg!(not(target_os = "macos"));
46-
4739
#[cfg(feature = "NSApplication")]
4840
mod application;
4941
#[cfg(feature = "NSEvent")]
@@ -58,10 +50,15 @@ mod text;
5850
#[cfg(feature = "NSResponder")]
5951
pub use self::application::*;
6052
pub use self::generated::*;
61-
#[cfg(feature = "NSImage")]
62-
pub use self::image::*;
63-
#[cfg(feature = "NSText")]
64-
pub use self::text::*;
53+
54+
/// (!TARGET_CPU_X86_64 || (TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST))
55+
///
56+
/// <https://github.com/xamarin/xamarin-macios/issues/12111>
57+
#[allow(unused)]
58+
#[allow(unexpected_cfgs)]
59+
pub(crate) const TARGET_ABI_USES_IOS_VALUES: bool = !cfg!(target_arch = "x86_64")
60+
|| (cfg!(all(target_vendor = "apple", not(target_os = "macos")))
61+
&& !cfg!(target_env = "macabi"));
6562

6663
// MacTypes.h
6764
#[allow(unused)]
Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,10 @@
1-
use objc2::encode::{Encode, Encoding, RefEncode};
2-
use objc2::ffi::NSInteger;
3-
4-
use super::TARGET_ABI_USES_IOS_VALUES;
5-
6-
// NS_ENUM
7-
#[repr(transparent)]
8-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
9-
pub struct NSTextAlignment(pub NSInteger);
10-
11-
unsafe impl Encode for NSTextAlignment {
12-
const ENCODING: Encoding = NSInteger::ENCODING;
13-
}
14-
15-
unsafe impl RefEncode for NSTextAlignment {
16-
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
17-
}
1+
use crate::{NSTextAlignment, TARGET_ABI_USES_IOS_VALUES};
182

193
#[allow(non_upper_case_globals)]
204
#[allow(clippy::bool_to_int_with_if)]
215
impl NSTextAlignment {
22-
#[doc(alias = "NSTextAlignmentLeft")]
23-
pub const Left: Self = Self(0);
246
#[doc(alias = "NSTextAlignmentRight")]
257
pub const Right: Self = Self(if TARGET_ABI_USES_IOS_VALUES { 2 } else { 1 });
268
#[doc(alias = "NSTextAlignmentCenter")]
279
pub const Center: Self = Self(if TARGET_ABI_USES_IOS_VALUES { 1 } else { 2 });
28-
#[doc(alias = "NSTextAlignmentJustified")]
29-
pub const Justified: Self = Self(3);
30-
#[doc(alias = "NSTextAlignmentNatural")]
31-
pub const Natural: Self = Self(4);
3210
}

framework-crates/objc2-app-kit/translation-config.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ class.NSLayoutXAxisAnchor.derives = "Debug"
6565
class.NSLayoutYAxisAnchor.derives = "Debug"
6666
class.NSLayoutDimension.derives = "Debug"
6767

68-
# Different definitions depending on target
69-
enum.NSImageResizingMode.skipped = true
70-
enum.NSTextAlignment.skipped = true
68+
# Different definitions depending on target.
69+
const.NSImageResizingModeTile.skipped = true
70+
const.NSImageResizingModeStretch.skipped = true
71+
const.NSTextAlignmentCenter.skipped = true
72+
const.NSTextAlignmentRight.skipped = true
7173

7274
# Uses constants from IOKit
7375
enum.NSPointingDeviceType.use-value = true
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#![allow(non_upper_case_globals)]
2+
#![allow(unexpected_cfgs)]
3+
use crate::*;
4+
5+
// CA_PREFER_FIXED_POINT = TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST
6+
#[cfg(all(
7+
all(target_vendor = "apple", not(target_os = "macos")),
8+
not(target_env = "macabi"),
9+
))]
10+
type Inner = f32;
11+
#[cfg(not(all(
12+
all(target_vendor = "apple", not(target_os = "macos")),
13+
not(target_env = "macabi"),
14+
)))]
15+
type Inner = i32;
16+
17+
#[allow(unused)]
18+
const kAudioUnitSampleFractionBits: AudioFormatFlags = 24;
19+
20+
/// [Apple's documentation](https://developer.apple.com/documentation/coreaudiotypes/audiosampletype?language=objc)
21+
#[deprecated]
22+
pub type AudioSampleType = Inner;
23+
24+
/// [Apple's documentation](https://developer.apple.com/documentation/coreaudiotypes/audiounitsampletype?language=objc)
25+
#[deprecated]
26+
pub type AudioUnitSampleType = Inner;
27+
28+
/// [Apple's documentation](https://developer.apple.com/documentation/coreaudiotypes/kaudioformatflagscanonical?language=objc)
29+
#[cfg(all(
30+
all(target_vendor = "apple", not(target_os = "macos")),
31+
not(target_env = "macabi"),
32+
))]
33+
#[deprecated]
34+
pub const kAudioFormatFlagsCanonical: AudioFormatFlags =
35+
kAudioFormatFlagIsFloat | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
36+
37+
/// [Apple's documentation](https://developer.apple.com/documentation/coreaudiotypes/kaudioformatflagsaudiounitcanonical?language=objc)
38+
#[cfg(all(
39+
all(target_vendor = "apple", not(target_os = "macos")),
40+
not(target_env = "macabi"),
41+
))]
42+
#[deprecated]
43+
pub const kAudioFormatFlagsAudioUnitCanonical: AudioFormatFlags = kAudioFormatFlagIsFloat
44+
| kAudioFormatFlagsNativeEndian
45+
| kAudioFormatFlagIsPacked
46+
| kAudioFormatFlagIsNonInterleaved;
47+
48+
/// [Apple's documentation](https://developer.apple.com/documentation/coreaudiotypes/kaudioformatflagscanonical?language=objc)
49+
#[cfg(not(all(
50+
all(target_vendor = "apple", not(target_os = "macos")),
51+
not(target_env = "macabi"),
52+
)))]
53+
#[deprecated]
54+
pub const kAudioFormatFlagsCanonical: AudioFormatFlags =
55+
kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
56+
57+
/// [Apple's documentation](https://developer.apple.com/documentation/coreaudiotypes/kaudioformatflagsaudiounitcanonical?language=objc)
58+
#[cfg(not(all(
59+
all(target_vendor = "apple", not(target_os = "macos")),
60+
not(target_env = "macabi"),
61+
)))]
62+
#[deprecated]
63+
pub const kAudioFormatFlagsAudioUnitCanonical: AudioFormatFlags = kAudioFormatFlagIsSignedInteger
64+
| kAudioFormatFlagsNativeEndian
65+
| kAudioFormatFlagIsPacked
66+
| kAudioFormatFlagIsNonInterleaved
67+
| (kAudioUnitSampleFractionBits << kLinearPCMFormatFlagsSampleFractionShift);

framework-crates/objc2-core-audio-types/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ extern crate alloc;
1515
#[cfg(feature = "std")]
1616
extern crate std;
1717

18+
#[cfg(feature = "CoreAudioBaseTypes")]
19+
mod base_types;
1820
#[allow(clippy::eq_op)]
1921
mod generated;
2022
#[cfg(feature = "AudioSessionTypes")]
2123
mod session;
2224

25+
#[cfg(feature = "CoreAudioBaseTypes")]
26+
pub use self::base_types::*;
2327
#[allow(unused_imports, unreachable_pub)]
2428
pub use self::generated::*;
2529
#[cfg(feature = "AudioSessionTypes")]

framework-crates/objc2-core-audio-types/translation-config.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ tvos = "13.0"
1010
watchos = "6.0"
1111
visionos = "1.0"
1212

13-
# Differs based on architecture
13+
# Differs based on architecture.
1414
typedef.AVAudioInteger.skipped = true
1515
typedef.AVAudioUInteger.skipped = true
16+
17+
# Differs based on platform.
18+
typedef.AudioSampleType.skipped = true
19+
typedef.AudioUnitSampleType.skipped = true
20+
const.kAudioUnitSampleFractionBits.skipped = true
21+
const.kAudioFormatFlagsCanonical.skipped = true
22+
const.kAudioFormatFlagsAudioUnitCanonical.skipped = true

framework-crates/objc2-core-media/src/base.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
// See CMBase.h
2+
#![allow(unexpected_cfgs)]
23

3-
// TODO: Or target_abi = "macabi"
4-
#[cfg(all(target_os = "macos", target_arch = "x86_64"))]
4+
// (TARGET_OS_OSX || TARGET_OS_MACCATALYST || TARGET_OS_WINDOWS) && TARGET_CPU_X86_64
5+
#[cfg(all(
6+
any(target_os = "macos", target_env = "macabi", target_os = "windows"),
7+
target_arch = "x86_64"
8+
))]
59
type Inner = u32; // uint32_t
6-
#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))]
10+
#[cfg(not(all(
11+
any(target_os = "macos", target_env = "macabi", target_os = "windows"),
12+
target_arch = "x86_64"
13+
)))]
714
type Inner = usize; // uintptr_t
815

916
/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/cmbaseclassversion?language=objc)

framework-crates/objc2-io-kit/translation-config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ const.kIOUSBInterfaceInterfaceID.skipped = true
6464
# Redefine for kUSBHostMessageRenegotiateCurrent
6565
const.kIOUSBMessageRenegotiateCurrent.skipped = true
6666

67+
# TODO: Check cfgs with `TARGET_OS_MACCATALYST`.
68+
6769
# Requires C++
6870
module.video.skipped = true
6971

0 commit comments

Comments
 (0)