Commit f4afc6525b
Changed files (3)
test
test/standalone/ios/build.zig
@@ -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);
+}
test/standalone/ios/main.m
@@ -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
test/standalone.zig
@@ -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");