| author | |
| committer | |
| log | eba153f88f0bdb36a654bd2cb794d2ead9d4e398 |
| tree | 9c7bb9eb49062b505b83d3519dd7ea62d12b4bad |
| parent | dae4c18aa7999a866b6b145ed3c88cb6c06852be |
| parent | 0ce54a141628b27ceab074dac4c19827a2188165 |
| signature |
Add standalone Objective-C enabled on macOS only6 files changed, 57 insertions(+), 0 deletions(-)
src/link/MachO.zig+1| ... | @@ -1471,6 +1471,7 @@ fn sortSections(self: *MachO) !void { | ... | @@ -1471,6 +1471,7 @@ fn sortSections(self: *MachO) !void { |
| 1471 | &self.cstring_section_index, | 1471 | &self.cstring_section_index, |
| 1472 | &self.ustring_section_index, | 1472 | &self.ustring_section_index, |
| 1473 | &self.text_const_section_index, | 1473 | &self.text_const_section_index, |
| 1474 | &self.objc_methlist_section_index, | ||
| 1474 | &self.objc_methname_section_index, | 1475 | &self.objc_methname_section_index, |
| 1475 | &self.objc_methtype_section_index, | 1476 | &self.objc_methtype_section_index, |
| 1476 | &self.objc_classname_section_index, | 1477 | &self.objc_classname_section_index, |
test/standalone.zig+4| ... | @@ -37,6 +37,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void { | ... | @@ -37,6 +37,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 37 | if (std.Target.current.os.tag == .linux) { | 37 | if (std.Target.current.os.tag == .linux) { |
| 38 | cases.addBuildFile("test/standalone/pie/build.zig", .{}); | 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 | // Ensure the development tools are buildable. | 45 | // Ensure the development tools are buildable. |
| 42 | cases.add("tools/gen_spirv_spec.zig"); | 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 | } | ||