Skip to content

Commit 9f4b86b

Browse files
committed
Add test for weak-linked Objective-C resilient class stubs
1 parent 1b4f171 commit 9f4b86b

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Foundation
2+
3+
open class BaseClass : NSObject {
4+
@objc dynamic open func instanceMethod() -> Int {
5+
return 42
6+
}
7+
8+
@objc dynamic open class func classMethod() -> Int {
9+
return 31337
10+
}
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module first {
2+
header "first.h"
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import first
2+
3+
#if BEFORE
4+
@_weakLinked public class DerivedClass : BaseClass {}
5+
#endif
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Check that Objective-C is able to use a resilient class stub emitted
2+
// by the Swift compiler.
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: %target-build-swift -emit-library -emit-module -o %t/libfirst.dylib -emit-objc-header-path %t/first.h %S/Inputs/class-stubs-weak/first.swift -Xlinker -install_name -Xlinker @executable_path/libfirst.dylib -enable-library-evolution
6+
// RUN: %target-build-swift -emit-library -o %t/libsecond.dylib -emit-objc-header-path %t/second.h -I %t %S/Inputs/class-stubs-weak/second.swift -Xlinker -install_name -Xlinker @executable_path/libsecond.dylib -lfirst -L %t -Xfrontend -enable-resilient-objc-class-stubs -DBEFORE
7+
// RUN: cp %S/Inputs/class-stubs-weak/module.map %t/
8+
// RUN: xcrun %clang %s -I %t -L %t -fmodules -fobjc-arc -o %t/main -lfirst -lsecond -Wl,-U,_objc_loadClassref
9+
10+
// Now rebuild the library, omitting the weak-exported class
11+
// RUN: %target-build-swift -emit-library -o %t/libsecond.dylib -I %t %S/Inputs/class-stubs-weak/second.swift -Xlinker -install_name -Xlinker @executable_path/libsecond.dylib -lfirst -L %t -Xfrontend -enable-resilient-objc-class-stubs
12+
13+
// RUN: %target-codesign %t/main %t/libfirst.dylib %t/libsecond.dylib
14+
// RUN: %target-run %t/main %t/libfirst.dylib %t/libsecond.dylib
15+
16+
// REQUIRES: executable_test
17+
// REQUIRES: objc_interop
18+
19+
#import <dlfcn.h>
20+
#import <stdio.h>
21+
#import "second.h"
22+
23+
@implementation DerivedClass (MyCategory)
24+
25+
- (int)instanceMethod {
26+
return [super instanceMethod] + 1;
27+
}
28+
29+
+ (int)classMethod {
30+
return [super classMethod] + 1;
31+
}
32+
33+
@end
34+
35+
int main(int argc, const char * const argv[]) {
36+
// Only test the new behavior on a new enough libobjc.
37+
if (!dlsym(RTLD_NEXT, "_objc_loadClassref")) {
38+
fprintf(stderr, "skipping evolution tests; OS too old\n");
39+
return EXIT_SUCCESS;
40+
}
41+
42+
Class cls = [DerivedClass class];
43+
if (cls) {
44+
printf("Class is not null");
45+
return EXIT_FAILURE;
46+
}
47+
48+
printf("Class is null");
49+
return EXIT_SUCCESS;
50+
}

0 commit comments

Comments
 (0)