| author | |
| committer | |
| log | 0ce54a141628b27ceab074dac4c19827a2188165 |
| tree | cb5db5a7a8ca5f47354874edbdf30a8b88f652c0 |
| parent | d794f4cd2a1e62334ba6b413864bc33bae6d41ef |
5 files changed, 56 insertions(+), 0 deletions(-)
test/standalone.zig+4| ... | ... | @@ -37,6 +37,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 37 | 37 | if (std.Target.current.os.tag == .linux) { |
| 38 | 38 | cases.addBuildFile("test/standalone/pie/build.zig", .{}); |
| 39 | 39 | } |
| 40 | // Try to build and run an Objective-C executable. | |
| 41 | if (std.Target.current.os.tag == .macos) { | |
| 42 | cases.addBuildFile("test/standalone/objc/build.zig", .{ .build_modes = true }); | |
| 43 | } | |
| 40 | 44 | |
| 41 | 45 | // Ensure the development tools are buildable. |
| 42 | 46 | cases.add("tools/gen_spirv_spec.zig"); |
test/standalone/objc/Foo.h created+7| ... | ... | @@ -0,0 +1,7 @@ |
| 1 | #import <Foundation/Foundation.h> | |
| 2 | ||
| 3 | @interface Foo : NSObject | |
| 4 | ||
| 5 | - (NSString *)name; | |
| 6 | ||
| 7 | @end |
test/standalone/objc/Foo.m created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | #import "Foo.h" | |
| 2 | ||
| 3 | @implementation Foo | |
| 4 | ||
| 5 | - (NSString *)name | |
| 6 | { | |
| 7 | NSString *str = [[NSString alloc] initWithFormat:@"Zig"]; | |
| 8 | return str; | |
| 9 | } | |
| 10 | ||
| 11 | @end |
test/standalone/objc/build.zig created+22| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | const std = @import("std"); | |
| 2 | const Builder = std.build.Builder; | |
| 3 | ||
| 4 | pub fn build(b: *Builder) void { | |
| 5 | const mode = b.standardReleaseOptions(); | |
| 6 | const target = b.standardTargetOptions(.{}); | |
| 7 | ||
| 8 | const test_step = b.step("test", "Test the program"); | |
| 9 | ||
| 10 | const exe = b.addExecutable("test", null); | |
| 11 | b.default_step.dependOn(&exe.step); | |
| 12 | exe.addIncludeDir("."); | |
| 13 | exe.addCSourceFile("Foo.m", &[0][]const u8{}); | |
| 14 | exe.addCSourceFile("test.m", &[0][]const u8{}); | |
| 15 | exe.setBuildMode(mode); | |
| 16 | exe.setTarget(target); | |
| 17 | exe.linkLibC(); | |
| 18 | exe.linkFramework("Foundation"); | |
| 19 | ||
| 20 | const run_cmd = exe.run(); | |
| 21 | test_step.dependOn(&run_cmd.step); | |
| 22 | } |
test/standalone/objc/test.m created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | #import "Foo.h" | |
| 2 | #import <assert.h> | |
| 3 | ||
| 4 | int main(int argc, char *argv[]) | |
| 5 | { | |
| 6 | @autoreleasepool { | |
| 7 | Foo *foo = [[Foo alloc] init]; | |
| 8 | NSString *result = [foo name]; | |
| 9 | assert([result isEqualToString:@"Zig"]); | |
| 10 | return 0; | |
| 11 | } | |
| 12 | } |