diff options
| -rw-r--r-- | test/standalone.zig | 4 | ||||
| -rw-r--r-- | test/standalone/ios/build.zig | 37 | ||||
| -rw-r--r-- | test/standalone/ios/main.m | 34 |
3 files changed, 75 insertions, 0 deletions
diff --git a/test/standalone.zig b/test/standalone.zig index 3725456fa1..6618986292 100644 --- a/test/standalone.zig +++ b/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"); diff --git a/test/standalone/ios/build.zig b/test/standalone/ios/build.zig new file mode 100644 index 0000000000..4e409cb5a3 --- /dev/null +++ b/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); +} diff --git a/test/standalone/ios/main.m b/test/standalone/ios/main.m new file mode 100644 index 0000000000..35465210e3 --- /dev/null +++ b/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 |
