diff --git a/lib/std/build/CheckObjectStep.zig b/lib/std/build/CheckObjectStep.zig index 7bebea54a0..41a275c38f 100644 --- a/lib/std/build/CheckObjectStep.zig +++ b/lib/std/build/CheckObjectStep.zig @@ -571,6 +571,12 @@ const MachODumper = struct { }); }, + .UUID => { + const uuid = lc.cast(macho.uuid_command).?; + try writer.writeByte('\n'); + try writer.print("uuid {x}", .{std.fmt.fmtSliceHexLower(&uuid.uuid)}); + }, + else => {}, } } diff --git a/test/link.zig b/test/link.zig index 7eec02e53a..5620ac95a0 100644 --- a/test/link.zig +++ b/test/link.zig @@ -170,6 +170,11 @@ fn addMachOCases(cases: *tests.StandaloneContext) void { .requires_symlinks = true, }); + cases.addBuildFile("test/link/macho/uuid/build.zig", .{ + .build_modes = false, + .requires_symlinks = true, + }); + cases.addBuildFile("test/link/macho/weak_library/build.zig", .{ .build_modes = true, .requires_symlinks = true, diff --git a/test/link/macho/uuid/build.zig b/test/link/macho/uuid/build.zig new file mode 100644 index 0000000000..620af04d04 --- /dev/null +++ b/test/link/macho/uuid/build.zig @@ -0,0 +1,52 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const Builder = std.build.Builder; +const LibExeObjectStep = std.build.LibExeObjStep; + +pub fn build(b: *Builder) void { + const test_step = b.step("test", "Test"); + test_step.dependOn(b.getInstallStep()); + + switch (builtin.cpu.arch) { + .aarch64 => { + testUuid(b, test_step, .ReleaseSafe, "eb1203019e453d808d4f1e71053af9af"); + testUuid(b, test_step, .ReleaseFast, "eb1203019e453d808d4f1e71053af9af"); + testUuid(b, test_step, .ReleaseSmall, "eb1203019e453d808d4f1e71053af9af"); + }, + .x86_64 => { + testUuid(b, test_step, .ReleaseSafe, "b3598e7c42dc38b0bd2975ead6e4ae85"); + testUuid(b, test_step, .ReleaseFast, "b3598e7c42dc38b0bd2975ead6e4ae85"); + testUuid(b, test_step, .ReleaseSmall, "1064b25eef4e3e6391866188b3dd7156"); + }, + else => unreachable, + } +} + +fn testUuid(b: *Builder, test_step: *std.build.Step, mode: std.builtin.Mode, comptime exp: []const u8) void { + // The calculated UUID value is independent of debug info and so it should + // stay the same across builds. + { + const dylib = simpleDylib(b, mode); + const check_dylib = dylib.checkObject(.macho); + check_dylib.checkStart("cmd UUID"); + check_dylib.checkNext("uuid " ++ exp); + test_step.dependOn(&check_dylib.step); + } + { + const dylib = simpleDylib(b, mode); + dylib.strip = true; + const check_dylib = dylib.checkObject(.macho); + check_dylib.checkStart("cmd UUID"); + check_dylib.checkNext("uuid " ++ exp); + test_step.dependOn(&check_dylib.step); + } +} + +fn simpleDylib(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep { + const dylib = b.addSharedLibrary("test", null, b.version(1, 0, 0)); + dylib.setBuildMode(mode); + dylib.setTarget(.{ .os_tag = .macos }); + dylib.addCSourceFile("test.c", &.{}); + dylib.linkLibC(); + return dylib; +} diff --git a/test/link/macho/uuid/test.c b/test/link/macho/uuid/test.c new file mode 100644 index 0000000000..6f23a1a926 --- /dev/null +++ b/test/link/macho/uuid/test.c @@ -0,0 +1,2 @@ +void test() {} +