aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-01-13 18:49:27 +0100
committerJakub Konka <kubkon@jakubkonka.com>2024-01-24 12:34:39 +0100
commitd93a0763d4c732fcdb3ed891d5b44a10943ccfed (patch)
tree47dfd634d9ed9e4f3dc777ca39221fed11da3850
parent041f7d69f0656254cfa62a59af2fa65ac1b1c433 (diff)
downloadzig-d93a0763d4c732fcdb3ed891d5b44a10943ccfed.tar.gz
zig-d93a0763d4c732fcdb3ed891d5b44a10943ccfed.zip
test/link/link: pass build options to elf and macho tests
-rw-r--r--test/link.zig4
-rw-r--r--test/link/elf.zig4
-rw-r--r--test/link/link.zig20
-rw-r--r--test/link/macho.zig28
-rw-r--r--test/link/macho/needed_framework/build.zig37
-rw-r--r--test/link/macho/needed_framework/main.c3
-rw-r--r--test/tests.zig43
7 files changed, 76 insertions, 63 deletions
diff --git a/test/link.zig b/test/link.zig
index a8cdfe19ad..259166f0e0 100644
--- a/test/link.zig
+++ b/test/link.zig
@@ -136,10 +136,6 @@ pub const cases = [_]Case{
.import = @import("link/macho/linksection/build.zig"),
},
.{
- .build_root = "test/link/macho/needed_framework",
- .import = @import("link/macho/needed_framework/build.zig"),
- },
- .{
.build_root = "test/link/macho/needed_library",
.import = @import("link/macho/needed_library/build.zig"),
},
diff --git a/test/link/elf.zig b/test/link/elf.zig
index 1f5c1978ce..8c02128521 100644
--- a/test/link/elf.zig
+++ b/test/link/elf.zig
@@ -2,7 +2,8 @@
//! Currently, we support linking x86_64 Linux, but in the future we
//! will progressively relax those to exercise more combinations.
-pub fn testAll(b: *Build) *Step {
+pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
+ _ = build_opts;
const elf_step = b.step("test-elf", "Run ELF tests");
const default_target = b.resolveTargetQuery(.{
@@ -3901,6 +3902,7 @@ const link = @import("link.zig");
const std = @import("std");
const Build = std.Build;
+const BuildOptions = link.BuildOptions;
const Options = link.Options;
const Step = Build.Step;
const WriteFile = Step.WriteFile;
diff --git a/test/link/link.zig b/test/link/link.zig
index ccce03bb0b..c17f8b0b5a 100644
--- a/test/link/link.zig
+++ b/test/link/link.zig
@@ -2,10 +2,26 @@ pub fn build(b: *Build) void {
const test_step = b.step("test-link", "Run link tests");
b.default_step = test_step;
- test_step.dependOn(@import("elf.zig").testAll(b));
- test_step.dependOn(@import("macho.zig").testAll(b));
+ const has_macos_sdk = b.option(bool, "has_macos_sdk", "whether the host provides a macOS SDK in system path");
+ const has_ios_sdk = b.option(bool, "has_ios_sdk", "whether the host provides a iOS SDK in system path");
+ const has_symlinks_windows = b.option(bool, "has_symlinks_windows", "whether the host is windows and has symlinks enabled");
+
+ const build_opts: BuildOptions = .{
+ .has_macos_sdk = has_macos_sdk orelse false,
+ .has_ios_sdk = has_ios_sdk orelse false,
+ .has_symlinks_windows = has_symlinks_windows orelse false,
+ };
+
+ test_step.dependOn(@import("elf.zig").testAll(b, build_opts));
+ test_step.dependOn(@import("macho.zig").testAll(b, build_opts));
}
+pub const BuildOptions = struct {
+ has_macos_sdk: bool,
+ has_ios_sdk: bool,
+ has_symlinks_windows: bool,
+};
+
pub const Options = struct {
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode = .Debug,
diff --git a/test/link/macho.zig b/test/link/macho.zig
index cc5bc7878e..b9e5ee4349 100644
--- a/test/link/macho.zig
+++ b/test/link/macho.zig
@@ -1,7 +1,7 @@
//! Here we test our MachO linker for correctness and functionality.
//! TODO migrate standalone tests from test/link/macho/* to here.
-pub fn testAll(b: *std.Build) *Step {
+pub fn testAll(b: *std.Build, build_opts: BuildOptions) *Step {
const macho_step = b.step("test-macho", "Run MachO tests");
const default_target = b.resolveTargetQuery(.{
@@ -13,6 +13,11 @@ pub fn testAll(b: *std.Build) *Step {
macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = default_target }));
macho_step.dependOn(testSegmentBoundarySymbols(b, .{ .target = default_target }));
+ // Tests requiring presence of macOS SDK in system path
+ if (build_opts.has_macos_sdk and build_opts.has_symlinks_windows) {
+ macho_step.dependOn(testNeededFramework(b, .{ .target = b.host }));
+ }
+
return macho_step;
}
@@ -151,6 +156,26 @@ fn testEntryPointDylib(b: *std.Build, opts: Options) *Step {
return test_step;
}
+fn testNeededFramework(b: *std.Build, opts: Options) *Step {
+ const test_step = addTestStep(b, "macho-needed-framework", opts);
+
+ const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = "int main() { return 0; }" });
+ exe.linkFrameworkNeeded("Cocoa");
+ exe.dead_strip_dylibs = true;
+
+ const check = exe.checkObject();
+ check.checkInHeaders();
+ check.checkExact("cmd LOAD_DYLIB");
+ check.checkContains("Cocoa");
+ test_step.dependOn(&check.step);
+
+ const run = addRunArtifact(exe);
+ run.expectExitCode(0);
+ test_step.dependOn(&run.step);
+
+ return test_step;
+}
+
fn testSectionBoundarySymbols(b: *std.Build, opts: Options) *Step {
const test_step = addTestStep(b, "macho-section-boundary-symbols", opts);
@@ -311,5 +336,6 @@ const addSharedLibrary = link.addSharedLibrary;
const expectLinkErrors = link.expectLinkErrors;
const link = @import("link.zig");
const std = @import("std");
+const BuildOptions = link.BuildOptions;
const Options = link.Options;
const Step = std.Build.Step;
diff --git a/test/link/macho/needed_framework/build.zig b/test/link/macho/needed_framework/build.zig
deleted file mode 100644
index 83a3e75e2d..0000000000
--- a/test/link/macho/needed_framework/build.zig
+++ /dev/null
@@ -1,37 +0,0 @@
-const std = @import("std");
-
-pub const requires_symlinks = true;
-pub const requires_macos_sdk = true;
-
-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 {
- // -dead_strip_dylibs
- // -needed_framework Cocoa
- const exe = b.addExecutable(.{
- .name = "test",
- .optimize = optimize,
- .target = b.host,
- });
- exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
- exe.linkLibC();
- exe.linkFrameworkNeeded("Cocoa");
- exe.dead_strip_dylibs = true;
-
- const check = exe.checkObject();
- check.checkInHeaders();
- check.checkExact("cmd LOAD_DYLIB");
- check.checkContains("Cocoa");
- test_step.dependOn(&check.step);
-
- const run_cmd = b.addRunArtifact(exe);
- test_step.dependOn(&run_cmd.step);
-}
diff --git a/test/link/macho/needed_framework/main.c b/test/link/macho/needed_framework/main.c
deleted file mode 100644
index ca68d24cc7..0000000000
--- a/test/link/macho/needed_framework/main.c
+++ /dev/null
@@ -1,3 +0,0 @@
-int main(int argc, char* argv[]) {
- return 0;
-}
diff --git a/test/tests.zig b/test/tests.zig
index b2fb1e4bca..9dcc77b141 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -750,26 +750,39 @@ pub fn addLinkTests(
const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows;
inline for (link.cases) |case| {
- const requires_stage2 = @hasDecl(case.import, "requires_stage2") and
- case.import.requires_stage2;
- const requires_symlinks = @hasDecl(case.import, "requires_symlinks") and
- case.import.requires_symlinks;
- const requires_macos_sdk = @hasDecl(case.import, "requires_macos_sdk") and
- case.import.requires_macos_sdk;
- const requires_ios_sdk = @hasDecl(case.import, "requires_ios_sdk") and
- case.import.requires_ios_sdk;
- const bad =
- (requires_stage2 and omit_stage2) or
- (requires_symlinks and omit_symlinks) or
- (requires_macos_sdk and !enable_macos_sdk) or
- (requires_ios_sdk and !enable_ios_sdk);
- if (!bad) {
- const dep = b.anonymousDependency(case.build_root, case.import, .{});
+ if (mem.eql(u8, @typeName(case.import), "test.link.link")) {
+ const dep = b.anonymousDependency(case.build_root, case.import, .{
+ .has_macos_sdk = enable_macos_sdk,
+ .has_ios_sdk = enable_ios_sdk,
+ .has_symlinks_windows = !omit_symlinks,
+ });
const dep_step = dep.builder.default_step;
assert(mem.startsWith(u8, dep.builder.dep_prefix, "test."));
const dep_prefix_adjusted = dep.builder.dep_prefix["test.".len..];
dep_step.name = b.fmt("{s}{s}", .{ dep_prefix_adjusted, dep_step.name });
step.dependOn(dep_step);
+ } else {
+ const requires_stage2 = @hasDecl(case.import, "requires_stage2") and
+ case.import.requires_stage2;
+ const requires_symlinks = @hasDecl(case.import, "requires_symlinks") and
+ case.import.requires_symlinks;
+ const requires_macos_sdk = @hasDecl(case.import, "requires_macos_sdk") and
+ case.import.requires_macos_sdk;
+ const requires_ios_sdk = @hasDecl(case.import, "requires_ios_sdk") and
+ case.import.requires_ios_sdk;
+ const bad =
+ (requires_stage2 and omit_stage2) or
+ (requires_symlinks and omit_symlinks) or
+ (requires_macos_sdk and !enable_macos_sdk) or
+ (requires_ios_sdk and !enable_ios_sdk);
+ if (!bad) {
+ const dep = b.anonymousDependency(case.build_root, case.import, .{});
+ const dep_step = dep.builder.default_step;
+ assert(mem.startsWith(u8, dep.builder.dep_prefix, "test."));
+ const dep_prefix_adjusted = dep.builder.dep_prefix["test.".len..];
+ dep_step.name = b.fmt("{s}{s}", .{ dep_prefix_adjusted, dep_step.name });
+ step.dependOn(dep_step);
+ }
}
}