From 6f0ea4e5b2fcb1a16d2f2b6883cebcf9b208a9b0 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 2 Sep 2021 00:59:09 +0200 Subject: [PATCH 1/3] Change cfg(target_os = ios|macos) to cfg(target_vendor = apple) Would allow support for tvOS and watchOS support in the future, and the cfg is shorter --- objc/src/message/mod.rs | 4 ++-- objc/src/rc/mod.rs | 2 +- objc/tests/use_macros.rs | 2 +- objc_block/src/lib.rs | 4 ++-- objc_foundation/src/lib.rs | 10 +++++----- objc_foundation/src/string.rs | 2 +- objc_id/src/id.rs | 2 +- objc_id/src/lib.rs | 8 ++++---- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/objc/src/message/mod.rs b/objc/src/message/mod.rs index 1f1fdad29..8a54f7b86 100644 --- a/objc/src/message/mod.rs +++ b/objc/src/message/mod.rs @@ -29,10 +29,10 @@ macro_rules! objc_try { mod verify; -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(target_vendor = "apple")] #[path = "apple/mod.rs"] mod platform; -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(target_vendor = "apple"))] #[path = "gnustep.rs"] mod platform; diff --git a/objc/src/rc/mod.rs b/objc/src/rc/mod.rs index 4ea147cd4..c479fc1fd 100644 --- a/objc/src/rc/mod.rs +++ b/objc/src/rc/mod.rs @@ -47,7 +47,7 @@ pub use self::strong::StrongPtr; pub use self::weak::WeakPtr; // These tests use NSObject, which isn't present for GNUstep -#[cfg(all(test, any(target_os = "macos", target_os = "ios")))] +#[cfg(all(test, target_vendor = "apple"))] mod tests { use super::autoreleasepool; use super::StrongPtr; diff --git a/objc/tests/use_macros.rs b/objc/tests/use_macros.rs index 8039c0ca6..958e678e2 100644 --- a/objc/tests/use_macros.rs +++ b/objc/tests/use_macros.rs @@ -1,4 +1,4 @@ -#![cfg(any(target_os = "macos", target_os = "ios"))] +#![cfg(target_vendor = "apple")] use objc::runtime::Object; use objc::{class, msg_send, sel}; diff --git a/objc_block/src/lib.rs b/objc_block/src/lib.rs index 3a81222f2..5a32810e6 100644 --- a/objc_block/src/lib.rs +++ b/objc_block/src/lib.rs @@ -70,11 +70,11 @@ struct ClassInternal { } #[cfg_attr( - any(target_os = "macos", target_os = "ios"), + target_vendor = "apple", link(name = "System", kind = "dylib") )] #[cfg_attr( - not(any(target_os = "macos", target_os = "ios")), + not(target_vendor = "apple"), link(name = "BlocksRuntime", kind = "dylib") )] extern "C" { diff --git a/objc_foundation/src/lib.rs b/objc_foundation/src/lib.rs index d25292177..eb45c951f 100644 --- a/objc_foundation/src/lib.rs +++ b/objc_foundation/src/lib.rs @@ -21,25 +21,25 @@ pub use self::object::{INSObject, NSObject}; pub use self::string::{INSCopying, INSMutableCopying, INSString, NSString}; pub use self::value::{INSValue, NSValue}; -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(target_vendor = "apple")] #[link(name = "Foundation", kind = "framework")] extern "C" {} -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(target_vendor = "apple"))] use objc::runtime::Class; -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(target_vendor = "apple"))] #[link(name = "gnustep-base", kind = "dylib")] extern "C" {} // Split up to illustrate that the linking doesn't have to be annotated on the // correct `extern` block. -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(target_vendor = "apple"))] extern "C" { static _OBJC_CLASS_NSObject: Class; } -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(target_vendor = "apple"))] #[allow(dead_code)] unsafe fn get_class_to_force_linkage() -> &'static Class { &_OBJC_CLASS_NSObject diff --git a/objc_foundation/src/string.rs b/objc_foundation/src/string.rs index 83244d86c..7edcdd17e 100644 --- a/objc_foundation/src/string.rs +++ b/objc_foundation/src/string.rs @@ -85,7 +85,7 @@ impl fmt::Display for NSString { mod tests { use super::{INSCopying, INSString, NSString}; - #[cfg(not(any(target_os = "macos", target_os = "ios")))] + #[cfg(not(target_vendor = "apple"))] #[test] fn ensure_linkage() { unsafe { crate::get_class_to_force_linkage() }; diff --git a/objc_id/src/id.rs b/objc_id/src/id.rs index b88ce0a72..3e36a5ae1 100644 --- a/objc_id/src/id.rs +++ b/objc_id/src/id.rs @@ -238,7 +238,7 @@ mod tests { use objc::runtime::Object; use objc::{class, msg_send}; - #[cfg(not(any(target_os = "macos", target_os = "ios")))] + #[cfg(not(target_vendor = "apple"))] #[test] fn ensure_linkage() { unsafe { crate::get_class_to_force_linkage() }; diff --git a/objc_id/src/lib.rs b/objc_id/src/lib.rs index a905d0900..eab716b0f 100644 --- a/objc_id/src/lib.rs +++ b/objc_id/src/lib.rs @@ -47,19 +47,19 @@ mod id; // TODO: Remove the need for this hack -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(target_vendor = "apple"))] use objc::runtime::Class; -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(target_vendor = "apple"))] #[link(name = "gnustep-base", kind = "dylib")] extern "C" {} -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(target_vendor = "apple"))] extern "C" { static _OBJC_CLASS_NSObject: Class; } -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(target_vendor = "apple"))] #[allow(dead_code)] unsafe fn get_class_to_force_linkage() -> &'static Class { &_OBJC_CLASS_NSObject From ea468b62741b3dc8b42e9951d95c4edc636f1dc7 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 2 Sep 2021 01:37:11 +0200 Subject: [PATCH 2/3] Fix UTF8_ENCODING on GNUStep --- objc_foundation/src/string.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/objc_foundation/src/string.rs b/objc_foundation/src/string.rs index 7edcdd17e..d093142d3 100644 --- a/objc_foundation/src/string.rs +++ b/objc_foundation/src/string.rs @@ -31,7 +31,10 @@ pub trait INSMutableCopying: INSObject { } } +#[cfg(target_vendor = "apple")] const UTF8_ENCODING: usize = 4; +#[cfg(not(target_vendor = "apple"))] +const UTF8_ENCODING: i32 = 4; pub trait INSString: INSObject { fn len(&self) -> usize { From 6a3a119daf7a8b08fb32992263cffa8661c4cc62 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 2 Sep 2021 17:03:20 +0200 Subject: [PATCH 3/3] Fix BOOL on GNUStep BOOL should probably be a newtype wrapper to alleviate these inconsistencies --- objc/src/runtime.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/objc/src/runtime.rs b/objc/src/runtime.rs index 608301392..c402bbd71 100644 --- a/objc/src/runtime.rs +++ b/objc/src/runtime.rs @@ -16,8 +16,11 @@ use crate::Encode; /// The Objective-C `BOOL` type. /// /// To convert an Objective-C `BOOL` into a Rust [`bool`], compare it with [`NO`]. -#[cfg(not(target_arch = "aarch64"))] +#[cfg(all(target_vendor = "apple", not(target_arch = "aarch64")))] pub type BOOL = ::std::os::raw::c_schar; +#[cfg(all(not(target_vendor = "apple"), not(target_arch = "aarch64")))] +pub type BOOL = u8; + /// The equivalent of true for Objective-C's [`BOOL`] type. #[cfg(not(target_arch = "aarch64"))] pub const YES: BOOL = 1;