Skip to content

Commit

Permalink
Merge pull request #31 from madsmtm/gnustep-fixes
Browse files Browse the repository at this point in the history
`GNUStep` encoding fixes
  • Loading branch information
madsmtm authored Sep 5, 2021
2 parents 9480a6f + 6a3a119 commit d48dc10
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 deletions objc/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion objc/src/rc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion objc/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion objc/tests/use_macros.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
4 changes: 2 additions & 2 deletions objc_block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
10 changes: 5 additions & 5 deletions objc_foundation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion objc_foundation/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -85,7 +88,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() };
Expand Down
2 changes: 1 addition & 1 deletion objc_id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
Expand Down
8 changes: 4 additions & 4 deletions objc_id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d48dc10

Please sign in to comment.