Skip to content

Commit

Permalink
Fix linking in objc_id
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Aug 31, 2021
1 parent f7e436a commit e66f48b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions objc_id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ mod tests {
use objc::runtime::Object;
use objc::{class, msg_send};

#[cfg(not(target_vendor = "apple"))]
#[test]
fn ensure_linkage() {
unsafe { crate::get_class_to_force_linkage() };
}

fn retain_count(obj: &Object) -> usize {
unsafe { msg_send![obj, retainCount] }
}
Expand Down
21 changes: 20 additions & 1 deletion objc_id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ which can be cloned to allow multiple references.
Weak references may be created using the [`WeakId`](struct.WeakId.html) struct.
```
```no_run
# use objc::msg_send;
use objc::runtime::{Class, Object};
use objc_id::{Id, WeakId};
Expand Down Expand Up @@ -41,3 +41,22 @@ assert!(weak.load().is_none());
pub use id::{Id, Owned, Ownership, ShareId, Shared, WeakId};

mod id;

// TODO: Remove the need for this hack

#[cfg(all(test, not(target_vendor = "apple")))]
use objc::runtime::Class;

#[cfg(all(test, not(target_vendor = "apple")))]
#[link(name = "gnustep-base", kind = "dylib")]
extern "C" {}

#[cfg(all(test, not(target_vendor = "apple")))]
extern "C" {
static _OBJC_CLASS_NSObject: Class;
}

#[cfg(all(test, not(target_vendor = "apple")))]
unsafe fn get_class_to_force_linkage() -> &'static Class {
&_OBJC_CLASS_NSObject
}

0 comments on commit e66f48b

Please sign in to comment.