From c2554cf0f17668659d0b898fcb43b3efb8694d3a Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 19 Jun 2023 11:33:06 +0200 Subject: [PATCH] link-test: remove now obsolete UUID test for MachO --- test/link.zig | 9 --- test/link/macho/uuid/build.zig | 144 --------------------------------- test/link/macho/uuid/test.c | 2 - 3 files changed, 155 deletions(-) delete mode 100644 test/link/macho/uuid/build.zig delete mode 100644 test/link/macho/uuid/test.c diff --git a/test/link.zig b/test/link.zig index b8857a1e5e..6f8134e4f4 100644 --- a/test/link.zig +++ b/test/link.zig @@ -164,15 +164,6 @@ pub const cases = [_]Case{ .build_root = "test/link/macho/unwind_info", .import = @import("link/macho/unwind_info/build.zig"), }, - // TODO: re-enable this test. It currently has some incompatibilities with - // the new build system API. In particular, it depends on installing the build - // artifacts, which should be unnecessary, and it has a custom build step that - // prints directly to stderr instead of failing the step with an error message. - //.{ - // .build_root = "test/link/macho/uuid", - // .import = @import("link/macho/uuid/build.zig"), - //}, - .{ .build_root = "test/link/macho/weak_library", .import = @import("link/macho/weak_library/build.zig"), diff --git a/test/link/macho/uuid/build.zig b/test/link/macho/uuid/build.zig deleted file mode 100644 index f2ef6b33ec..0000000000 --- a/test/link/macho/uuid/build.zig +++ /dev/null @@ -1,144 +0,0 @@ -const std = @import("std"); -const FileSource = std.Build.FileSource; -const Step = std.Build.Step; - -pub const requires_symlinks = true; - -pub fn build(b: *std.Build) void { - const test_step = b.step("test", "Test"); - b.default_step = test_step; - - // We force cross-compilation to ensure we always pick a generic CPU with - // constant set of CPU features. - const aarch64_macos = std.zig.CrossTarget{ - .cpu_arch = .aarch64, - .os_tag = .macos, - }; - - testUuid(b, test_step, .ReleaseSafe, aarch64_macos); - testUuid(b, test_step, .ReleaseFast, aarch64_macos); - testUuid(b, test_step, .ReleaseSmall, aarch64_macos); - - const x86_64_macos = std.zig.CrossTarget{ - .cpu_arch = .x86_64, - .os_tag = .macos, - }; - - testUuid(b, test_step, .ReleaseSafe, x86_64_macos); - testUuid(b, test_step, .ReleaseFast, x86_64_macos); - testUuid(b, test_step, .ReleaseSmall, x86_64_macos); -} - -fn testUuid( - b: *std.Build, - test_step: *std.Build.Step, - optimize: std.builtin.OptimizeMode, - target: std.zig.CrossTarget, -) void { - // The calculated UUID value is independent of debug info and so it should - // stay the same across builds. - { - const dylib = simpleDylib(b, optimize, target); - const install_step = b.addInstallArtifact(dylib); - install_step.dest_sub_path = "test1.dylib"; - install_step.step.dependOn(&dylib.step); - } - { - const dylib = simpleDylib(b, optimize, target); - dylib.strip = true; - const install_step = b.addInstallArtifact(dylib); - install_step.dest_sub_path = "test2.dylib"; - install_step.step.dependOn(&dylib.step); - } - - const cmp_step = CompareUuid.create(b, "test1.dylib", "test2.dylib"); - test_step.dependOn(&cmp_step.step); -} - -fn simpleDylib( - b: *std.Build, - optimize: std.builtin.OptimizeMode, - target: std.zig.CrossTarget, -) *std.Build.Step.Compile { - const dylib = b.addSharedLibrary(.{ - .name = "test", - .version = .{ .major = 1, .minor = 0, .patch = 0 }, - .optimize = optimize, - .target = target, - }); - dylib.addCSourceFile("test.c", &.{}); - dylib.linkLibC(); - return dylib; -} - -const CompareUuid = struct { - pub const base_id = .custom; - - step: Step, - lhs: []const u8, - rhs: []const u8, - - pub fn create(owner: *std.Build, lhs: []const u8, rhs: []const u8) *CompareUuid { - const self = owner.allocator.create(CompareUuid) catch @panic("OOM"); - self.* = CompareUuid{ - .step = Step.init(.{ - .id = base_id, - .name = owner.fmt("compare uuid: {s} and {s}", .{ - lhs, - rhs, - }), - .owner = owner, - .makeFn = make, - }), - .lhs = lhs, - .rhs = rhs, - }; - return self; - } - - fn make(step: *Step, prog_node: *std.Progress.Node) anyerror!void { - _ = prog_node; - const b = step.owner; - const self = @fieldParentPtr(CompareUuid, "step", step); - const gpa = b.allocator; - - var lhs_uuid: [16]u8 = undefined; - const lhs_path = b.getInstallPath(.lib, self.lhs); - try parseUuid(gpa, lhs_path, &lhs_uuid); - - var rhs_uuid: [16]u8 = undefined; - const rhs_path = b.getInstallPath(.lib, self.rhs); - try parseUuid(gpa, rhs_path, &rhs_uuid); - - try std.testing.expectEqualStrings(&lhs_uuid, &rhs_uuid); - } - - fn parseUuid(gpa: std.mem.Allocator, path: []const u8, uuid: *[16]u8) anyerror!void { - const max_bytes: usize = 20 * 1024 * 1024; - const data = try std.fs.cwd().readFileAllocOptions( - gpa, - path, - max_bytes, - null, - @alignOf(u64), - null, - ); - var stream = std.io.fixedBufferStream(data); - const reader = stream.reader(); - - const hdr = try reader.readStruct(std.macho.mach_header_64); - if (hdr.magic != std.macho.MH_MAGIC_64) { - return error.InvalidMagicNumber; - } - - var it = std.macho.LoadCommandIterator{ - .ncmds = hdr.ncmds, - .buffer = data[@sizeOf(std.macho.mach_header_64)..][0..hdr.sizeofcmds], - }; - const cmd = while (it.next()) |cmd| switch (cmd.cmd()) { - .UUID => break cmd.cast(std.macho.uuid_command).?, - else => {}, - } else return error.UuidLoadCommandNotFound; - std.mem.copy(u8, uuid, &cmd.uuid); - } -}; diff --git a/test/link/macho/uuid/test.c b/test/link/macho/uuid/test.c deleted file mode 100644 index 6f23a1a926..0000000000 --- a/test/link/macho/uuid/test.c +++ /dev/null @@ -1,2 +0,0 @@ -void test() {} -