From d794f4cd2a1e62334ba6b413864bc33bae6d41ef Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sun, 1 Aug 2021 18:05:07 +0200 Subject: [PATCH 1/2] macho: add runaway section id when sorting sections --- src/link/MachO.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 9f9a0d5157a6f00debf356f5d261ec2769ba9fe3..61b2ff888c18e7b04d2f763d69a1450f1acd493c 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -1471,6 +1471,7 @@ fn sortSections(self: *MachO) !void { &self.cstring_section_index, &self.ustring_section_index, &self.text_const_section_index, + &self.objc_methlist_section_index, &self.objc_methname_section_index, &self.objc_methtype_section_index, &self.objc_classname_section_index, -- 2.54.0 From 0ce54a141628b27ceab074dac4c19827a2188165 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sun, 1 Aug 2021 22:48:39 +0200 Subject: [PATCH 2/2] add standalone Objective-C enabled on macOS only --- test/standalone.zig | 4 ++++ test/standalone/objc/Foo.h | 7 +++++++ test/standalone/objc/Foo.m | 11 +++++++++++ test/standalone/objc/build.zig | 22 ++++++++++++++++++++++ test/standalone/objc/test.m | 12 ++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 test/standalone/objc/Foo.h create mode 100644 test/standalone/objc/Foo.m create mode 100644 test/standalone/objc/build.zig create mode 100644 test/standalone/objc/test.m diff --git a/test/standalone.zig b/test/standalone.zig index a483097f4a2c559aaba85c937b14ca9875ded86c..52fba31828bbbba4f8a9ac42ab1ef226cc67cd8b 100644 --- a/test/standalone.zig +++ b/test/standalone.zig @@ -37,6 +37,10 @@ pub fn addCases(cases: *tests.StandaloneContext) void { if (std.Target.current.os.tag == .linux) { cases.addBuildFile("test/standalone/pie/build.zig", .{}); } + // Try to build and run an Objective-C executable. + if (std.Target.current.os.tag == .macos) { + cases.addBuildFile("test/standalone/objc/build.zig", .{ .build_modes = true }); + } // Ensure the development tools are buildable. cases.add("tools/gen_spirv_spec.zig"); diff --git a/test/standalone/objc/Foo.h b/test/standalone/objc/Foo.h new file mode 100644 index 0000000000000000000000000000000000000000..05cb7df39b9dc2cdb4b93a144dd5e9104f873772 --- /dev/null +++ b/test/standalone/objc/Foo.h @@ -0,0 +1,7 @@ +#import + +@interface Foo : NSObject + +- (NSString *)name; + +@end diff --git a/test/standalone/objc/Foo.m b/test/standalone/objc/Foo.m new file mode 100644 index 0000000000000000000000000000000000000000..6fc9b1edf0a9b0911062ae04ad4e17a11e9fa263 --- /dev/null +++ b/test/standalone/objc/Foo.m @@ -0,0 +1,11 @@ +#import "Foo.h" + +@implementation Foo + +- (NSString *)name +{ + NSString *str = [[NSString alloc] initWithFormat:@"Zig"]; + return str; +} + +@end diff --git a/test/standalone/objc/build.zig b/test/standalone/objc/build.zig new file mode 100644 index 0000000000000000000000000000000000000000..30becd398c48b16028f052b42dca83699680bde7 --- /dev/null +++ b/test/standalone/objc/build.zig @@ -0,0 +1,22 @@ +const std = @import("std"); +const Builder = std.build.Builder; + +pub fn build(b: *Builder) void { + const mode = b.standardReleaseOptions(); + const target = b.standardTargetOptions(.{}); + + const test_step = b.step("test", "Test the program"); + + const exe = b.addExecutable("test", null); + b.default_step.dependOn(&exe.step); + exe.addIncludeDir("."); + exe.addCSourceFile("Foo.m", &[0][]const u8{}); + exe.addCSourceFile("test.m", &[0][]const u8{}); + exe.setBuildMode(mode); + exe.setTarget(target); + exe.linkLibC(); + exe.linkFramework("Foundation"); + + const run_cmd = exe.run(); + test_step.dependOn(&run_cmd.step); +} diff --git a/test/standalone/objc/test.m b/test/standalone/objc/test.m new file mode 100644 index 0000000000000000000000000000000000000000..3c81316788d075a4eb3328b90e21a270c06257c8 --- /dev/null +++ b/test/standalone/objc/test.m @@ -0,0 +1,12 @@ +#import "Foo.h" +#import + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + Foo *foo = [[Foo alloc] init]; + NSString *result = [foo name]; + assert([result isEqualToString:@"Zig"]); + return 0; + } +} -- 2.54.0