Skip to content

Commit

Permalink
Ensure linkage of the gnustep-base
Browse files Browse the repository at this point in the history
The linker is smart enough to figure out that we are not using
any symbols from the Foundation library, and elides the request to
link it. To circumvent this, we define a (unused) function referencing
the symbol for NSObject
  • Loading branch information
ngrewe authored and madsmtm committed Aug 31, 2021
1 parent 21037f1 commit 4ff9a8b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions objc_foundation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,23 @@ 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"))]
#[link(name = "Foundation", kind = "framework")]
extern "C" {}

#[cfg(not(any(target_os = "macos", target_os = "ios")))]
use objc::runtime::Class;

#[cfg(not(any(target_os = "macos", target_os = "ios")))]
#[link(name = "gnustep-base", kind = "dylib")]
extern { static _OBJC_CLASS_NSObject : Class; }

#[cfg(not(any(target_os = "macos", target_os = "ios")))]
#[allow(dead_code)]
unsafe fn get_class_to_force_linkage() -> &'static Class {
&_OBJC_CLASS_NSObject
}

#[macro_use]
mod macros;

Expand Down

0 comments on commit 4ff9a8b

Please sign in to comment.