aboutsummaryrefslogtreecommitdiff
path: root/test/tests.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-02-26 01:18:23 -0500
committerAndrew Kelley <andrew@ziglang.org>2020-02-28 14:51:54 -0500
commitdbe4d72bcfb20fc43713781679a0d23aea0a17d9 (patch)
tree7ba5a5bc8683a089615d18ca9e5dcc73a2f0c899 /test/tests.zig
parent87b9e744dda465ecf7663e2463066ea26a44e63a (diff)
downloadzig-dbe4d72bcfb20fc43713781679a0d23aea0a17d9.tar.gz
zig-dbe4d72bcfb20fc43713781679a0d23aea0a17d9.zip
separate std.Target and std.zig.CrossTarget
Zig now supports a more fine-grained sense of what is native and what is not. Some examples: This is now allowed: -target native Different OS but native CPU, default Windows C ABI: -target native-windows This could be useful for example when running in Wine. Different CPU but native OS, native C ABI. -target x86_64-native -mcpu=skylake Different C ABI but otherwise native target: -target native-native-musl -target native-native-gnu Lots of breaking changes to related std lib APIs. Calls to getOs() will need to be changed to getOsTag(). Calls to getArch() will need to be changed to getCpuArch(). Usage of Target.Cross and Target.Native need to be updated to use CrossTarget API. `std.build.Builder.standardTargetOptions` is changed to accept its parameters as a struct with default values. It now has the ability to specify a whitelist of targets allowed, as well as the default target. Rather than two different ways of collecting the target, it's now always a string that is validated, and prints helpful diagnostics for invalid targets. This feature should now be actually useful, and contributions welcome to further improve the user experience. `std.build.LibExeObjStep.setTheTarget` is removed. `std.build.LibExeObjStep.setTarget` is updated to take a CrossTarget parameter. `std.build.LibExeObjStep.setTargetGLibC` is removed. glibc versions are handled in the CrossTarget API and can be specified with the `-target` triple. `std.builtin.Version` gains a `format` method.
Diffstat (limited to 'test/tests.zig')
-rw-r--r--test/tests.zig204
1 files changed, 82 insertions, 122 deletions
diff --git a/test/tests.zig b/test/tests.zig
index 78eaf56273..9cf4e7bd98 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -3,7 +3,7 @@ const builtin = std.builtin;
const debug = std.debug;
const warn = debug.warn;
const build = std.build;
-pub const Target = build.Target;
+const CrossTarget = std.zig.CrossTarget;
const Buffer = std.Buffer;
const io = std.io;
const fs = std.fs;
@@ -30,7 +30,7 @@ pub const RunTranslatedCContext = @import("src/run_translated_c.zig").RunTransla
pub const CompareOutputContext = @import("src/compare_output.zig").CompareOutputContext;
const TestTarget = struct {
- target: build.Target = .Native,
+ target: CrossTarget = @as(CrossTarget, .{}),
mode: builtin.Mode = .Debug,
link_libc: bool = false,
single_threaded: bool = false,
@@ -52,105 +52,85 @@ const test_targets = blk: {
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.x86_64),
- .os = std.Target.Os.defaultVersionRange(.linux),
- .abi = .none,
- },
+ .target = .{
+ .cpu_arch = .x86_64,
+ .os_tag = .linux,
+ .abi = .none,
},
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.x86_64),
- .os = std.Target.Os.defaultVersionRange(.linux),
- .abi = .gnu,
- },
+ .target = .{
+ .cpu_arch = .x86_64,
+ .os_tag = .linux,
+ .abi = .gnu,
},
.link_libc = true,
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.x86_64),
- .os = std.Target.Os.defaultVersionRange(.linux),
- .abi = .musl,
- },
+ .target = .{
+ .cpu_arch = .x86_64,
+ .os_tag = .linux,
+ .abi = .musl,
},
.link_libc = true,
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.i386),
- .os = std.Target.Os.defaultVersionRange(.linux),
- .abi = .none,
- },
+ .target = .{
+ .cpu_arch = .i386,
+ .os_tag = .linux,
+ .abi = .none,
},
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.i386),
- .os = std.Target.Os.defaultVersionRange(.linux),
- .abi = .musl,
- },
+ .target = .{
+ .cpu_arch = .i386,
+ .os_tag = .linux,
+ .abi = .musl,
},
.link_libc = true,
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.aarch64),
- .os = std.Target.Os.defaultVersionRange(.linux),
- .abi = .none,
- },
+ .target = .{
+ .cpu_arch = .aarch64,
+ .os_tag = .linux,
+ .abi = .none,
},
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.aarch64),
- .os = std.Target.Os.defaultVersionRange(.linux),
- .abi = .musl,
- },
+ .target = .{
+ .cpu_arch = .aarch64,
+ .os_tag = .linux,
+ .abi = .musl,
},
.link_libc = true,
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.aarch64),
- .os = std.Target.Os.defaultVersionRange(.linux),
- .abi = .gnu,
- },
+ .target = .{
+ .cpu_arch = .aarch64,
+ .os_tag = .linux,
+ .abi = .gnu,
},
.link_libc = true,
},
TestTarget{
- .target = .{
- .Cross = std.Target.parse(.{
- .arch_os_abi = "arm-linux-none",
- .cpu_features = "generic+v8a",
- }) catch unreachable,
- },
+ .target = CrossTarget.parse(.{
+ .arch_os_abi = "arm-linux-none",
+ .cpu_features = "generic+v8a",
+ }) catch unreachable,
},
TestTarget{
- .target = .{
- .Cross = std.Target.parse(.{
- .arch_os_abi = "arm-linux-musleabihf",
- .cpu_features = "generic+v8a",
- }) catch unreachable,
- },
+ .target = CrossTarget.parse(.{
+ .arch_os_abi = "arm-linux-musleabihf",
+ .cpu_features = "generic+v8a",
+ }) catch unreachable,
.link_libc = true,
},
// TODO https://github.com/ziglang/zig/issues/3287
//TestTarget{
- // .target = std.Target.parse(.{
+ // .target = CrossTarget.parse(.{
// .arch_os_abi = "arm-linux-gnueabihf",
// .cpu_features = "generic+v8a",
// }) catch unreachable,
@@ -158,75 +138,61 @@ const test_targets = blk: {
//},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.mipsel),
- .os = std.Target.Os.defaultVersionRange(.linux),
- .abi = .none,
- },
+ .target = .{
+ .cpu_arch = .mipsel,
+ .os_tag = .linux,
+ .abi = .none,
},
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.mipsel),
- .os = std.Target.Os.defaultVersionRange(.linux),
- .abi = .musl,
- },
+ .target = .{
+ .cpu_arch = .mipsel,
+ .os_tag = .linux,
+ .abi = .musl,
},
.link_libc = true,
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.x86_64),
- .os = std.Target.Os.defaultVersionRange(.macosx),
- .abi = .gnu,
- },
+ .target = .{
+ .cpu_arch = .x86_64,
+ .os_tag = .macosx,
+ .abi = .gnu,
},
// TODO https://github.com/ziglang/zig/issues/3295
.disable_native = true,
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.i386),
- .os = std.Target.Os.defaultVersionRange(.windows),
- .abi = .msvc,
- },
+ .target = .{
+ .cpu_arch = .i386,
+ .os_tag = .windows,
+ .abi = .msvc,
},
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.x86_64),
- .os = std.Target.Os.defaultVersionRange(.windows),
- .abi = .msvc,
- },
+ .target = .{
+ .cpu_arch = .x86_64,
+ .os_tag = .windows,
+ .abi = .msvc,
},
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.i386),
- .os = std.Target.Os.defaultVersionRange(.windows),
- .abi = .gnu,
- },
+ .target = .{
+ .cpu_arch = .i386,
+ .os_tag = .windows,
+ .abi = .gnu,
},
.link_libc = true,
},
TestTarget{
- .target = Target{
- .Cross = .{
- .cpu = std.Target.Cpu.baseline(.x86_64),
- .os = std.Target.Os.defaultVersionRange(.windows),
- .abi = .gnu,
- },
+ .target = .{
+ .cpu_arch = .x86_64,
+ .os_tag = .windows,
+ .abi = .gnu,
},
.link_libc = true,
},
@@ -435,13 +401,13 @@ pub fn addPkgTests(
const step = b.step(b.fmt("test-{}", .{name}), desc);
for (test_targets) |test_target| {
- if (skip_non_native and test_target.target != .Native)
+ if (skip_non_native and !test_target.target.isNative())
continue;
if (skip_libc and test_target.link_libc)
continue;
- if (test_target.link_libc and test_target.target.getTarget().osRequiresLibC()) {
+ if (test_target.link_libc and test_target.target.getOs().requiresLibC()) {
// This would be a redundant test.
continue;
}
@@ -451,8 +417,8 @@ pub fn addPkgTests(
const ArchTag = @TagType(builtin.Arch);
if (test_target.disable_native and
- test_target.target.getOs() == std.Target.current.os.tag and
- test_target.target.getArch() == std.Target.current.cpu.arch)
+ test_target.target.getOsTag() == std.Target.current.os.tag and
+ test_target.target.getCpuArch() == std.Target.current.cpu.arch)
{
continue;
}
@@ -462,17 +428,14 @@ pub fn addPkgTests(
} else false;
if (!want_this_mode) continue;
- const libc_prefix = if (test_target.target.getTarget().osRequiresLibC())
+ const libc_prefix = if (test_target.target.getOs().requiresLibC())
""
else if (test_target.link_libc)
"c"
else
"bare";
- const triple_prefix = if (test_target.target == .Native)
- @as([]const u8, "native")
- else
- test_target.target.zigTriple(b.allocator) catch unreachable;
+ const triple_prefix = test_target.target.zigTriple(b.allocator) catch unreachable;
const these_tests = b.addTest(root_src);
const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
@@ -486,7 +449,7 @@ pub fn addPkgTests(
these_tests.single_threaded = test_target.single_threaded;
these_tests.setFilter(test_filter);
these_tests.setBuildMode(test_target.mode);
- these_tests.setTheTarget(test_target.target);
+ these_tests.setTarget(test_target.target);
if (test_target.link_libc) {
these_tests.linkSystemLibrary("c");
}
@@ -716,7 +679,7 @@ pub const CompileErrorContext = struct {
link_libc: bool,
is_exe: bool,
is_test: bool,
- target: Target = .Native,
+ target: CrossTarget = CrossTarget{},
const SourceFile = struct {
filename: []const u8,
@@ -808,12 +771,9 @@ pub const CompileErrorContext = struct {
zig_args.append("--output-dir") catch unreachable;
zig_args.append(b.pathFromRoot(b.cache_root)) catch unreachable;
- switch (self.case.target) {
- .Native => {},
- .Cross => {
- try zig_args.append("-target");
- try zig_args.append(try self.case.target.zigTriple(b.allocator));
- },
+ if (!self.case.target.isNative()) {
+ try zig_args.append("-target");
+ try zig_args.append(try self.case.target.zigTriple(b.allocator));
}
switch (self.build_mode) {