authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-01 22:48:39+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-01 22:48:39+02:00
log0ce54a141628b27ceab074dac4c19827a2188165
treecb5db5a7a8ca5f47354874edbdf30a8b88f652c0
parentd794f4cd2a1e62334ba6b413864bc33bae6d41ef

add standalone Objective-C enabled on macOS only


5 files changed, 56 insertions(+), 0 deletions(-)

test/standalone.zig+4
......@@ -37,6 +37,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
3737 if (std.Target.current.os.tag == .linux) {
3838 cases.addBuildFile("test/standalone/pie/build.zig", .{});
3939 }
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 }
4044
4145 // Ensure the development tools are buildable.
4246 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 @@
1const std = @import("std");
2const Builder = std.build.Builder;
3
4pub 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
4int 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}