test/link/macho: upgrade tbdv3 test

This commit is contained in:
Jakub Konka 2024-01-15 12:05:26 +01:00
parent a3f68c6fa2
commit 2b3ac3e82f
5 changed files with 39 additions and 71 deletions

View File

@ -115,8 +115,4 @@ pub const cases = [_]Case{
.build_root = "test/link/macho/objcpp",
.import = @import("link/macho/objcpp/build.zig"),
},
.{
.build_root = "test/link/macho/tbdv3",
.import = @import("link/macho/tbdv3/build.zig"),
},
};

View File

@ -50,6 +50,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
macho_step.dependOn(testDylib(b, .{ .target = default_target }));
macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target }));
macho_step.dependOn(testSearchStrategy(b, .{ .target = default_target }));
macho_step.dependOn(testTbdv3(b, .{ .target = default_target }));
macho_step.dependOn(testTls(b, .{ .target = default_target }));
macho_step.dependOn(testTwoLevelNamespace(b, .{ .target = default_target }));
macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target }));
@ -1285,6 +1286,44 @@ fn testStackSize(b: *Build, opts: Options) *Step {
return test_step;
}
fn testTbdv3(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "macho-tbdv3", opts);
const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = "int getFoo() { return 42; }" });
const tbd = tbd: {
const wf = WriteFile.create(b);
break :tbd wf.add("liba.tbd",
\\--- !tapi-tbd-v3
\\archs: [ arm64, x86_64 ]
\\uuids: [ 'arm64: DEADBEEF', 'x86_64: BEEFDEAD' ]
\\platform: macos
\\install-name: @rpath/liba.dylib
\\current-version: 0
\\exports:
\\ - archs: [ arm64, x86_64 ]
\\ symbols: [ _getFoo ]
);
};
const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
\\#include <stdio.h>
\\int getFoo();
\\int main() {
\\ return getFoo() - 42;
\\}
});
exe.root_module.linkSystemLibrary("a", .{});
exe.root_module.addLibraryPath(tbd.dirname());
exe.root_module.addRPath(dylib.getEmittedBinDirectory());
const run = addRunArtifact(exe);
run.expectExitCode(0);
test_step.dependOn(&run.step);
return test_step;
}
fn testTentative(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "macho-tentative", opts);

View File

@ -1,3 +0,0 @@
int getFoo() {
return 42;
}

View File

@ -1,57 +0,0 @@
const std = @import("std");
const builtin = @import("builtin");
pub const requires_symlinks = true;
pub const requires_macos_sdk = false;
pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Test it");
b.default_step = test_step;
add(b, test_step, .Debug);
add(b, test_step, .ReleaseFast);
add(b, test_step, .ReleaseSmall);
add(b, test_step, .ReleaseSafe);
}
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const target = b.resolveTargetQuery(.{ .os_tag = .macos });
const lib = b.addSharedLibrary(.{
.name = "a",
.version = .{ .major = 1, .minor = 0, .patch = 0 },
.optimize = optimize,
.target = target,
});
lib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
lib.linkLibC();
const tbd_file = b.addWriteFile("liba.tbd",
\\--- !tapi-tbd-v3
\\archs: [ arm64, x86_64 ]
\\uuids: [ 'arm64: DEADBEEF', 'x86_64: BEEFDEAD' ]
\\platform: macos
\\install-name: @rpath/liba.dylib
\\current-version: 0
\\exports:
\\ - archs: [ arm64, x86_64 ]
\\ symbols: [ _getFoo ]
);
const exe = b.addExecutable(.{
.name = "test",
.optimize = optimize,
.target = target,
});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
exe.linkSystemLibrary("a");
exe.addLibraryPath(tbd_file.getDirectory());
exe.addRPath(lib.getEmittedBinDirectory());
exe.linkLibC();
const run = b.addRunArtifact(exe);
run.skip_foreign_checks = true;
run.expectExitCode(0);
test_step.dependOn(&run.step);
}

View File

@ -1,7 +0,0 @@
#include <stdio.h>
int getFoo();
int main() {
return getFoo() - 42;
}