Skip to content

Commit

Permalink
Fix linking to libobjc2 v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jun 13, 2022
1 parent d1bb3e6 commit aca6ed5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions objc2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,17 @@ pub mod __gnustep_hack {
#[link(name = "gnustep-base", kind = "dylib")]
// This linking doesn't have to be on the correct `extern` block.
extern "C" {
static _OBJC_CLASS_NSObject: Class;
// The linking changed in libobjc2 v2.0
#[cfg_attr(feature = "gnustep-2-0", link_name = "._OBJC_CLASS_NSObject")]
#[cfg_attr(not(feature = "gnustep-2-0"), link_name = "_OBJC_CLASS_NSObject")]
static OBJC_CLASS_NSObject: Class;
// Others:
// __objc_class_name_NSObject
// _OBJC_CLASS_REF_NSObject
}

pub unsafe fn get_class_to_force_linkage() -> &'static Class {
unsafe { core::ptr::read_volatile(&&_OBJC_CLASS_NSObject) }
unsafe { core::ptr::read_volatile(&&OBJC_CLASS_NSObject) }
}

#[test]
Expand Down

0 comments on commit aca6ed5

Please sign in to comment.