authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-07 20:23:11-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:14-07:00
log1142e0534351a57b81bd4a127f29745c62cc59c9
tree6ad6df8fef7c05de06fe2a34fc577f7756a32652
parent9a9b0083009f62dda9500f978544380a17b1f325

re-enable macho linker tests


25 files changed, 385 insertions(+), 233 deletions(-)

build.zig+1-1
......@@ -454,7 +454,7 @@ pub fn build(b: *std.Build) !void {
454454 // enable_symlinks_windows,
455455 //));
456456 test_step.dependOn(tests.addCAbiTests(b, skip_non_native, skip_release));
457 test_step.dependOn(tests.addLinkTests(b, test_filter, optimization_modes, enable_macos_sdk, skip_stage2_tests, enable_symlinks_windows));
457 test_step.dependOn(tests.addLinkTests(b, enable_macos_sdk, skip_stage2_tests, enable_symlinks_windows));
458458 test_step.dependOn(tests.addStackTraceTests(b, test_filter, optimization_modes));
459459 test_step.dependOn(tests.addCliTests(b, test_filter, optimization_modes));
460460 test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, optimization_modes));
test/link.zig+97-116
......@@ -76,122 +76,103 @@ pub const cases = [_]Case{
7676 },
7777
7878 // Mach-O Cases
79 // cases.addBuildFile("test/link/macho/bugs/13056/build.zig", .{
80 // .build_modes = true,
81 // .requires_macos_sdk = true,
82 // .requires_symlinks = true,
83 // });
84 //
85 // cases.addBuildFile("test/link/macho/bugs/13457/build.zig", .{
86 // .build_modes = true,
87 // .requires_symlinks = true,
88 // });
89 //
90 // cases.addBuildFile("test/link/macho/dead_strip/build.zig", .{
91 // .build_modes = false,
92 // .requires_symlinks = true,
93 // });
94 //
95 // cases.addBuildFile("test/link/macho/dead_strip_dylibs/build.zig", .{
96 // .build_modes = true,
97 // .requires_macos_sdk = true,
98 // .requires_symlinks = true,
99 // });
100 //
101 // cases.addBuildFile("test/link/macho/dylib/build.zig", .{
102 // .build_modes = true,
103 // .requires_symlinks = true,
104 // });
105 //
106 // cases.addBuildFile("test/link/macho/empty/build.zig", .{
107 // .build_modes = true,
108 // .requires_symlinks = true,
109 // });
110 //
111 // cases.addBuildFile("test/link/macho/entry/build.zig", .{
112 // .build_modes = true,
113 // .requires_symlinks = true,
114 // });
115 //
116 // cases.addBuildFile("test/link/macho/headerpad/build.zig", .{
117 // .build_modes = true,
118 // .requires_macos_sdk = true,
119 // .requires_symlinks = true,
120 // });
121 //
122 // cases.addBuildFile("test/link/macho/linksection/build.zig", .{
123 // .build_modes = true,
124 // .requires_symlinks = true,
125 // });
126 //
127 // cases.addBuildFile("test/link/macho/needed_framework/build.zig", .{
128 // .build_modes = true,
129 // .requires_macos_sdk = true,
130 // .requires_symlinks = true,
131 // });
132 //
133 // cases.addBuildFile("test/link/macho/needed_library/build.zig", .{
134 // .build_modes = true,
135 // .requires_symlinks = true,
136 // });
137 //
138 // cases.addBuildFile("test/link/macho/objc/build.zig", .{
139 // .build_modes = true,
140 // .requires_macos_sdk = true,
141 // .requires_symlinks = true,
142 // });
143 //
144 // cases.addBuildFile("test/link/macho/objcpp/build.zig", .{
145 // .build_modes = true,
146 // .requires_macos_sdk = true,
147 // .requires_symlinks = true,
148 // });
149 //
150 // cases.addBuildFile("test/link/macho/pagezero/build.zig", .{
151 // .build_modes = false,
152 // .requires_symlinks = true,
153 // });
154 //
155 // cases.addBuildFile("test/link/macho/search_strategy/build.zig", .{
156 // .build_modes = true,
157 // .requires_symlinks = true,
158 // });
159 //
160 // cases.addBuildFile("test/link/macho/stack_size/build.zig", .{
161 // .build_modes = true,
162 // .requires_symlinks = true,
163 // });
164 //
165 // cases.addBuildFile("test/link/macho/strict_validation/build.zig", .{
166 // .build_modes = true,
167 // .requires_symlinks = true,
168 // });
169 //
170 // cases.addBuildFile("test/link/macho/tls/build.zig", .{
171 // .build_modes = true,
172 // .requires_symlinks = true,
173 // });
174 //
175 // cases.addBuildFile("test/link/macho/unwind_info/build.zig", .{
176 // .build_modes = true,
177 // .requires_symlinks = true,
178 // });
179 //
180 // cases.addBuildFile("test/link/macho/uuid/build.zig", .{
181 // .build_modes = false,
182 // .requires_symlinks = true,
183 // });
184 //
185 // cases.addBuildFile("test/link/macho/weak_library/build.zig", .{
186 // .build_modes = true,
187 // .requires_symlinks = true,
188 // });
189 //
190 // cases.addBuildFile("test/link/macho/weak_framework/build.zig", .{
191 // .build_modes = true,
192 // .requires_macos_sdk = true,
193 // .requires_symlinks = true,
194 // });
79 .{
80 .build_root = "test/link/macho/bugs/13056",
81 .import = @import("link/macho/bugs/13056/build.zig"),
82 },
83 .{
84 .build_root = "test/link/macho/bugs/13457",
85 .import = @import("link/macho/bugs/13457/build.zig"),
86 },
87 .{
88 .build_root = "test/link/macho/bugs/13457",
89 .import = @import("link/macho/bugs/13457/build.zig"),
90 },
91 .{
92 .build_root = "test/link/macho/dead_strip",
93 .import = @import("link/macho/dead_strip/build.zig"),
94 },
95 .{
96 .build_root = "test/link/macho/dead_strip_dylibs",
97 .import = @import("link/macho/dead_strip_dylibs/build.zig"),
98 },
99 .{
100 .build_root = "test/link/macho/dylib",
101 .import = @import("link/macho/dylib/build.zig"),
102 },
103 .{
104 .build_root = "test/link/macho/empty",
105 .import = @import("link/macho/empty/build.zig"),
106 },
107 .{
108 .build_root = "test/link/macho/entry",
109 .import = @import("link/macho/entry/build.zig"),
110 },
111 .{
112 .build_root = "test/link/macho/headerpad",
113 .import = @import("link/macho/headerpad/build.zig"),
114 },
115 .{
116 .build_root = "test/link/macho/linksection",
117 .import = @import("link/macho/linksection/build.zig"),
118 },
119 .{
120 .build_root = "test/link/macho/needed_framework",
121 .import = @import("link/macho/needed_framework/build.zig"),
122 },
123 .{
124 .build_root = "test/link/macho/needed_library",
125 .import = @import("link/macho/needed_library/build.zig"),
126 },
127 .{
128 .build_root = "test/link/macho/objc",
129 .import = @import("link/macho/objc/build.zig"),
130 },
131 .{
132 .build_root = "test/link/macho/objcpp",
133 .import = @import("link/macho/objcpp/build.zig"),
134 },
135 .{
136 .build_root = "test/link/macho/pagezero",
137 .import = @import("link/macho/pagezero/build.zig"),
138 },
139 .{
140 .build_root = "test/link/macho/search_strategy",
141 .import = @import("link/macho/search_strategy/build.zig"),
142 },
143 .{
144 .build_root = "test/link/macho/stack_size",
145 .import = @import("link/macho/stack_size/build.zig"),
146 },
147 .{
148 .build_root = "test/link/macho/strict_validation",
149 .import = @import("link/macho/strict_validation/build.zig"),
150 },
151 .{
152 .build_root = "test/link/macho/tls",
153 .import = @import("link/macho/tls/build.zig"),
154 },
155 .{
156 .build_root = "test/link/macho/unwind_info",
157 .import = @import("link/macho/unwind_info/build.zig"),
158 },
159 // TODO: re-enable this test. It currently has some incompatibilities with
160 // the new build system API. In particular, it depends on installing the build
161 // artifacts, which should be unnecessary, and it has a custom build step that
162 // prints directly to stderr instead of failing the step with an error message.
163 //.{
164 // .build_root = "test/link/macho/uuid",
165 // .import = @import("link/macho/uuid/build.zig"),
166 //},
167
168 .{
169 .build_root = "test/link/macho/weak_library",
170 .import = @import("link/macho/weak_library/build.zig"),
171 },
172 .{
173 .build_root = "test/link/macho/weak_framework",
174 .import = @import("link/macho/weak_framework/build.zig"),
175 },
195176};
196177
197178const std = @import("std");
test/link/macho/bugs/13056/build.zig+12-4
......@@ -1,20 +1,28 @@
11const std = @import("std");
22
3pub const requires_macos_sdk = true;
4pub const requires_symlinks = true;
5
36pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
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}
515
16fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
617 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
718 const target_info = std.zig.system.NativeTargetInfo.detect(target) catch unreachable;
819 const sdk = std.zig.system.darwin.getDarwinSDK(b.allocator, target_info.target) orelse
920 @panic("macOS SDK is required to run the test");
1021
11 const test_step = b.step("test", "Test the program");
12
1322 const exe = b.addExecutable(.{
1423 .name = "test",
1524 .optimize = optimize,
1625 });
17 b.default_step.dependOn(&exe.step);
1826 exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include" }) catch unreachable);
1927 exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include/c++/v1" }) catch unreachable);
2028 exe.addCSourceFile("test.cpp", &.{
test/link/macho/bugs/13457/build.zig+13-3
......@@ -1,10 +1,19 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4
35pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
5 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
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}
614
7 const test_step = b.step("test", "Test the program");
15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
817
918 const exe = b.addExecutable(.{
1019 .name = "test",
......@@ -16,5 +25,6 @@ pub fn build(b: *std.Build) void {
1625 const run = b.addRunArtifact(exe);
1726 run.skip_foreign_checks = true;
1827 run.expectStdOutEqual("");
28
1929 test_step.dependOn(&run.step);
2030}
test/link/macho/dead_strip/build.zig+8-5
......@@ -1,15 +1,17 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4
35pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
6 const optimize: std.builtin.OptimizeMode = .Debug;
57 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
68
79 const test_step = b.step("test", "Test the program");
8 test_step.dependOn(b.getInstallStep());
10 b.default_step = test_step;
911
1012 {
1113 // Without -dead_strip, we expect `iAmUnused` symbol present
12 const exe = createScenario(b, optimize, target);
14 const exe = createScenario(b, optimize, target, "no-gc");
1315
1416 const check = exe.checkObject(.macho);
1517 check.checkInSymtab();
......@@ -22,7 +24,7 @@ pub fn build(b: *std.Build) void {
2224
2325 {
2426 // With -dead_strip, no `iAmUnused` symbol should be present
25 const exe = createScenario(b, optimize, target);
27 const exe = createScenario(b, optimize, target, "yes-gc");
2628 exe.link_gc_sections = true;
2729
2830 const check = exe.checkObject(.macho);
......@@ -39,9 +41,10 @@ fn createScenario(
3941 b: *std.Build,
4042 optimize: std.builtin.OptimizeMode,
4143 target: std.zig.CrossTarget,
44 name: []const u8,
4245) *std.Build.CompileStep {
4346 const exe = b.addExecutable(.{
44 .name = "test",
47 .name = name,
4548 .optimize = optimize,
4649 .target = target,
4750 });
test/link/macho/dead_strip_dylibs/build.zig+21-9
......@@ -1,14 +1,22 @@
11const std = @import("std");
22
3pub const requires_macos_sdk = true;
4pub const requires_symlinks = true;
5
36pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
7 const test_step = b.step("test", "Test it");
8 b.default_step = test_step;
59
6 const test_step = b.step("test", "Test the program");
7 test_step.dependOn(b.getInstallStep());
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}
815
16fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
917 {
1018 // Without -dead_strip_dylibs we expect `-la` to include liba.dylib in the final executable
11 const exe = createScenario(b, optimize);
19 const exe = createScenario(b, optimize, "no-dead-strip");
1220
1321 const check = exe.checkObject(.macho);
1422 check.checkStart("cmd LOAD_DYLIB");
......@@ -25,18 +33,22 @@ pub fn build(b: *std.Build) void {
2533
2634 {
2735 // With -dead_strip_dylibs, we should include liba.dylib as it's unreachable
28 const exe = createScenario(b, optimize);
36 const exe = createScenario(b, optimize, "yes-dead-strip");
2937 exe.dead_strip_dylibs = true;
3038
31 const run_cmd = exe.run();
32 run_cmd.expected_term = .{ .Exited = @bitCast(u8, @as(i8, -2)) }; // should fail
39 const run_cmd = b.addRunArtifact(exe);
40 run_cmd.expectExitCode(@bitCast(u8, @as(i8, -2))); // should fail
3341 test_step.dependOn(&run_cmd.step);
3442 }
3543}
3644
37fn createScenario(b: *std.Build, optimize: std.builtin.OptimizeMode) *std.Build.CompileStep {
45fn createScenario(
46 b: *std.Build,
47 optimize: std.builtin.OptimizeMode,
48 name: []const u8,
49) *std.Build.CompileStep {
3850 const exe = b.addExecutable(.{
39 .name = "test",
51 .name = name,
4052 .optimize = optimize,
4153 });
4254 exe.addCSourceFile("main.c", &[0][]const u8{});
test/link/macho/dylib/build.zig+18-9
......@@ -1,11 +1,19 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4
35pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
5 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
6 const test_step = b.step("test", "Test it");
7 b.default_step = test_step;
68
7 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());
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: std.zig.CrossTarget = .{ .os_tag = .macos };
917
1018 const dylib = b.addSharedLibrary(.{
1119 .name = "a",
......@@ -15,7 +23,6 @@ pub fn build(b: *std.Build) void {
1523 });
1624 dylib.addCSourceFile("a.c", &.{});
1725 dylib.linkLibC();
18 dylib.install();
1926
2027 const check_dylib = dylib.checkObject(.macho);
2128 check_dylib.checkStart("cmd ID_DYLIB");
......@@ -33,9 +40,9 @@ pub fn build(b: *std.Build) void {
3340 });
3441 exe.addCSourceFile("main.c", &.{});
3542 exe.linkSystemLibrary("a");
43 exe.addLibraryPathDirectorySource(dylib.getOutputDirectorySource());
44 exe.addRPathDirectorySource(dylib.getOutputDirectorySource());
3645 exe.linkLibC();
37 exe.addLibraryPath(b.pathFromRoot("zig-out/lib/"));
38 exe.addRPath(b.pathFromRoot("zig-out/lib"));
3946
4047 const check_exe = exe.checkObject(.macho);
4148 check_exe.checkStart("cmd LOAD_DYLIB");
......@@ -45,10 +52,12 @@ pub fn build(b: *std.Build) void {
4552 check_exe.checkNext("compatibility version 10000");
4653
4754 check_exe.checkStart("cmd RPATH");
48 check_exe.checkNext(std.fmt.allocPrint(b.allocator, "path {s}", .{b.pathFromRoot("zig-out/lib")}) catch unreachable);
55 // TODO check this (perhaps with `checkNextFileSource(dylib.getOutputDirectorySource())`)
56 //check_exe.checkNext(std.fmt.allocPrint(b.allocator, "path {s}", .{
57 // b.pathFromRoot("zig-out/lib"),
58 //}) catch unreachable);
4959
5060 const run = check_exe.runAndCompare();
51 run.cwd = b.pathFromRoot(".");
5261 run.expectStdOutEqual("Hello world");
5362 test_step.dependOn(&run.step);
5463}
test/link/macho/empty/build.zig+12-4
......@@ -1,11 +1,19 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4
35pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
5 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
6 const test_step = b.step("test", "Test it");
7 b.default_step = test_step;
68
7 const test_step = b.step("test", "Test the program");
8 test_step.dependOn(b.getInstallStep());
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: std.zig.CrossTarget = .{ .os_tag = .macos };
917
1018 const exe = b.addExecutable(.{
1119 .name = "test",
test/link/macho/entry/build.zig+10-3
......@@ -1,11 +1,18 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4
35pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
6 const test_step = b.step("test", "Test it");
7 b.default_step = test_step;
58
6 const test_step = b.step("test", "Test");
7 test_step.dependOn(b.getInstallStep());
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}
814
15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
916 const exe = b.addExecutable(.{
1017 .name = "main",
1118 .optimize = optimize,
test/link/macho/headerpad/build.zig+11-3
......@@ -1,12 +1,20 @@
11const std = @import("std");
22const builtin = @import("builtin");
33
4pub const requires_symlinks = true;
5pub const requires_macos_sdk = true;
6
47pub fn build(b: *std.Build) void {
5 const optimize = b.standardOptimizeOption(.{});
8 const test_step = b.step("test", "Test it");
9 b.default_step = test_step;
610
7 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());
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}
916
17fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1018 {
1119 // Test -headerpad_max_install_names
1220 const exe = simpleExe(b, optimize);
test/link/macho/linksection/build.zig+12-4
......@@ -1,11 +1,19 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4
35pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
5 const target = std.zig.CrossTarget{ .os_tag = .macos };
6 const test_step = b.step("test", "Test it");
7 b.default_step = test_step;
68
7 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());
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 = std.zig.CrossTarget{ .os_tag = .macos };
917
1018 const obj = b.addObject(.{
1119 .name = "test",
test/link/macho/needed_framework/build.zig+11-3
......@@ -1,11 +1,19 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4pub const requires_macos_sdk = true;
5
36pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
7 const test_step = b.step("test", "Test it");
8 b.default_step = test_step;
59
6 const test_step = b.step("test", "Test the program");
7 test_step.dependOn(b.getInstallStep());
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}
815
16fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
917 // -dead_strip_dylibs
1018 // -needed_framework Cocoa
1119 const exe = b.addExecutable(.{
test/link/macho/needed_library/build.zig+14-7
......@@ -1,11 +1,19 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4
35pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
5 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
6 const test_step = b.step("test", "Test it");
7 b.default_step = test_step;
68
7 const test_step = b.step("test", "Test the program");
8 test_step.dependOn(b.getInstallStep());
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: std.zig.CrossTarget = .{ .os_tag = .macos };
917
1018 const dylib = b.addSharedLibrary(.{
1119 .name = "a",
......@@ -15,7 +23,6 @@ pub fn build(b: *std.Build) void {
1523 });
1624 dylib.addCSourceFile("a.c", &.{});
1725 dylib.linkLibC();
18 dylib.install();
1926
2027 // -dead_strip_dylibs
2128 // -needed-la
......@@ -27,8 +34,8 @@ pub fn build(b: *std.Build) void {
2734 exe.addCSourceFile("main.c", &[0][]const u8{});
2835 exe.linkLibC();
2936 exe.linkSystemLibraryNeeded("a");
30 exe.addLibraryPath(b.pathFromRoot("zig-out/lib"));
31 exe.addRPath(b.pathFromRoot("zig-out/lib"));
37 exe.addLibraryPathDirectorySource(dylib.getOutputDirectorySource());
38 exe.addRPathDirectorySource(dylib.getOutputDirectorySource());
3239 exe.dead_strip_dylibs = true;
3340
3441 const check = exe.checkObject(.macho);
test/link/macho/objc/build.zig+11-2
......@@ -1,10 +1,19 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4pub const requires_macos_sdk = true;
5
36pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
7 const test_step = b.step("test", "Test it");
8 b.default_step = test_step;
59
6 const test_step = b.step("test", "Test the program");
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}
715
16fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
817 const exe = b.addExecutable(.{
918 .name = "test",
1019 .optimize = optimize,
test/link/macho/objcpp/build.zig+11-2
......@@ -1,10 +1,19 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4pub const requires_macos_sdk = true;
5
36pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
7 const test_step = b.step("test", "Test it");
8 b.default_step = test_step;
59
6 const test_step = b.step("test", "Test the program");
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}
715
16fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
817 const exe = b.addExecutable(.{
918 .name = "test",
1019 .optimize = optimize,
test/link/macho/pagezero/build.zig+6-4
......@@ -1,11 +1,13 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4
35pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
5 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
6 const test_step = b.step("test", "Test it");
7 b.default_step = test_step;
68
7 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());
9 const optimize: std.builtin.OptimizeMode = .Debug;
10 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
911
1012 {
1113 const exe = b.addExecutable(.{
test/link/macho/search_strategy/build.zig+23-18
......@@ -1,35 +1,41 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4
35pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
5 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
6 const test_step = b.step("test", "Test it");
7 b.default_step = test_step;
68
7 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());
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: std.zig.CrossTarget = .{ .os_tag = .macos };
917
1018 {
1119 // -search_dylibs_first
12 const exe = createScenario(b, optimize, target);
20 const exe = createScenario(b, optimize, target, "search_dylibs_first");
1321 exe.search_strategy = .dylibs_first;
1422
1523 const check = exe.checkObject(.macho);
1624 check.checkStart("cmd LOAD_DYLIB");
17 check.checkNext("name @rpath/liba.dylib");
25 check.checkNext("name @rpath/libsearch_dylibs_first.dylib");
1826
1927 const run = check.runAndCompare();
20 run.cwd = b.pathFromRoot(".");
2128 run.expectStdOutEqual("Hello world");
2229 test_step.dependOn(&run.step);
2330 }
2431
2532 {
2633 // -search_paths_first
27 const exe = createScenario(b, optimize, target);
34 const exe = createScenario(b, optimize, target, "search_paths_first");
2835 exe.search_strategy = .paths_first;
2936
3037 const run = b.addRunArtifact(exe);
3138 run.skip_foreign_checks = true;
32 run.cwd = b.pathFromRoot(".");
3339 run.expectStdOutEqual("Hello world");
3440 test_step.dependOn(&run.step);
3541 }
......@@ -39,9 +45,10 @@ fn createScenario(
3945 b: *std.Build,
4046 optimize: std.builtin.OptimizeMode,
4147 target: std.zig.CrossTarget,
48 name: []const u8,
4249) *std.Build.CompileStep {
4350 const static = b.addStaticLibrary(.{
44 .name = "a",
51 .name = name,
4552 .optimize = optimize,
4653 .target = target,
4754 });
......@@ -50,10 +57,9 @@ fn createScenario(
5057 static.override_dest_dir = std.Build.InstallDir{
5158 .custom = "static",
5259 };
53 static.install();
5460
5561 const dylib = b.addSharedLibrary(.{
56 .name = "a",
62 .name = name,
5763 .version = .{ .major = 1, .minor = 0 },
5864 .optimize = optimize,
5965 .target = target,
......@@ -63,18 +69,17 @@ fn createScenario(
6369 dylib.override_dest_dir = std.Build.InstallDir{
6470 .custom = "dynamic",
6571 };
66 dylib.install();
6772
6873 const exe = b.addExecutable(.{
69 .name = "main",
74 .name = name,
7075 .optimize = optimize,
7176 .target = target,
7277 });
7378 exe.addCSourceFile("main.c", &.{});
74 exe.linkSystemLibraryName("a");
79 exe.linkSystemLibraryName(name);
7580 exe.linkLibC();
76 exe.addLibraryPath(b.pathFromRoot("zig-out/static"));
77 exe.addLibraryPath(b.pathFromRoot("zig-out/dynamic"));
78 exe.addRPath(b.pathFromRoot("zig-out/dynamic"));
81 exe.addLibraryPathDirectorySource(static.getOutputDirectorySource());
82 exe.addLibraryPathDirectorySource(dylib.getOutputDirectorySource());
83 exe.addRPathDirectorySource(dylib.getOutputDirectorySource());
7984 return exe;
8085}
test/link/macho/stack_size/build.zig+12-4
......@@ -1,11 +1,19 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4
35pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
5 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
6 const test_step = b.step("test", "Test it");
7 b.default_step = test_step;
68
7 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());
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: std.zig.CrossTarget = .{ .os_tag = .macos };
917
1018 const exe = b.addExecutable(.{
1119 .name = "main",
test/link/macho/strict_validation/build.zig+12-4
......@@ -1,12 +1,20 @@
11const std = @import("std");
22const builtin = @import("builtin");
33
4pub const requires_symlinks = true;
5
46pub fn build(b: *std.Build) void {
5 const optimize = b.standardOptimizeOption(.{});
6 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
7 const test_step = b.step("test", "Test it");
8 b.default_step = test_step;
79
8 const test_step = b.step("test", "Test");
9 test_step.dependOn(b.getInstallStep());
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: std.zig.CrossTarget = .{ .os_tag = .macos };
1018
1119 const exe = b.addExecutable(.{
1220 .name = "main",
test/link/macho/tls/build.zig+12-2
......@@ -1,7 +1,18 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4
35pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
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 {
516 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
617
718 const lib = b.addSharedLibrary(.{
......@@ -21,6 +32,5 @@ pub fn build(b: *std.Build) void {
2132 test_exe.linkLibrary(lib);
2233 test_exe.linkLibC();
2334
24 const test_step = b.step("test", "Test it");
2535 test_step.dependOn(&test_exe.step);
2636}
test/link/macho/unwind_info/build.zig+18-7
......@@ -1,14 +1,23 @@
11const std = @import("std");
22const builtin = @import("builtin");
33
4pub const requires_symlinks = true;
5
46pub fn build(b: *std.Build) void {
5 const optimize = b.standardOptimizeOption(.{});
6 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
7 const test_step = b.step("test", "Test it");
8 b.default_step = test_step;
79
8 const test_step = b.step("test", "Test the program");
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: std.zig.CrossTarget = .{ .os_tag = .macos };
918
10 testUnwindInfo(b, test_step, optimize, target, false);
11 testUnwindInfo(b, test_step, optimize, target, true);
19 testUnwindInfo(b, test_step, optimize, target, false, "no-dead-strip");
20 testUnwindInfo(b, test_step, optimize, target, true, "yes-dead-strip");
1221}
1322
1423fn testUnwindInfo(
......@@ -17,8 +26,9 @@ fn testUnwindInfo(
1726 optimize: std.builtin.OptimizeMode,
1827 target: std.zig.CrossTarget,
1928 dead_strip: bool,
29 name: []const u8,
2030) void {
21 const exe = createScenario(b, optimize, target);
31 const exe = createScenario(b, optimize, target, name);
2232 exe.link_gc_sections = dead_strip;
2333
2434 const check = exe.checkObject(.macho);
......@@ -54,9 +64,10 @@ fn createScenario(
5464 b: *std.Build,
5565 optimize: std.builtin.OptimizeMode,
5666 target: std.zig.CrossTarget,
67 name: []const u8,
5768) *std.Build.CompileStep {
5869 const exe = b.addExecutable(.{
59 .name = "test",
70 .name = name,
6071 .optimize = optimize,
6172 .target = target,
6273 });
test/link/macho/uuid/build.zig+5-2
......@@ -3,11 +3,14 @@ const CompileStep = std.Build.CompileStep;
33const FileSource = std.Build.FileSource;
44const Step = std.Build.Step;
55
6pub const requires_symlinks = true;
7
68pub fn build(b: *std.Build) void {
79 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());
10 b.default_step = test_step;
911
10 // We force cross-compilation to ensure we always pick a generic CPU with constant set of CPU features.
12 // We force cross-compilation to ensure we always pick a generic CPU with
13 // constant set of CPU features.
1114 const aarch64_macos = std.zig.CrossTarget{
1215 .cpu_arch = .aarch64,
1316 .os_tag = .macos,
test/link/macho/weak_framework/build.zig+11-3
......@@ -1,11 +1,19 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4pub const requires_macos_sdk = true;
5
36pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
7 const test_step = b.step("test", "Test it");
8 b.default_step = test_step;
59
6 const test_step = b.step("test", "Test the program");
7 test_step.dependOn(b.getInstallStep());
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}
815
16fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
917 const exe = b.addExecutable(.{
1018 .name = "test",
1119 .optimize = optimize,
test/link/macho/weak_library/build.zig+14-6
......@@ -1,11 +1,19 @@
11const std = @import("std");
22
3pub const requires_symlinks = true;
4
35pub fn build(b: *std.Build) void {
4 const optimize = b.standardOptimizeOption(.{});
5 const target: std.zig.CrossTarget = .{ .os_tag = .macos };
6 const test_step = b.step("test", "Test it");
7 b.default_step = test_step;
68
7 const test_step = b.step("test", "Test the program");
8 test_step.dependOn(b.getInstallStep());
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: std.zig.CrossTarget = .{ .os_tag = .macos };
917
1018 const dylib = b.addSharedLibrary(.{
1119 .name = "a",
......@@ -25,8 +33,8 @@ pub fn build(b: *std.Build) void {
2533 exe.addCSourceFile("main.c", &[0][]const u8{});
2634 exe.linkLibC();
2735 exe.linkSystemLibraryWeak("a");
28 exe.addLibraryPath(b.pathFromRoot("zig-out/lib"));
29 exe.addRPath(b.pathFromRoot("zig-out/lib"));
36 exe.addLibraryPathDirectorySource(dylib.getOutputDirectorySource());
37 exe.addRPathDirectorySource(dylib.getOutputDirectorySource());
3038
3139 const check = exe.checkObject(.macho);
3240 check.checkStart("cmd LOAD_WEAK_DYLIB");
test/tests.zig+10-8
......@@ -590,23 +590,25 @@ pub fn addStandaloneTests(
590590
591591pub fn addLinkTests(
592592 b: *std.Build,
593 test_filter: ?[]const u8,
594 optimize_modes: []const OptimizeMode,
595593 enable_macos_sdk: bool,
596594 omit_stage2: bool,
597595 enable_symlinks_windows: bool,
598596) *Step {
599 _ = test_filter;
600 _ = optimize_modes;
601 _ = enable_macos_sdk;
602 _ = enable_symlinks_windows;
603
604597 const step = b.step("test-link", "Run the linker tests");
598 const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows;
605599
606600 inline for (link.cases) |link_test| {
607601 const requires_stage2 = @hasDecl(link_test.import, "requires_stage2") and
608602 link_test.import.requires_stage2;
609 if (!requires_stage2 or !omit_stage2) {
603 const requires_symlinks = @hasDecl(link_test.import, "requires_symlinks") and
604 link_test.import.requires_symlinks;
605 const requires_macos_sdk = @hasDecl(link_test.import, "requires_macos_sdk") and
606 link_test.import.requires_macos_sdk;
607 const bad =
608 (requires_stage2 and omit_stage2) or
609 (requires_symlinks and omit_symlinks) or
610 (requires_macos_sdk and !enable_macos_sdk);
611 if (!bad) {
610612 const dep = b.anonymousDependency(link_test.build_root, link_test.import, .{});
611613 const dep_step = dep.builder.default_step;
612614 assert(mem.startsWith(u8, dep.builder.dep_prefix, "test."));