mirror of
https://github.com/ziglang/zig.git
synced 2025-12-20 13:13:16 +00:00
test/link/link: pass build options to elf and macho tests
This commit is contained in:
parent
041f7d69f0
commit
d93a0763d4
@ -135,10 +135,6 @@ pub const cases = [_]Case{
|
|||||||
.build_root = "test/link/macho/linksection",
|
.build_root = "test/link/macho/linksection",
|
||||||
.import = @import("link/macho/linksection/build.zig"),
|
.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",
|
.build_root = "test/link/macho/needed_library",
|
||||||
.import = @import("link/macho/needed_library/build.zig"),
|
.import = @import("link/macho/needed_library/build.zig"),
|
||||||
|
|||||||
@ -2,7 +2,8 @@
|
|||||||
//! Currently, we support linking x86_64 Linux, but in the future we
|
//! Currently, we support linking x86_64 Linux, but in the future we
|
||||||
//! will progressively relax those to exercise more combinations.
|
//! 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 elf_step = b.step("test-elf", "Run ELF tests");
|
||||||
|
|
||||||
const default_target = b.resolveTargetQuery(.{
|
const default_target = b.resolveTargetQuery(.{
|
||||||
@ -3901,6 +3902,7 @@ const link = @import("link.zig");
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const Build = std.Build;
|
const Build = std.Build;
|
||||||
|
const BuildOptions = link.BuildOptions;
|
||||||
const Options = link.Options;
|
const Options = link.Options;
|
||||||
const Step = Build.Step;
|
const Step = Build.Step;
|
||||||
const WriteFile = Step.WriteFile;
|
const WriteFile = Step.WriteFile;
|
||||||
|
|||||||
@ -2,10 +2,26 @@ pub fn build(b: *Build) void {
|
|||||||
const test_step = b.step("test-link", "Run link tests");
|
const test_step = b.step("test-link", "Run link tests");
|
||||||
b.default_step = test_step;
|
b.default_step = test_step;
|
||||||
|
|
||||||
test_step.dependOn(@import("elf.zig").testAll(b));
|
const has_macos_sdk = b.option(bool, "has_macos_sdk", "whether the host provides a macOS SDK in system path");
|
||||||
test_step.dependOn(@import("macho.zig").testAll(b));
|
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 {
|
pub const Options = struct {
|
||||||
target: std.Build.ResolvedTarget,
|
target: std.Build.ResolvedTarget,
|
||||||
optimize: std.builtin.OptimizeMode = .Debug,
|
optimize: std.builtin.OptimizeMode = .Debug,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
//! Here we test our MachO linker for correctness and functionality.
|
//! Here we test our MachO linker for correctness and functionality.
|
||||||
//! TODO migrate standalone tests from test/link/macho/* to here.
|
//! 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 macho_step = b.step("test-macho", "Run MachO tests");
|
||||||
|
|
||||||
const default_target = b.resolveTargetQuery(.{
|
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(testSectionBoundarySymbols(b, .{ .target = default_target }));
|
||||||
macho_step.dependOn(testSegmentBoundarySymbols(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;
|
return macho_step;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,6 +156,26 @@ fn testEntryPointDylib(b: *std.Build, opts: Options) *Step {
|
|||||||
return test_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 {
|
fn testSectionBoundarySymbols(b: *std.Build, opts: Options) *Step {
|
||||||
const test_step = addTestStep(b, "macho-section-boundary-symbols", opts);
|
const test_step = addTestStep(b, "macho-section-boundary-symbols", opts);
|
||||||
|
|
||||||
@ -311,5 +336,6 @@ const addSharedLibrary = link.addSharedLibrary;
|
|||||||
const expectLinkErrors = link.expectLinkErrors;
|
const expectLinkErrors = link.expectLinkErrors;
|
||||||
const link = @import("link.zig");
|
const link = @import("link.zig");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const BuildOptions = link.BuildOptions;
|
||||||
const Options = link.Options;
|
const Options = link.Options;
|
||||||
const Step = std.Build.Step;
|
const Step = std.Build.Step;
|
||||||
|
|||||||
@ -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);
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
int main(int argc, char* argv[]) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@ -750,6 +750,18 @@ pub fn addLinkTests(
|
|||||||
const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows;
|
const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows;
|
||||||
|
|
||||||
inline for (link.cases) |case| {
|
inline for (link.cases) |case| {
|
||||||
|
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
|
const requires_stage2 = @hasDecl(case.import, "requires_stage2") and
|
||||||
case.import.requires_stage2;
|
case.import.requires_stage2;
|
||||||
const requires_symlinks = @hasDecl(case.import, "requires_symlinks") and
|
const requires_symlinks = @hasDecl(case.import, "requires_symlinks") and
|
||||||
@ -772,6 +784,7 @@ pub fn addLinkTests(
|
|||||||
step.dependOn(dep_step);
|
step.dependOn(dep_step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return step;
|
return step;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user