Skip to content

Commit 4ff9a8b

Browse files
ngrewemadsmtm
authored andcommitted
Ensure linkage of the gnustep-base
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
1 parent 21037f1 commit 4ff9a8b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

objc_foundation/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,23 @@ pub use self::object::{INSObject, NSObject};
1111
pub use self::string::{INSCopying, INSMutableCopying, INSString, NSString};
1212
pub use self::value::{INSValue, NSValue};
1313

14+
#[cfg(any(target_os = "macos", target_os = "ios"))]
1415
#[link(name = "Foundation", kind = "framework")]
1516
extern "C" {}
1617

18+
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
19+
use objc::runtime::Class;
20+
21+
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
22+
#[link(name = "gnustep-base", kind = "dylib")]
23+
extern { static _OBJC_CLASS_NSObject : Class; }
24+
25+
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
26+
#[allow(dead_code)]
27+
unsafe fn get_class_to_force_linkage() -> &'static Class {
28+
&_OBJC_CLASS_NSObject
29+
}
30+
1731
#[macro_use]
1832
mod macros;
1933

0 commit comments

Comments
 (0)