mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
standalone: add iOS smoke test - test ability to target iOS with Zig
This commit is contained in:
parent
517a2c7caf
commit
f4afc6525b
@ -245,6 +245,10 @@ pub const build_cases = [_]BuildCase{
|
|||||||
.build_root = "test/standalone/compiler_rt_panic",
|
.build_root = "test/standalone/compiler_rt_panic",
|
||||||
.import = @import("standalone/compiler_rt_panic/build.zig"),
|
.import = @import("standalone/compiler_rt_panic/build.zig"),
|
||||||
},
|
},
|
||||||
|
.{
|
||||||
|
.build_root = "test/standalone/ios",
|
||||||
|
.import = @import("standalone/ios/build.zig"),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|||||||
37
test/standalone/ios/build.zig
Normal file
37
test/standalone/ios/build.zig
Normal 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);
|
||||||
|
}
|
||||||
34
test/standalone/ios/main.m
Normal file
34
test/standalone/ios/main.m
Normal 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
|
||||||
Loading…
x
Reference in New Issue
Block a user