authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-15 12:30:55+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-24 12:34:40+01:00
log03b33b0f0139129e649f57952209586db188cb79
treec6592c3defd239acf4e2f00522d2fb86d93a44e8
parent2b3ac3e82f4207981469739b4ecd9fa0c3ac3308

test/link/macho: migrate all tests to the new test matrix


21 files changed, 136 insertions(+), 429 deletions(-)

test/link.zig-26
...@@ -89,30 +89,4 @@ pub const cases = [_]Case{...@@ -89,30 +89,4 @@ pub const cases = [_]Case{
89 .build_root = "test/link/wasm/type",89 .build_root = "test/link/wasm/type",
90 .import = @import("link/wasm/type/build.zig"),90 .import = @import("link/wasm/type/build.zig"),
91 },91 },
92
93 // Mach-O Cases
94 .{
95 .build_root = "test/link/macho/bugs/13056",
96 .import = @import("link/macho/bugs/13056/build.zig"),
97 },
98 .{
99 .build_root = "test/link/macho/bugs/13457",
100 .import = @import("link/macho/bugs/13457/build.zig"),
101 },
102 .{
103 .build_root = "test/link/macho/bugs/16308",
104 .import = @import("link/macho/bugs/16308/build.zig"),
105 },
106 .{
107 .build_root = "test/link/macho/bugs/16628",
108 .import = @import("link/macho/bugs/16628/build.zig"),
109 },
110 .{
111 .build_root = "test/link/macho/linksection",
112 .import = @import("link/macho/linksection/build.zig"),
113 },
114 .{
115 .build_root = "test/link/macho/objcpp",
116 .import = @import("link/macho/objcpp/build.zig"),
117 },
118};92};
test/link/link.zig+8
...@@ -48,6 +48,8 @@ const OverlayOptions = struct {...@@ -48,6 +48,8 @@ const OverlayOptions = struct {
48 cpp_source_flags: []const []const u8 = &.{},48 cpp_source_flags: []const []const u8 = &.{},
49 objc_source_bytes: ?[]const u8 = null,49 objc_source_bytes: ?[]const u8 = null,
50 objc_source_flags: []const []const u8 = &.{},50 objc_source_flags: []const []const u8 = &.{},
51 objcpp_source_bytes: ?[]const u8 = null,
52 objcpp_source_flags: []const []const u8 = &.{},
51 zig_source_bytes: ?[]const u8 = null,53 zig_source_bytes: ?[]const u8 = null,
52 pic: ?bool = null,54 pic: ?bool = null,
53 strip: ?bool = null,55 strip: ?bool = null,
...@@ -100,6 +102,12 @@ fn addCompileStep(...@@ -100,6 +102,12 @@ fn addCompileStep(
100 .static_lib => .static,102 .static_lib => .static,
101 },103 },
102 });104 });
105 if (overlay.objcpp_source_bytes) |bytes| {
106 compile_step.addCSourceFile(.{
107 .file = b.addWriteFiles().add("a.mm", bytes),
108 .flags = overlay.objcpp_source_flags,
109 });
110 }
103 if (overlay.objc_source_bytes) |bytes| {111 if (overlay.objc_source_bytes) |bytes| {
104 compile_step.addCSourceFile(.{112 compile_step.addCSourceFile(.{
105 .file = b.addWriteFiles().add("a.m", bytes),113 .file = b.addWriteFiles().add("a.m", bytes),
test/link/macho.zig+128-1
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1//! Here we test our MachO linker for correctness and functionality.1//! Here we test our MachO linker for correctness and functionality.
2//! TODO migrate standalone tests from test/link/macho/* to here.
32
4pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {3pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
5 const macho_step = b.step("test-macho", "Run MachO tests");4 const macho_step = b.step("test-macho", "Run MachO tests");
...@@ -18,12 +17,14 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {...@@ -18,12 +17,14 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
1817
19 macho_step.dependOn(testDeadStrip(b, .{ .target = default_target }));18 macho_step.dependOn(testDeadStrip(b, .{ .target = default_target }));
20 macho_step.dependOn(testEmptyObject(b, .{ .target = default_target }));19 macho_step.dependOn(testEmptyObject(b, .{ .target = default_target }));
20 macho_step.dependOn(testEmptyZig(b, .{ .target = default_target }));
21 macho_step.dependOn(testEntryPoint(b, .{ .target = default_target }));21 macho_step.dependOn(testEntryPoint(b, .{ .target = default_target }));
22 macho_step.dependOn(testHeaderWeakFlags(b, .{ .target = default_target }));22 macho_step.dependOn(testHeaderWeakFlags(b, .{ .target = default_target }));
23 macho_step.dependOn(testHelloC(b, .{ .target = default_target }));23 macho_step.dependOn(testHelloC(b, .{ .target = default_target }));
24 macho_step.dependOn(testHelloZig(b, .{ .target = default_target }));24 macho_step.dependOn(testHelloZig(b, .{ .target = default_target }));
25 macho_step.dependOn(testLargeBss(b, .{ .target = default_target }));25 macho_step.dependOn(testLargeBss(b, .{ .target = default_target }));
26 macho_step.dependOn(testLayout(b, .{ .target = default_target }));26 macho_step.dependOn(testLayout(b, .{ .target = default_target }));
27 macho_step.dependOn(testLinksection(b, .{ .target = default_target }));
27 macho_step.dependOn(testMhExecuteHeader(b, .{ .target = default_target }));28 macho_step.dependOn(testMhExecuteHeader(b, .{ .target = default_target }));
28 macho_step.dependOn(testNoDeadStrip(b, .{ .target = default_target }));29 macho_step.dependOn(testNoDeadStrip(b, .{ .target = default_target }));
29 macho_step.dependOn(testNoExportsDylib(b, .{ .target = default_target }));30 macho_step.dependOn(testNoExportsDylib(b, .{ .target = default_target }));
...@@ -59,8 +60,10 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {...@@ -59,8 +60,10 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
59 if (build_opts.has_macos_sdk) {60 if (build_opts.has_macos_sdk) {
60 macho_step.dependOn(testDeadStripDylibs(b, .{ .target = b.host }));61 macho_step.dependOn(testDeadStripDylibs(b, .{ .target = b.host }));
61 macho_step.dependOn(testHeaderpad(b, .{ .target = b.host }));62 macho_step.dependOn(testHeaderpad(b, .{ .target = b.host }));
63 macho_step.dependOn(testLinkDirectlyCppTbd(b, .{ .target = b.host }));
62 macho_step.dependOn(testNeededFramework(b, .{ .target = b.host }));64 macho_step.dependOn(testNeededFramework(b, .{ .target = b.host }));
63 macho_step.dependOn(testObjc(b, .{ .target = b.host }));65 macho_step.dependOn(testObjc(b, .{ .target = b.host }));
66 macho_step.dependOn(testObjcpp(b, .{ .target = b.host }));
64 macho_step.dependOn(testWeakFramework(b, .{ .target = b.host }));67 macho_step.dependOn(testWeakFramework(b, .{ .target = b.host }));
65 }68 }
66 }69 }
...@@ -255,6 +258,18 @@ fn testEmptyObject(b: *Build, opts: Options) *Step {...@@ -255,6 +258,18 @@ fn testEmptyObject(b: *Build, opts: Options) *Step {
255 return test_step;258 return test_step;
256}259}
257260
261fn testEmptyZig(b: *Build, opts: Options) *Step {
262 const test_step = addTestStep(b, "macho-empty-zig", opts);
263
264 const exe = addExecutable(b, opts, .{ .name = "empty", .zig_source_bytes = "pub fn main() void {}" });
265
266 const run = addRunArtifact(exe);
267 run.expectExitCode(0);
268 test_step.dependOn(&run.step);
269
270 return test_step;
271}
272
258fn testEntryPoint(b: *Build, opts: Options) *Step {273fn testEntryPoint(b: *Build, opts: Options) *Step {
259 const test_step = addTestStep(b, "macho-entry-point", opts);274 const test_step = addTestStep(b, "macho-entry-point", opts);
260275
...@@ -745,6 +760,65 @@ fn testLayout(b: *Build, opts: Options) *Step {...@@ -745,6 +760,65 @@ fn testLayout(b: *Build, opts: Options) *Step {
745 return test_step;760 return test_step;
746}761}
747762
763fn testLinkDirectlyCppTbd(b: *Build, opts: Options) *Step {
764 const test_step = addTestStep(b, "macho-link-directly-cpp-tbd", opts);
765
766 const sdk = std.zig.system.darwin.getSdk(b.allocator, opts.target.result) orelse
767 @panic("macOS SDK is required to run the test");
768
769 const exe = addExecutable(b, opts, .{
770 .name = "main",
771 .cpp_source_bytes =
772 \\#include <new>
773 \\#include <cstdio>
774 \\int main() {
775 \\ int *x = new int;
776 \\ *x = 5;
777 \\ fprintf(stderr, "x: %d\n", *x);
778 \\ delete x;
779 \\}
780 ,
781 .cpp_source_flags = &.{ "-nostdlib++", "-nostdinc++" },
782 });
783 exe.root_module.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include" }) });
784 exe.root_module.addIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include/c++/v1" }) });
785 exe.root_module.addObjectFile(.{ .path = b.pathJoin(&.{ sdk, "/usr/lib/libc++.tbd" }) });
786
787 const check = exe.checkObject();
788 check.checkInSymtab();
789 check.checkContains("[referenced dynamically] external __mh_execute_header");
790 test_step.dependOn(&check.step);
791
792 return test_step;
793}
794
795fn testLinksection(b: *Build, opts: Options) *Step {
796 const test_step = addTestStep(b, "macho-linksection", opts);
797
798 const obj = addObject(b, opts, .{ .name = "main", .zig_source_bytes =
799 \\export var test_global: u32 linksection("__DATA,__TestGlobal") = undefined;
800 \\export fn testFn() linksection("__TEXT,__TestFn") callconv(.C) void {
801 \\ testGenericFn("A");
802 \\}
803 \\fn testGenericFn(comptime suffix: []const u8) linksection("__TEXT,__TestGenFn" ++ suffix) void {}
804 });
805
806 const check = obj.checkObject();
807 check.checkInSymtab();
808 check.checkContains("(__DATA,__TestGlobal) external _test_global");
809 check.checkInSymtab();
810 check.checkContains("(__TEXT,__TestFn) external _testFn");
811
812 if (opts.optimize == .Debug) {
813 check.checkInSymtab();
814 check.checkContains("(__TEXT,__TestGenFnA) _a.testGenericFn__anon_");
815 }
816
817 test_step.dependOn(&check.step);
818
819 return test_step;
820}
821
748fn testMhExecuteHeader(b: *Build, opts: Options) *Step {822fn testMhExecuteHeader(b: *Build, opts: Options) *Step {
749 const test_step = addTestStep(b, "macho-mh-execute-header", opts);823 const test_step = addTestStep(b, "macho-mh-execute-header", opts);
750824
...@@ -870,6 +944,59 @@ fn testObjc(b: *Build, opts: Options) *Step {...@@ -870,6 +944,59 @@ fn testObjc(b: *Build, opts: Options) *Step {
870 return test_step;944 return test_step;
871}945}
872946
947fn testObjcpp(b: *Build, opts: Options) *Step {
948 const test_step = addTestStep(b, "macho-objcpp", opts);
949
950 const foo_h = foo_h: {
951 const wf = WriteFile.create(b);
952 break :foo_h wf.add("Foo.h",
953 \\#import <Foundation/Foundation.h>
954 \\@interface Foo : NSObject
955 \\- (NSString *)name;
956 \\@end
957 );
958 };
959
960 const foo_o = addObject(b, opts, .{ .name = "foo", .objcpp_source_bytes =
961 \\#import "Foo.h"
962 \\@implementation Foo
963 \\- (NSString *)name
964 \\{
965 \\ NSString *str = [[NSString alloc] initWithFormat:@"Zig"];
966 \\ return str;
967 \\}
968 \\@end
969 });
970 foo_o.root_module.addIncludePath(foo_h.dirname());
971 foo_o.linkLibCpp();
972
973 const exe = addExecutable(b, opts, .{ .name = "main", .objcpp_source_bytes =
974 \\#import "Foo.h"
975 \\#import <assert.h>
976 \\#include <iostream>
977 \\int main(int argc, char *argv[])
978 \\{
979 \\ @autoreleasepool {
980 \\ Foo *foo = [[Foo alloc] init];
981 \\ NSString *result = [foo name];
982 \\ std::cout << "Hello from C++ and " << [result UTF8String];
983 \\ assert([result isEqualToString:@"Zig"]);
984 \\ return 0;
985 \\ }
986 \\}
987 });
988 exe.root_module.addIncludePath(foo_h.dirname());
989 exe.addObject(foo_o);
990 exe.linkLibCpp();
991 exe.root_module.linkFramework("Foundation", .{});
992
993 const run = addRunArtifact(exe);
994 run.expectStdOutEqual("Hello from C++ and Zig");
995 test_step.dependOn(&run.step);
996
997 return test_step;
998}
999
873fn testPagezeroSize(b: *Build, opts: Options) *Step {1000fn testPagezeroSize(b: *Build, opts: Options) *Step {
874 const test_step = addTestStep(b, "macho-pagezero-size", opts);1001 const test_step = addTestStep(b, "macho-pagezero-size", opts);
8751002
test/link/macho/bugs/13056/build.zig deleted-38
...@@ -1,38 +0,0 @@
1const std = @import("std");
2
3pub const requires_macos_sdk = true;
4pub const requires_symlinks = true;
5
6pub fn build(b: *std.Build) void {
7 const test_step = b.step("test", "Test it");
8 b.default_step = test_step;
9
10 add(b, test_step, .Debug);
11 add(b, test_step, .ReleaseFast);
12 add(b, test_step, .ReleaseSmall);
13 add(b, test_step, .ReleaseSafe);
14}
15
16fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
17 const target = b.resolveTargetQuery(.{ .os_tag = .macos });
18 const sdk = std.zig.system.darwin.getSdk(b.allocator, target.result) orelse
19 @panic("macOS SDK is required to run the test");
20
21 const exe = b.addExecutable(.{
22 .name = "test",
23 .optimize = optimize,
24 .target = b.host,
25 });
26 exe.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include" }) });
27 exe.addIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include/c++/v1" }) });
28 exe.addCSourceFile(.{ .file = .{ .path = "test.cpp" }, .flags = &.{
29 "-nostdlib++",
30 "-nostdinc++",
31 } });
32 exe.addObjectFile(.{ .path = b.pathJoin(&.{ sdk, "/usr/lib/libc++.tbd" }) });
33
34 const run_cmd = b.addRunArtifact(exe);
35 run_cmd.expectStdErrEqual("x: 5\n");
36
37 test_step.dependOn(&run_cmd.step);
38}
test/link/macho/bugs/13056/test.cpp deleted-10
...@@ -1,10 +0,0 @@
1// test.cpp
2#include <new>
3#include <cstdio>
4
5int main() {
6 int *x = new int;
7 *x = 5;
8 fprintf(stderr, "x: %d\n", *x);
9 delete x;
10}
test/link/macho/bugs/13457/build.zig deleted-30
...@@ -1,30 +0,0 @@
1const std = @import("std");
2
3pub const requires_symlinks = true;
4
5pub fn build(b: *std.Build) void {
6 const test_step = b.step("test", "Test it");
7 b.default_step = test_step;
8
9 add(b, test_step, .Debug);
10 add(b, test_step, .ReleaseFast);
11 add(b, test_step, .ReleaseSmall);
12 add(b, test_step, .ReleaseSafe);
13}
14
15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const target = b.resolveTargetQuery(.{ .os_tag = .macos });
17
18 const exe = b.addExecutable(.{
19 .name = "test",
20 .root_source_file = .{ .path = "main.zig" },
21 .optimize = optimize,
22 .target = target,
23 });
24
25 const run = b.addRunArtifact(exe);
26 run.skip_foreign_checks = true;
27 run.expectStdOutEqual("");
28
29 test_step.dependOn(&run.step);
30}
test/link/macho/bugs/13457/main.zig deleted-1
...@@ -1 +0,0 @@
1pub fn main() void {}
test/link/macho/bugs/16308/build.zig deleted-23
...@@ -1,23 +0,0 @@
1const std = @import("std");
2
3pub const requires_symlinks = true;
4
5pub fn build(b: *std.Build) void {
6 const test_step = b.step("test", "Test it");
7 b.default_step = test_step;
8
9 const target = b.resolveTargetQuery(.{ .os_tag = .macos });
10
11 const lib = b.addSharedLibrary(.{
12 .name = "a",
13 .root_source_file = .{ .path = "main.zig" },
14 .optimize = .Debug,
15 .target = target,
16 });
17
18 const check = lib.checkObject();
19 check.checkInSymtab();
20 check.checkNotPresent("external _abc");
21
22 test_step.dependOn(&check.step);
23}
test/link/macho/bugs/16308/main.zig deleted-1
...@@ -1 +0,0 @@
1fn abc() void {}
test/link/macho/bugs/16628/a_arm64.s deleted-37
...@@ -1,37 +0,0 @@
1.globl _foo
2.align 4
3_foo:
4 .cfi_startproc
5 stp x29, x30, [sp, #-32]!
6 .cfi_def_cfa_offset 32
7 .cfi_offset w30, -24
8 .cfi_offset w29, -32
9 mov x29, sp
10 .cfi_def_cfa w29, 32
11 bl _bar
12 ldp x29, x30, [sp], #32
13 .cfi_restore w29
14 .cfi_restore w30
15 .cfi_def_cfa_offset 0
16 ret
17 .cfi_endproc
18
19.globl _bar
20.align 4
21_bar:
22 .cfi_startproc
23 sub sp, sp, #32
24 .cfi_def_cfa_offset -32
25 stp x29, x30, [sp, #16]
26 .cfi_offset w30, -24
27 .cfi_offset w29, -32
28 mov x29, sp
29 .cfi_def_cfa w29, 32
30 mov w0, #4
31 ldp x29, x30, [sp, #16]
32 .cfi_restore w29
33 .cfi_restore w30
34 add sp, sp, #32
35 .cfi_def_cfa_offset 0
36 ret
37 .cfi_endproc
test/link/macho/bugs/16628/a_x64.s deleted-29
...@@ -1,29 +0,0 @@
1.globl _foo
2_foo:
3 .cfi_startproc
4 push %rbp
5 .cfi_def_cfa_offset 8
6 .cfi_offset %rbp, -8
7 mov %rsp, %rbp
8 .cfi_def_cfa_register %rbp
9 call _bar
10 pop %rbp
11 .cfi_restore %rbp
12 .cfi_def_cfa_offset 0
13 ret
14 .cfi_endproc
15
16.globl _bar
17_bar:
18 .cfi_startproc
19 push %rbp
20 .cfi_def_cfa_offset 8
21 .cfi_offset %rbp, -8
22 mov %rsp, %rbp
23 .cfi_def_cfa_register %rbp
24 mov $4, %rax
25 pop %rbp
26 .cfi_restore %rbp
27 .cfi_def_cfa_offset 0
28 ret
29 .cfi_endproc
test/link/macho/bugs/16628/build.zig deleted-42
...@@ -1,42 +0,0 @@
1const std = @import("std");
2const builtin = @import("builtin");
3
4pub const requires_symlinks = true;
5pub const requires_macos_sdk = false;
6
7pub fn build(b: *std.Build) void {
8 const test_step = b.step("test", "Test it");
9 b.default_step = test_step;
10
11 add(b, test_step, .Debug);
12 add(b, test_step, .ReleaseFast);
13 add(b, test_step, .ReleaseSmall);
14 add(b, test_step, .ReleaseSafe);
15}
16
17fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
18 const target = b.resolveTargetQuery(.{ .os_tag = .macos });
19
20 const exe = b.addExecutable(.{
21 .name = "test",
22 .optimize = optimize,
23 .target = target,
24 });
25 exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
26 switch (builtin.cpu.arch) {
27 .aarch64 => {
28 exe.addCSourceFile(.{ .file = .{ .path = "a_arm64.s" }, .flags = &[0][]const u8{} });
29 },
30 .x86_64 => {
31 exe.addCSourceFile(.{ .file = .{ .path = "a_x64.s" }, .flags = &[0][]const u8{} });
32 },
33 else => unreachable,
34 }
35 exe.linkLibC();
36
37 const run = b.addRunArtifact(exe);
38 run.skip_foreign_checks = true;
39 run.expectStdOutEqual("4\n");
40
41 test_step.dependOn(&run.step);
42}
test/link/macho/bugs/16628/main.c deleted-8
...@@ -1,8 +0,0 @@
1#include <stdio.h>
2
3int foo();
4
5int main() {
6 printf("%d\n", foo());
7 return 0;
8}
test/link/macho/dead_strip_dylibs/build.zig deleted-61
...@@ -1,61 +0,0 @@
1const std = @import("std");
2
3pub const requires_macos_sdk = true;
4pub const requires_symlinks = true;
5
6pub fn build(b: *std.Build) void {
7 const test_step = b.step("test", "Test it");
8 b.default_step = test_step;
9
10 add(b, test_step, .Debug);
11 add(b, test_step, .ReleaseFast);
12 add(b, test_step, .ReleaseSmall);
13 add(b, test_step, .ReleaseSafe);
14}
15
16fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
17 {
18 // Without -dead_strip_dylibs we expect `-la` to include liba.dylib in the final executable
19 const exe = createScenario(b, optimize, "no-dead-strip");
20
21 const check = exe.checkObject();
22 check.checkInHeaders();
23 check.checkExact("cmd LOAD_DYLIB");
24 check.checkContains("Cocoa");
25
26 check.checkInHeaders();
27 check.checkExact("cmd LOAD_DYLIB");
28 check.checkContains("libobjc");
29
30 test_step.dependOn(&check.step);
31
32 const run_cmd = b.addRunArtifact(exe);
33 test_step.dependOn(&run_cmd.step);
34 }
35
36 {
37 // With -dead_strip_dylibs, we should include liba.dylib as it's unreachable
38 const exe = createScenario(b, optimize, "yes-dead-strip");
39 exe.dead_strip_dylibs = true;
40
41 const run_cmd = b.addRunArtifact(exe);
42 run_cmd.expectExitCode(@as(u8, @bitCast(@as(i8, -2)))); // should fail
43 test_step.dependOn(&run_cmd.step);
44 }
45}
46
47fn createScenario(
48 b: *std.Build,
49 optimize: std.builtin.OptimizeMode,
50 name: []const u8,
51) *std.Build.Step.Compile {
52 const exe = b.addExecutable(.{
53 .name = name,
54 .optimize = optimize,
55 .target = b.host,
56 });
57 exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
58 exe.linkLibC();
59 exe.linkFramework("Cocoa");
60 return exe;
61}
test/link/macho/dead_strip_dylibs/main.c deleted-11
...@@ -1,11 +0,0 @@
1#include <objc/runtime.h>
2
3int main(int argc, char* argv[]) {
4 if (objc_getClass("NSObject") == 0) {
5 return -1;
6 }
7 if (objc_getClass("NSApplication") == 0) {
8 return -2;
9 }
10 return 0;
11}
test/link/macho/linksection/build.zig deleted-39
...@@ -1,39 +0,0 @@
1const std = @import("std");
2
3pub const requires_symlinks = true;
4
5pub fn build(b: *std.Build) void {
6 const test_step = b.step("test", "Test it");
7 b.default_step = test_step;
8
9 add(b, test_step, .Debug);
10 add(b, test_step, .ReleaseFast);
11 add(b, test_step, .ReleaseSmall);
12 add(b, test_step, .ReleaseSafe);
13}
14
15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const target = b.resolveTargetQuery(.{ .os_tag = .macos });
17
18 const obj = b.addObject(.{
19 .name = "test",
20 .root_source_file = .{ .path = "main.zig" },
21 .optimize = optimize,
22 .target = target,
23 });
24
25 const check = obj.checkObject();
26
27 check.checkInSymtab();
28 check.checkContains("(__DATA,__TestGlobal) external _test_global");
29
30 check.checkInSymtab();
31 check.checkContains("(__TEXT,__TestFn) external _testFn");
32
33 if (optimize == .Debug) {
34 check.checkInSymtab();
35 check.checkContains("(__TEXT,__TestGenFnA) _main.testGenericFn__anon_");
36 }
37
38 test_step.dependOn(&check.step);
39}
test/link/macho/linksection/main.zig deleted-5
...@@ -1,5 +0,0 @@
1export var test_global: u32 linksection("__DATA,__TestGlobal") = undefined;
2export fn testFn() linksection("__TEXT,__TestFn") callconv(.C) void {
3 testGenericFn("A");
4}
5fn testGenericFn(comptime suffix: []const u8) linksection("__TEXT,__TestGenFn" ++ suffix) void {}
test/link/macho/objcpp/Foo.h deleted-7
...@@ -1,7 +0,0 @@
1#import <Foundation/Foundation.h>
2
3@interface Foo : NSObject
4
5- (NSString *)name;
6
7@end
test/link/macho/objcpp/Foo.mm deleted-11
...@@ -1,11 +0,0 @@
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/link/macho/objcpp/build.zig deleted-35
...@@ -1,35 +0,0 @@
1const std = @import("std");
2
3pub const requires_symlinks = true;
4pub const requires_macos_sdk = true;
5
6pub fn build(b: *std.Build) void {
7 const test_step = b.step("test", "Test it");
8 b.default_step = test_step;
9
10 add(b, test_step, .Debug);
11 add(b, test_step, .ReleaseFast);
12 add(b, test_step, .ReleaseSmall);
13 add(b, test_step, .ReleaseSafe);
14}
15
16fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
17 const exe = b.addExecutable(.{
18 .name = "test",
19 .optimize = optimize,
20 .target = b.host,
21 });
22 b.default_step.dependOn(&exe.step);
23 exe.addIncludePath(.{ .path = "." });
24 exe.addCSourceFile(.{ .file = .{ .path = "Foo.mm" }, .flags = &[0][]const u8{} });
25 exe.addCSourceFile(.{ .file = .{ .path = "test.mm" }, .flags = &[0][]const u8{} });
26 exe.linkLibCpp();
27 // TODO when we figure out how to ship framework stubs for cross-compilation,
28 // populate paths to the sysroot here.
29 exe.linkFramework("Foundation");
30
31 const run_cmd = b.addRunArtifact(exe);
32 run_cmd.expectStdOutEqual("Hello from C++ and Zig");
33
34 test_step.dependOn(&run_cmd.step);
35}
test/link/macho/objcpp/test.mm deleted-14
...@@ -1,14 +0,0 @@
1#import "Foo.h"
2#import <assert.h>
3#include <iostream>
4
5int main(int argc, char *argv[])
6{
7 @autoreleasepool {
8 Foo *foo = [[Foo alloc] init];
9 NSString *result = [foo name];
10 std::cout << "Hello from C++ and " << [result UTF8String];
11 assert([result isEqualToString:@"Zig"]);
12 return 0;
13 }
14}