authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-06-19 11:33:06+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-06-19 11:33:06+02:00
logc2554cf0f17668659d0b898fcb43b3efb8694d3a
tree05dde71b2eed077dea7957f8af680a79cd86e8a2
parent10aaf2983d5db65082c4b348269150eddc12e67e

link-test: remove now obsolete UUID test for MachO


3 files changed, 0 insertions(+), 155 deletions(-)

test/link.zig-9
...@@ -164,15 +164,6 @@ pub const cases = [_]Case{...@@ -164,15 +164,6 @@ pub const cases = [_]Case{
164 .build_root = "test/link/macho/unwind_info",164 .build_root = "test/link/macho/unwind_info",
165 .import = @import("link/macho/unwind_info/build.zig"),165 .import = @import("link/macho/unwind_info/build.zig"),
166 },166 },
167 // TODO: re-enable this test. It currently has some incompatibilities with
168 // the new build system API. In particular, it depends on installing the build
169 // artifacts, which should be unnecessary, and it has a custom build step that
170 // prints directly to stderr instead of failing the step with an error message.
171 //.{
172 // .build_root = "test/link/macho/uuid",
173 // .import = @import("link/macho/uuid/build.zig"),
174 //},
175
176 .{167 .{
177 .build_root = "test/link/macho/weak_library",168 .build_root = "test/link/macho/weak_library",
178 .import = @import("link/macho/weak_library/build.zig"),169 .import = @import("link/macho/weak_library/build.zig"),
test/link/macho/uuid/build.zig deleted-144
...@@ -1,144 +0,0 @@
1const std = @import("std");
2const FileSource = std.Build.FileSource;
3const Step = std.Build.Step;
4
5pub const requires_symlinks = true;
6
7pub fn build(b: *std.Build) void {
8 const test_step = b.step("test", "Test");
9 b.default_step = test_step;
10
11 // We force cross-compilation to ensure we always pick a generic CPU with
12 // constant set of CPU features.
13 const aarch64_macos = std.zig.CrossTarget{
14 .cpu_arch = .aarch64,
15 .os_tag = .macos,
16 };
17
18 testUuid(b, test_step, .ReleaseSafe, aarch64_macos);
19 testUuid(b, test_step, .ReleaseFast, aarch64_macos);
20 testUuid(b, test_step, .ReleaseSmall, aarch64_macos);
21
22 const x86_64_macos = std.zig.CrossTarget{
23 .cpu_arch = .x86_64,
24 .os_tag = .macos,
25 };
26
27 testUuid(b, test_step, .ReleaseSafe, x86_64_macos);
28 testUuid(b, test_step, .ReleaseFast, x86_64_macos);
29 testUuid(b, test_step, .ReleaseSmall, x86_64_macos);
30}
31
32fn testUuid(
33 b: *std.Build,
34 test_step: *std.Build.Step,
35 optimize: std.builtin.OptimizeMode,
36 target: std.zig.CrossTarget,
37) void {
38 // The calculated UUID value is independent of debug info and so it should
39 // stay the same across builds.
40 {
41 const dylib = simpleDylib(b, optimize, target);
42 const install_step = b.addInstallArtifact(dylib);
43 install_step.dest_sub_path = "test1.dylib";
44 install_step.step.dependOn(&dylib.step);
45 }
46 {
47 const dylib = simpleDylib(b, optimize, target);
48 dylib.strip = true;
49 const install_step = b.addInstallArtifact(dylib);
50 install_step.dest_sub_path = "test2.dylib";
51 install_step.step.dependOn(&dylib.step);
52 }
53
54 const cmp_step = CompareUuid.create(b, "test1.dylib", "test2.dylib");
55 test_step.dependOn(&cmp_step.step);
56}
57
58fn simpleDylib(
59 b: *std.Build,
60 optimize: std.builtin.OptimizeMode,
61 target: std.zig.CrossTarget,
62) *std.Build.Step.Compile {
63 const dylib = b.addSharedLibrary(.{
64 .name = "test",
65 .version = .{ .major = 1, .minor = 0, .patch = 0 },
66 .optimize = optimize,
67 .target = target,
68 });
69 dylib.addCSourceFile("test.c", &.{});
70 dylib.linkLibC();
71 return dylib;
72}
73
74const CompareUuid = struct {
75 pub const base_id = .custom;
76
77 step: Step,
78 lhs: []const u8,
79 rhs: []const u8,
80
81 pub fn create(owner: *std.Build, lhs: []const u8, rhs: []const u8) *CompareUuid {
82 const self = owner.allocator.create(CompareUuid) catch @panic("OOM");
83 self.* = CompareUuid{
84 .step = Step.init(.{
85 .id = base_id,
86 .name = owner.fmt("compare uuid: {s} and {s}", .{
87 lhs,
88 rhs,
89 }),
90 .owner = owner,
91 .makeFn = make,
92 }),
93 .lhs = lhs,
94 .rhs = rhs,
95 };
96 return self;
97 }
98
99 fn make(step: *Step, prog_node: *std.Progress.Node) anyerror!void {
100 _ = prog_node;
101 const b = step.owner;
102 const self = @fieldParentPtr(CompareUuid, "step", step);
103 const gpa = b.allocator;
104
105 var lhs_uuid: [16]u8 = undefined;
106 const lhs_path = b.getInstallPath(.lib, self.lhs);
107 try parseUuid(gpa, lhs_path, &lhs_uuid);
108
109 var rhs_uuid: [16]u8 = undefined;
110 const rhs_path = b.getInstallPath(.lib, self.rhs);
111 try parseUuid(gpa, rhs_path, &rhs_uuid);
112
113 try std.testing.expectEqualStrings(&lhs_uuid, &rhs_uuid);
114 }
115
116 fn parseUuid(gpa: std.mem.Allocator, path: []const u8, uuid: *[16]u8) anyerror!void {
117 const max_bytes: usize = 20 * 1024 * 1024;
118 const data = try std.fs.cwd().readFileAllocOptions(
119 gpa,
120 path,
121 max_bytes,
122 null,
123 @alignOf(u64),
124 null,
125 );
126 var stream = std.io.fixedBufferStream(data);
127 const reader = stream.reader();
128
129 const hdr = try reader.readStruct(std.macho.mach_header_64);
130 if (hdr.magic != std.macho.MH_MAGIC_64) {
131 return error.InvalidMagicNumber;
132 }
133
134 var it = std.macho.LoadCommandIterator{
135 .ncmds = hdr.ncmds,
136 .buffer = data[@sizeOf(std.macho.mach_header_64)..][0..hdr.sizeofcmds],
137 };
138 const cmd = while (it.next()) |cmd| switch (cmd.cmd()) {
139 .UUID => break cmd.cast(std.macho.uuid_command).?,
140 else => {},
141 } else return error.UuidLoadCommandNotFound;
142 std.mem.copy(u8, uuid, &cmd.uuid);
143 }
144};
test/link/macho/uuid/test.c deleted-2
...@@ -1,2 +0,0 @@
1void test() {}
2