authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-18 11:58:11+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-18 11:58:11+02:00
logf4afc6525b256bda323a8e3b38ed4ba2bd7ebd68
tree6a0b3bd1478661503d2524f84a2b0409e487d804
parent517a2c7cafd75e963033df479aef0916c7a4181a

standalone: add iOS smoke test - test ability to target iOS with Zig


3 files changed, 75 insertions(+), 0 deletions(-)

test/standalone.zig+4
...@@ -245,6 +245,10 @@ pub const build_cases = [_]BuildCase{...@@ -245,6 +245,10 @@ pub const build_cases = [_]BuildCase{
245 .build_root = "test/standalone/compiler_rt_panic",245 .build_root = "test/standalone/compiler_rt_panic",
246 .import = @import("standalone/compiler_rt_panic/build.zig"),246 .import = @import("standalone/compiler_rt_panic/build.zig"),
247 },247 },
248 .{
249 .build_root = "test/standalone/ios",
250 .import = @import("standalone/ios/build.zig"),
251 },
248};252};
249253
250const std = @import("std");254const std = @import("std");
test/standalone/ios/build.zig created+37
...@@ -0,0 +1,37 @@
1const std = @import("std");
2
3pub const requires_symlinks = true;
4pub const requires_ios_sdk = true;
5
6pub fn build(b: *std.Build) void {
7 const test_step = b.step("test", "Test it");
8 b.default_step = test_step;
9
10 const optimize: std.builtin.OptimizeMode = .Debug;
11 const target: std.zig.CrossTarget = .{
12 .cpu_arch = .aarch64,
13 .os_tag = .ios,
14 };
15 const target_info = std.zig.system.NativeTargetInfo.detect(target) catch @panic("couldn't detect native target");
16 const sdk = std.zig.system.darwin.getSdk(b.allocator, target_info.target) orelse @panic("no iOS SDK found");
17 b.sysroot = sdk.path;
18
19 const exe = b.addExecutable(.{
20 .name = "main",
21 .optimize = optimize,
22 .target = target,
23 });
24 exe.addCSourceFile(.{ .file = .{ .path = "main.m" }, .flags = &.{} });
25 exe.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk.path, "/usr/include" }) });
26 exe.addSystemFrameworkPath(.{ .path = b.pathJoin(&.{ sdk.path, "/System/Library/Frameworks" }) });
27 exe.addLibraryPath(.{ .path = b.pathJoin(&.{ sdk.path, "/usr/lib" }) });
28 exe.linkFramework("Foundation");
29 exe.linkFramework("UIKit");
30 exe.linkLibC();
31
32 const check = exe.checkObject();
33 check.checkStart();
34 check.checkExact("cmd BUILD_VERSION");
35 check.checkExact("platform IOS");
36 test_step.dependOn(&check.step);
37}
test/standalone/ios/main.m created+34
...@@ -0,0 +1,34 @@
1#import <UIKit/UIKit.h>
2
3@interface AppDelegate : UIResponder <UIApplicationDelegate>
4@property (strong, nonatomic) UIWindow *window;
5@end
6
7int main() {
8 @autoreleasepool {
9 return UIApplicationMain(0, nil, nil, NSStringFromClass([AppDelegate class]));
10 }
11}
12
13@implementation AppDelegate
14
15- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(id)options {
16 CGRect mainScreenBounds = [[UIScreen mainScreen] bounds];
17 self.window = [[UIWindow alloc] initWithFrame:mainScreenBounds];
18 UIViewController *viewController = [[UIViewController alloc] init];
19 viewController.view.frame = mainScreenBounds;
20
21 NSString* msg = @"Hello world";
22
23 UILabel *label = [[UILabel alloc] initWithFrame:mainScreenBounds];
24 [label setText:msg];
25 [viewController.view addSubview: label];
26
27 self.window.rootViewController = viewController;
28
29 [self.window makeKeyAndVisible];
30
31 return YES;
32}
33
34@end