authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-16 18:31:48+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-12-16 18:31:48+01:00
log9ad24a4aee839437a10d1038bb2f99a2abdbf1c2
treef3c50feb50a43d0cd8dde17c9931464578b1b8ed
parentf7266e03a8a9dda93b7118ea10c8f97adf21b3b0

macho: add uuid link test


4 files changed, 65 insertions(+), 0 deletions(-)

lib/std/build/CheckObjectStep.zig+6
...@@ -571,6 +571,12 @@ const MachODumper = struct {...@@ -571,6 +571,12 @@ const MachODumper = struct {
571 });571 });
572 },572 },
573573
574 .UUID => {
575 const uuid = lc.cast(macho.uuid_command).?;
576 try writer.writeByte('\n');
577 try writer.print("uuid {x}", .{std.fmt.fmtSliceHexLower(&uuid.uuid)});
578 },
579
574 else => {},580 else => {},
575 }581 }
576 }582 }
test/link.zig+5
...@@ -170,6 +170,11 @@ fn addMachOCases(cases: *tests.StandaloneContext) void {...@@ -170,6 +170,11 @@ fn addMachOCases(cases: *tests.StandaloneContext) void {
170 .requires_symlinks = true,170 .requires_symlinks = true,
171 });171 });
172172
173 cases.addBuildFile("test/link/macho/uuid/build.zig", .{
174 .build_modes = false,
175 .requires_symlinks = true,
176 });
177
173 cases.addBuildFile("test/link/macho/weak_library/build.zig", .{178 cases.addBuildFile("test/link/macho/weak_library/build.zig", .{
174 .build_modes = true,179 .build_modes = true,
175 .requires_symlinks = true,180 .requires_symlinks = true,
test/link/macho/uuid/build.zig created+52
...@@ -0,0 +1,52 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const Builder = std.build.Builder;
4const LibExeObjectStep = std.build.LibExeObjStep;
5
6pub fn build(b: *Builder) void {
7 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());
9
10 switch (builtin.cpu.arch) {
11 .aarch64 => {
12 testUuid(b, test_step, .ReleaseSafe, "eb1203019e453d808d4f1e71053af9af");
13 testUuid(b, test_step, .ReleaseFast, "eb1203019e453d808d4f1e71053af9af");
14 testUuid(b, test_step, .ReleaseSmall, "eb1203019e453d808d4f1e71053af9af");
15 },
16 .x86_64 => {
17 testUuid(b, test_step, .ReleaseSafe, "b3598e7c42dc38b0bd2975ead6e4ae85");
18 testUuid(b, test_step, .ReleaseFast, "b3598e7c42dc38b0bd2975ead6e4ae85");
19 testUuid(b, test_step, .ReleaseSmall, "1064b25eef4e3e6391866188b3dd7156");
20 },
21 else => unreachable,
22 }
23}
24
25fn testUuid(b: *Builder, test_step: *std.build.Step, mode: std.builtin.Mode, comptime exp: []const u8) void {
26 // The calculated UUID value is independent of debug info and so it should
27 // stay the same across builds.
28 {
29 const dylib = simpleDylib(b, mode);
30 const check_dylib = dylib.checkObject(.macho);
31 check_dylib.checkStart("cmd UUID");
32 check_dylib.checkNext("uuid " ++ exp);
33 test_step.dependOn(&check_dylib.step);
34 }
35 {
36 const dylib = simpleDylib(b, mode);
37 dylib.strip = true;
38 const check_dylib = dylib.checkObject(.macho);
39 check_dylib.checkStart("cmd UUID");
40 check_dylib.checkNext("uuid " ++ exp);
41 test_step.dependOn(&check_dylib.step);
42 }
43}
44
45fn simpleDylib(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {
46 const dylib = b.addSharedLibrary("test", null, b.version(1, 0, 0));
47 dylib.setBuildMode(mode);
48 dylib.setTarget(.{ .os_tag = .macos });
49 dylib.addCSourceFile("test.c", &.{});
50 dylib.linkLibC();
51 return dylib;
52}
test/link/macho/uuid/test.c created+2
...@@ -0,0 +1,2 @@
1void test() {}
2