authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-15 12:05:26+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-24 12:34:40+01:00
log2b3ac3e82f4207981469739b4ecd9fa0c3ac3308
tree92d69521c967826a29b78d0a1302eb0eeff22f99
parenta3f68c6fa23f893597b7708e0c00e81f57cb35c1

test/link/macho: upgrade tbdv3 test


5 files changed, 39 insertions(+), 71 deletions(-)

test/link.zig-4
......@@ -115,8 +115,4 @@ pub const cases = [_]Case{
115115 .build_root = "test/link/macho/objcpp",
116116 .import = @import("link/macho/objcpp/build.zig"),
117117 },
118 .{
119 .build_root = "test/link/macho/tbdv3",
120 .import = @import("link/macho/tbdv3/build.zig"),
121 },
122118};
test/link/macho.zig+39
......@@ -50,6 +50,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
5050 macho_step.dependOn(testDylib(b, .{ .target = default_target }));
5151 macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target }));
5252 macho_step.dependOn(testSearchStrategy(b, .{ .target = default_target }));
53 macho_step.dependOn(testTbdv3(b, .{ .target = default_target }));
5354 macho_step.dependOn(testTls(b, .{ .target = default_target }));
5455 macho_step.dependOn(testTwoLevelNamespace(b, .{ .target = default_target }));
5556 macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target }));
......@@ -1285,6 +1286,44 @@ fn testStackSize(b: *Build, opts: Options) *Step {
12851286 return test_step;
12861287}
12871288
1289fn testTbdv3(b: *Build, opts: Options) *Step {
1290 const test_step = addTestStep(b, "macho-tbdv3", opts);
1291
1292 const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = "int getFoo() { return 42; }" });
1293
1294 const tbd = tbd: {
1295 const wf = WriteFile.create(b);
1296 break :tbd wf.add("liba.tbd",
1297 \\--- !tapi-tbd-v3
1298 \\archs: [ arm64, x86_64 ]
1299 \\uuids: [ 'arm64: DEADBEEF', 'x86_64: BEEFDEAD' ]
1300 \\platform: macos
1301 \\install-name: @rpath/liba.dylib
1302 \\current-version: 0
1303 \\exports:
1304 \\ - archs: [ arm64, x86_64 ]
1305 \\ symbols: [ _getFoo ]
1306 );
1307 };
1308
1309 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
1310 \\#include <stdio.h>
1311 \\int getFoo();
1312 \\int main() {
1313 \\ return getFoo() - 42;
1314 \\}
1315 });
1316 exe.root_module.linkSystemLibrary("a", .{});
1317 exe.root_module.addLibraryPath(tbd.dirname());
1318 exe.root_module.addRPath(dylib.getEmittedBinDirectory());
1319
1320 const run = addRunArtifact(exe);
1321 run.expectExitCode(0);
1322 test_step.dependOn(&run.step);
1323
1324 return test_step;
1325}
1326
12881327fn testTentative(b: *Build, opts: Options) *Step {
12891328 const test_step = addTestStep(b, "macho-tentative", opts);
12901329
test/link/macho/tbdv3/a.c deleted-3
......@@ -1,3 +0,0 @@
1int getFoo() {
2 return 42;
3}
test/link/macho/tbdv3/build.zig deleted-57
......@@ -1,57 +0,0 @@
1const std = @import("std");
2const builtin = @import("builtin");
3
4pub const requires_symlinks = true;
5pub const requires_macos_sdk = false;
6
7pub fn build(b: *std.Build) void {
8 const test_step = b.step("test", "Test it");
9 b.default_step = test_step;
10
11 add(b, test_step, .Debug);
12 add(b, test_step, .ReleaseFast);
13 add(b, test_step, .ReleaseSmall);
14 add(b, test_step, .ReleaseSafe);
15}
16
17fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
18 const target = b.resolveTargetQuery(.{ .os_tag = .macos });
19
20 const lib = b.addSharedLibrary(.{
21 .name = "a",
22 .version = .{ .major = 1, .minor = 0, .patch = 0 },
23 .optimize = optimize,
24 .target = target,
25 });
26 lib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
27 lib.linkLibC();
28
29 const tbd_file = b.addWriteFile("liba.tbd",
30 \\--- !tapi-tbd-v3
31 \\archs: [ arm64, x86_64 ]
32 \\uuids: [ 'arm64: DEADBEEF', 'x86_64: BEEFDEAD' ]
33 \\platform: macos
34 \\install-name: @rpath/liba.dylib
35 \\current-version: 0
36 \\exports:
37 \\ - archs: [ arm64, x86_64 ]
38 \\ symbols: [ _getFoo ]
39 );
40
41 const exe = b.addExecutable(.{
42 .name = "test",
43 .optimize = optimize,
44 .target = target,
45 });
46 exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
47 exe.linkSystemLibrary("a");
48 exe.addLibraryPath(tbd_file.getDirectory());
49 exe.addRPath(lib.getEmittedBinDirectory());
50 exe.linkLibC();
51
52 const run = b.addRunArtifact(exe);
53 run.skip_foreign_checks = true;
54 run.expectExitCode(0);
55
56 test_step.dependOn(&run.step);
57}
test/link/macho/tbdv3/main.c deleted-7
......@@ -1,7 +0,0 @@
1#include <stdio.h>
2
3int getFoo();
4
5int main() {
6 return getFoo() - 42;
7}