| author | |
| committer | |
| log | 0e9bdb44a6ca022558ed703749353c76e796dc35 |
| tree | aeedbc3a20024875139cf892fa6dbdf4f08e35d0 |
| parent | 052b4ae9415596e0b6b6c32b9b4f2d3ff8c9e953 |
5 files changed, 83 insertions(+), 12 deletions(-)
src/link.cpp+3| ... | ... | @@ -573,6 +573,9 @@ static void get_darwin_platform(LinkJob *lj, DarwinPlatform *platform) { |
| 573 | 573 | platform->kind = MacOS; |
| 574 | 574 | } else if (g->mios_version_min) { |
| 575 | 575 | platform->kind = IPhoneOS; |
| 576 | } else if (g->zig_target.os == ZigLLVM_MacOSX) { | |
| 577 | platform->kind = MacOS; | |
| 578 | g->mmacosx_version_min = buf_create_from_str("10.10"); | |
| 576 | 579 | } else { |
| 577 | 580 | zig_panic("unable to infer -mmacosx-version-min or -mios-version-min"); |
| 578 | 581 | } |
src/main.cpp+10| ... | ... | @@ -676,6 +676,16 @@ int main(int argc, char **argv) { |
| 676 | 676 | } else if (cmd == CmdTest) { |
| 677 | 677 | codegen_build(g); |
| 678 | 678 | codegen_link(g, "./test"); |
| 679 | ||
| 680 | ZigTarget native; | |
| 681 | get_native_target(&native); | |
| 682 | bool is_native_target = target == nullptr || (target->os == native.os && | |
| 683 | target->arch.arch == native.arch.arch && target->arch.sub_arch == native.arch.sub_arch); | |
| 684 | if (!is_native_target) { | |
| 685 | fprintf(stderr, "Skipping execution of non-native test binary.\n"); | |
| 686 | return 0; | |
| 687 | } | |
| 688 | ||
| 679 | 689 | ZigList<const char *> args = {0}; |
| 680 | 690 | Termination term; |
| 681 | 691 | os_spawn_process("./test", args, &term); |
src/target.cpp+1-1| ... | ... | @@ -482,6 +482,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 482 | 482 | } |
| 483 | 483 | case ZigLLVM_Linux: |
| 484 | 484 | case ZigLLVM_Darwin: |
| 485 | case ZigLLVM_MacOSX: | |
| 485 | 486 | switch (id) { |
| 486 | 487 | case CIntTypeShort: |
| 487 | 488 | case CIntTypeUShort: |
| ... | ... | @@ -521,7 +522,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 521 | 522 | case ZigLLVM_IOS: |
| 522 | 523 | case ZigLLVM_KFreeBSD: |
| 523 | 524 | case ZigLLVM_Lv2: |
| 524 | case ZigLLVM_MacOSX: | |
| 525 | 525 | case ZigLLVM_NetBSD: |
| 526 | 526 | case ZigLLVM_OpenBSD: |
| 527 | 527 | case ZigLLVM_Solaris: |
std/build.zig+28| ... | ... | @@ -1027,6 +1027,7 @@ pub const TestStep = struct { |
| 1027 | 1027 | link_libs: BufSet, |
| 1028 | 1028 | name_prefix: []const u8, |
| 1029 | 1029 | filter: ?[]const u8, |
| 1030 | target: Target, | |
| 1030 | 1031 | |
| 1031 | 1032 | pub fn init(builder: &Builder, root_src: []const u8) -> TestStep { |
| 1032 | 1033 | const step_name = builder.fmt("test {}", root_src); |
| ... | ... | @@ -1039,6 +1040,7 @@ pub const TestStep = struct { |
| 1039 | 1040 | .name_prefix = "", |
| 1040 | 1041 | .filter = null, |
| 1041 | 1042 | .link_libs = BufSet.init(builder.allocator), |
| 1043 | .target = Target.Native, | |
| 1042 | 1044 | } |
| 1043 | 1045 | } |
| 1044 | 1046 | |
| ... | ... | @@ -1062,6 +1064,18 @@ pub const TestStep = struct { |
| 1062 | 1064 | self.filter = text; |
| 1063 | 1065 | } |
| 1064 | 1066 | |
| 1067 | pub fn setTarget(self: &TestStep, target_arch: builtin.Arch, target_os: builtin.Os, | |
| 1068 | target_environ: builtin.Environ) | |
| 1069 | { | |
| 1070 | self.target = Target.Cross { | |
| 1071 | CrossTarget { | |
| 1072 | .arch = target_arch, | |
| 1073 | .os = target_os, | |
| 1074 | .environ = target_environ, | |
| 1075 | } | |
| 1076 | }; | |
| 1077 | } | |
| 1078 | ||
| 1065 | 1079 | fn make(step: &Step) -> %void { |
| 1066 | 1080 | const self = @fieldParentPtr(TestStep, "step", step); |
| 1067 | 1081 | const builder = self.builder; |
| ... | ... | @@ -1082,6 +1096,20 @@ pub const TestStep = struct { |
| 1082 | 1096 | builtin.Mode.ReleaseFast => %%zig_args.append("--release-fast"), |
| 1083 | 1097 | } |
| 1084 | 1098 | |
| 1099 | switch (self.target) { | |
| 1100 | Target.Native => {}, | |
| 1101 | Target.Cross => |cross_target| { | |
| 1102 | %%zig_args.append("--target-arch"); | |
| 1103 | %%zig_args.append(@enumTagName(cross_target.arch)); | |
| 1104 | ||
| 1105 | %%zig_args.append("--target-os"); | |
| 1106 | %%zig_args.append(@enumTagName(cross_target.os)); | |
| 1107 | ||
| 1108 | %%zig_args.append("--target-environ"); | |
| 1109 | %%zig_args.append(@enumTagName(cross_target.environ)); | |
| 1110 | }, | |
| 1111 | } | |
| 1112 | ||
| 1085 | 1113 | if (self.filter) |filter| { |
| 1086 | 1114 | %%zig_args.append("--test-filter"); |
| 1087 | 1115 | %%zig_args.append(filter); |
test/tests.zig+41-11| ... | ... | @@ -9,7 +9,8 @@ const io = std.io; |
| 9 | 9 | const mem = std.mem; |
| 10 | 10 | const fmt = std.fmt; |
| 11 | 11 | const ArrayList = std.ArrayList; |
| 12 | const Mode = @import("builtin").Mode; | |
| 12 | const builtin = @import("builtin"); | |
| 13 | const Mode = builtin.Mode; | |
| 13 | 14 | |
| 14 | 15 | const compare_output = @import("compare_output.zig"); |
| 15 | 16 | const build_examples = @import("build_examples.zig"); |
| ... | ... | @@ -18,6 +19,25 @@ const assemble_and_link = @import("assemble_and_link.zig"); |
| 18 | 19 | const debug_safety = @import("debug_safety.zig"); |
| 19 | 20 | const parseh = @import("parseh.zig"); |
| 20 | 21 | |
| 22 | const TestTarget = struct { | |
| 23 | os: builtin.Os, | |
| 24 | arch: builtin.Arch, | |
| 25 | environ: builtin.Environ, | |
| 26 | }; | |
| 27 | ||
| 28 | const test_targets = []TestTarget { | |
| 29 | TestTarget { | |
| 30 | .os = builtin.Os.linux, | |
| 31 | .arch = builtin.Arch.x86_64, | |
| 32 | .environ = builtin.Environ.gnu, | |
| 33 | }, | |
| 34 | TestTarget { | |
| 35 | .os = builtin.Os.macosx, | |
| 36 | .arch = builtin.Arch.x86_64, | |
| 37 | .environ = builtin.Environ.unknown, | |
| 38 | }, | |
| 39 | }; | |
| 40 | ||
| 21 | 41 | error TestFailed; |
| 22 | 42 | |
| 23 | 43 | pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step { |
| ... | ... | @@ -121,17 +141,27 @@ pub fn addPkgTestsRaw(b: &build.Builder, test_filter: ?[]const u8, root_src: []c |
| 121 | 141 | { |
| 122 | 142 | const libc_bools = if (always_link_libc) []bool{true} else []bool{false, true}; |
| 123 | 143 | const step = b.step(b.fmt("test-{}", name), desc); |
| 124 | for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| { | |
| 125 | for (libc_bools) |link_libc| { | |
| 126 | const these_tests = b.addTest(root_src); | |
| 127 | these_tests.setNamePrefix(b.fmt("{}-{}-{} ", name, @enumTagName(mode), | |
| 128 | if (link_libc) "c" else "bare")); | |
| 129 | these_tests.setFilter(test_filter); | |
| 130 | these_tests.setBuildMode(mode); | |
| 131 | if (link_libc) { | |
| 132 | these_tests.linkSystemLibrary("c"); | |
| 144 | for (test_targets) |test_target| { | |
| 145 | const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch); | |
| 146 | for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| { | |
| 147 | for (libc_bools) |link_libc| { | |
| 148 | if (link_libc and !is_native) { | |
| 149 | // don't assume we have a cross-compiling libc set up | |
| 150 | continue; | |
| 151 | } | |
| 152 | const these_tests = b.addTest(root_src); | |
| 153 | these_tests.setNamePrefix(b.fmt("{}-{}-{}-{}-{} ", name, @enumTagName(test_target.os), | |
| 154 | @enumTagName(test_target.arch), @enumTagName(mode), if (link_libc) "c" else "bare")); | |
| 155 | these_tests.setFilter(test_filter); | |
| 156 | these_tests.setBuildMode(mode); | |
| 157 | if (!is_native) { | |
| 158 | these_tests.setTarget(test_target.arch, test_target.os, test_target.environ); | |
| 159 | } | |
| 160 | if (link_libc) { | |
| 161 | these_tests.linkSystemLibrary("c"); | |
| 162 | } | |
| 163 | step.dependOn(&these_tests.step); | |
| 133 | 164 | } |
| 134 | step.dependOn(&these_tests.step); | |
| 135 | 165 | } |
| 136 | 166 | } |
| 137 | 167 | return step; |