Skip to content

Commit ecea206

Browse files
authored
Merge pull request #43 from madsmtm/fix-ci
Fix GNUStep `Foundation` linking when running tests
2 parents 55cc239 + 4c685e1 commit ecea206

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

objc2/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,27 @@ pub mod runtime;
100100

101101
#[cfg(test)]
102102
mod test_utils;
103+
104+
/// Hacky way to make GNUStep link properly to Foundation while testing.
105+
///
106+
/// This is a temporary solution to make our CI work for now!
107+
#[doc(hidden)]
108+
#[cfg(not(target_vendor = "apple"))]
109+
pub mod __gnustep_hack {
110+
use super::runtime::Class;
111+
112+
#[link(name = "gnustep-base", kind = "dylib")]
113+
// This linking doesn't have to be on the correct `extern` block.
114+
extern "C" {
115+
static _OBJC_CLASS_NSObject: Class;
116+
}
117+
118+
pub unsafe fn get_class_to_force_linkage() -> &'static Class {
119+
&_OBJC_CLASS_NSObject
120+
}
121+
122+
#[test]
123+
fn ensure_linkage() {
124+
unsafe { get_class_to_force_linkage() };
125+
}
126+
}

objc2/src/rc/autorelease.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl !AutoreleaseSafe for AutoreleasePool {}
216216
///
217217
/// Basic usage:
218218
///
219-
/// ```rust
219+
/// ```rust,no_run
220220
/// use objc2::{class, msg_send};
221221
/// use objc2::rc::{autoreleasepool, AutoreleasePool};
222222
/// use objc2::runtime::Object;

objc2_foundation/src/lib.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,10 @@ pub use self::value::{INSValue, NSValue};
2525
#[link(name = "Foundation", kind = "framework")]
2626
extern "C" {}
2727

28-
#[cfg(not(target_vendor = "apple"))]
29-
use objc2::runtime::Class;
30-
3128
#[cfg(not(target_vendor = "apple"))]
3229
#[link(name = "gnustep-base", kind = "dylib")]
3330
extern "C" {}
3431

35-
// Split up to illustrate that the linking doesn't have to be annotated on the
36-
// correct `extern` block.
37-
#[cfg(not(target_vendor = "apple"))]
38-
extern "C" {
39-
static _OBJC_CLASS_NSObject: Class;
40-
}
41-
42-
#[cfg(not(target_vendor = "apple"))]
43-
#[allow(dead_code)]
44-
unsafe fn get_class_to_force_linkage() -> &'static Class {
45-
&_OBJC_CLASS_NSObject
46-
}
47-
4832
#[macro_use]
4933
mod macros;
5034

objc2_foundation/src/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ mod tests {
9595
#[cfg(not(target_vendor = "apple"))]
9696
#[test]
9797
fn ensure_linkage() {
98-
unsafe { crate::get_class_to_force_linkage() };
98+
unsafe { objc2::__gnustep_hack::get_class_to_force_linkage() };
9999
}
100100

101101
#[test]

0 commit comments

Comments
 (0)