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

This commit is contained in:
Jakub Konka 2023-08-18 11:58:11 +02:00
parent 517a2c7caf
commit f4afc6525b
3 changed files with 75 additions and 0 deletions

View File

@ -245,6 +245,10 @@ pub const build_cases = [_]BuildCase{
.build_root = "test/standalone/compiler_rt_panic",
.import = @import("standalone/compiler_rt_panic/build.zig"),
},
.{
.build_root = "test/standalone/ios",
.import = @import("standalone/ios/build.zig"),
},
};
const std = @import("std");

View File

@ -0,0 +1,37 @@
const std = @import("std");
pub const requires_symlinks = true;
pub const requires_ios_sdk = true;
pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Test it");
b.default_step = test_step;
const optimize: std.builtin.OptimizeMode = .Debug;
const target: std.zig.CrossTarget = .{
.cpu_arch = .aarch64,
.os_tag = .ios,
};
const target_info = std.zig.system.NativeTargetInfo.detect(target) catch @panic("couldn't detect native target");
const sdk = std.zig.system.darwin.getSdk(b.allocator, target_info.target) orelse @panic("no iOS SDK found");
b.sysroot = sdk.path;
const exe = b.addExecutable(.{
.name = "main",
.optimize = optimize,
.target = target,
});
exe.addCSourceFile(.{ .file = .{ .path = "main.m" }, .flags = &.{} });
exe.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk.path, "/usr/include" }) });
exe.addSystemFrameworkPath(.{ .path = b.pathJoin(&.{ sdk.path, "/System/Library/Frameworks" }) });
exe.addLibraryPath(.{ .path = b.pathJoin(&.{ sdk.path, "/usr/lib" }) });
exe.linkFramework("Foundation");
exe.linkFramework("UIKit");
exe.linkLibC();
const check = exe.checkObject();
check.checkStart();
check.checkExact("cmd BUILD_VERSION");
check.checkExact("platform IOS");
test_step.dependOn(&check.step);
}

View File

@ -0,0 +1,34 @@
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
int main() {
@autoreleasepool {
return UIApplicationMain(0, nil, nil, NSStringFromClass([AppDelegate class]));
}
}
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(id)options {
CGRect mainScreenBounds = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame:mainScreenBounds];
UIViewController *viewController = [[UIViewController alloc] init];
viewController.view.frame = mainScreenBounds;
NSString* msg = @"Hello world";
UILabel *label = [[UILabel alloc] initWithFrame:mainScreenBounds];
[label setText:msg];
[viewController.view addSubview: label];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
@end