authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-15 09:03:36+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-24 12:34:40+01:00
log82a044f4f7997dbbb43d1aa7f8ba956328380371
treec8675434901f94d740a04e7381e2ec897bc129fc
parenta454ba79083128e3172d2ca14fced9ec4a3763b1

test/link/macho: upgrade empty object test


8 files changed, 21 insertions(+), 122 deletions(-)

test/link.zig-4
...@@ -107,10 +107,6 @@ pub const cases = [_]Case{...@@ -107,10 +107,6 @@ pub const cases = [_]Case{
107 .build_root = "test/link/macho/bugs/16628",107 .build_root = "test/link/macho/bugs/16628",
108 .import = @import("link/macho/bugs/16628/build.zig"),108 .import = @import("link/macho/bugs/16628/build.zig"),
109 },109 },
110 .{
111 .build_root = "test/link/macho/empty",
112 .import = @import("link/macho/empty/build.zig"),
113 },
114 .{110 .{
115 .build_root = "test/link/macho/entry",111 .build_root = "test/link/macho/entry",
116 .import = @import("link/macho/entry/build.zig"),112 .import = @import("link/macho/entry/build.zig"),
test/link/macho.zig+21
...@@ -17,6 +17,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {...@@ -17,6 +17,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
17 });17 });
1818
19 macho_step.dependOn(testDeadStrip(b, .{ .target = default_target }));19 macho_step.dependOn(testDeadStrip(b, .{ .target = default_target }));
20 macho_step.dependOn(testEmptyObject(b, .{ .target = default_target }));
20 macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target }));21 macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target }));
21 macho_step.dependOn(testHeaderWeakFlags(b, .{ .target = default_target }));22 macho_step.dependOn(testHeaderWeakFlags(b, .{ .target = default_target }));
22 macho_step.dependOn(testHelloC(b, .{ .target = default_target }));23 macho_step.dependOn(testHelloC(b, .{ .target = default_target }));
...@@ -220,6 +221,26 @@ fn testDylib(b: *Build, opts: Options) *Step {...@@ -220,6 +221,26 @@ fn testDylib(b: *Build, opts: Options) *Step {
220 return test_step;221 return test_step;
221}222}
222223
224fn testEmptyObject(b: *Build, opts: Options) *Step {
225 const test_step = addTestStep(b, "macho-empty-object", opts);
226
227 const empty = addObject(b, opts, .{ .name = "empty", .c_source_bytes = "" });
228
229 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
230 \\#include <stdio.h>
231 \\int main() {
232 \\ printf("Hello world!");
233 \\}
234 });
235 exe.addObject(empty);
236
237 const run = addRunArtifact(exe);
238 run.expectStdOutEqual("Hello world!");
239 test_step.dependOn(&run.step);
240
241 return test_step;
242}
243
223fn testEntryPointDylib(b: *Build, opts: Options) *Step {244fn testEntryPointDylib(b: *Build, opts: Options) *Step {
224 const test_step = addTestStep(b, "macho-entry-point-dylib", opts);245 const test_step = addTestStep(b, "macho-entry-point-dylib", opts);
225246
test/link/macho/dylib/a.c deleted-7
...@@ -1,7 +0,0 @@
1#include <stdio.h>
2
3char world[] = "world";
4
5char* hello() {
6 return "Hello";
7}
test/link/macho/dylib/build.zig deleted-65
...@@ -1,65 +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 dylib = b.addSharedLibrary(.{
19 .name = "a",
20 .version = .{ .major = 1, .minor = 0, .patch = 0 },
21 .optimize = optimize,
22 .target = target,
23 });
24 dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
25 dylib.linkLibC();
26
27 const check_dylib = dylib.checkObject();
28 check_dylib.checkInHeaders();
29 check_dylib.checkExact("cmd ID_DYLIB");
30 check_dylib.checkExact("name @rpath/liba.dylib");
31 check_dylib.checkExact("timestamp 2");
32 check_dylib.checkExact("current version 10000");
33 check_dylib.checkExact("compatibility version 10000");
34
35 test_step.dependOn(&check_dylib.step);
36
37 const exe = b.addExecutable(.{
38 .name = "main",
39 .optimize = optimize,
40 .target = target,
41 });
42 exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
43 exe.linkSystemLibrary("a");
44 exe.addLibraryPath(dylib.getEmittedBinDirectory());
45 exe.addRPath(dylib.getEmittedBinDirectory());
46 exe.linkLibC();
47
48 const check_exe = exe.checkObject();
49 check_exe.checkInHeaders();
50 check_exe.checkExact("cmd LOAD_DYLIB");
51 check_exe.checkExact("name @rpath/liba.dylib");
52 check_exe.checkExact("timestamp 2");
53 check_exe.checkExact("current version 10000");
54 check_exe.checkExact("compatibility version 10000");
55
56 check_exe.checkInHeaders();
57 check_exe.checkExact("cmd RPATH");
58 check_exe.checkExactPath("path", dylib.getEmittedBinDirectory());
59 test_step.dependOn(&check_exe.step);
60
61 const run = b.addRunArtifact(exe);
62 run.skip_foreign_checks = true;
63 run.expectStdOutEqual("Hello world");
64 test_step.dependOn(&run.step);
65}
test/link/macho/dylib/main.c deleted-9
...@@ -1,9 +0,0 @@
1#include <stdio.h>
2
3char* hello();
4extern char world[];
5
6int main(int argc, char* argv[]) {
7 printf("%s %s", hello(), world);
8 return 0;
9}
test/link/macho/empty/build.zig deleted-31
...@@ -1,31 +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 .optimize = optimize,
21 .target = target,
22 });
23 exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
24 exe.addCSourceFile(.{ .file = .{ .path = "empty.c" }, .flags = &[0][]const u8{} });
25 exe.linkLibC();
26
27 const run_cmd = b.addRunArtifact(exe);
28 run_cmd.skip_foreign_checks = true;
29 run_cmd.expectStdOutEqual("Hello!\n");
30 test_step.dependOn(&run_cmd.step);
31}
test/link/macho/empty/empty.c deleted
test/link/macho/empty/main.c deleted-6
...@@ -1,6 +0,0 @@
1#include <stdio.h>
2
3int main(int argc, char* argv[]) {
4 printf("Hello!\n");
5 return 0;
6}