authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-22 21:18:27-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-09-22 21:18:27-04:00
log35c1d8cefc3a77b867ecc2da999162781099b4c6
tree572620e3af2d8254f74fdd7086eab1e851148084
parent989cd4233e14d592c19d458fee24ff0fa9fd9638
parent55925b6e259b5453b8af29a5365d82378cb1d54b
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #3290 from ziglang/more-test-coverage

significantly increase test coverage

31 files changed, 565 insertions(+), 163 deletions(-)

.gitattributes+1
......@@ -1,4 +1,5 @@
11*.zig text eol=lf
2*.txt text eol=lf
23langref.html.in text eol=lf
34
45deps/* linguist-vendored
build.zig+8-6
......@@ -70,6 +70,7 @@ pub fn build(b: *Builder) !void {
7070 const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release;
7171 const skip_release_safe = b.option(bool, "skip-release-safe", "Main test suite skips release-safe builds") orelse skip_release;
7272 const skip_non_native = b.option(bool, "skip-non-native", "Main test suite skips non-native builds") orelse false;
73 const skip_libc = b.option(bool, "skip-libc", "Main test suite skips tests that link libc") orelse false;
7374 const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") orelse false;
7475 if (!skip_self_hosted) {
7576 // TODO re-enable this after https://github.com/ziglang/zig/issues/2377
......@@ -96,6 +97,10 @@ pub fn build(b: *Builder) !void {
9697
9798 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
9899
100 const is_wine_enabled = b.option(bool, "enable-wine", "Use Wine to run cross compiled Windows tests") orelse false;
101 const is_qemu_enabled = b.option(bool, "enable-qemu", "Use QEMU to run cross compiled foreign architecture tests") orelse false;
102 const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");
103
99104 const test_stage2_step = b.step("test-stage2", "Run the stage2 compiler tests");
100105 test_stage2_step.dependOn(&test_stage2.step);
101106
......@@ -122,19 +127,16 @@ pub fn build(b: *Builder) !void {
122127 }
123128 const modes = chosen_modes[0..chosen_mode_index];
124129
125 const multi_and_single = [_]bool{ false, true };
126 const just_multi = [_]bool{false};
127
128130 // run stage1 `zig fmt` on this build.zig file just to make sure it works
129131 test_step.dependOn(&fmt_build_zig.step);
130132 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");
131133 fmt_step.dependOn(&fmt_build_zig.step);
132134
133 test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, multi_and_single, skip_non_native));
135 test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, false, skip_non_native, skip_libc, is_wine_enabled, is_qemu_enabled, glibc_multi_dir));
134136
135 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes, multi_and_single, skip_non_native));
137 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes, false, skip_non_native, skip_libc, is_wine_enabled, is_qemu_enabled, glibc_multi_dir));
136138
137 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, just_multi, skip_non_native));
139 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, true, skip_non_native, true, is_wine_enabled, is_qemu_enabled, glibc_multi_dir));
138140
139141 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
140142 test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));
ci/azure/linux_script+2-2
......@@ -12,7 +12,7 @@ sudo apt-get update -q
1212
1313sudo apt-get remove -y llvm-*
1414sudo rm -rf /usr/local/*
15sudo apt-get install -y libxml2-dev libclang-9-dev llvm-9 llvm-9-dev cmake s3cmd gcc-7 g++-7
15sudo apt-get install -y libxml2-dev libclang-9-dev llvm-9 llvm-9-dev cmake s3cmd gcc-7 g++-7 qemu
1616
1717export CC=gcc-7
1818export CXX=g++-7
......@@ -20,7 +20,7 @@ mkdir build
2020cd build
2121cmake .. -DCMAKE_BUILD_TYPE=Release
2222make -j2 install
23./zig build --build-file ../build.zig test
23./zig build test -Denable-qemu
2424
2525if [ "${BUILD_REASON}" != "PullRequest" ]; then
2626 ARTIFACTSDIR="$BUILDDIR/artifacts"
ci/azure/macos_script+1-1
......@@ -70,7 +70,7 @@ mkdir build
7070cd build
7171cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_INSTALL_PREFIX=$(pwd)/release -DZIG_STATIC=ON
7272make $JOBS install
73release/bin/zig build --build-file ../build.zig test
73release/bin/zig build test
7474
7575if [ "${BUILD_REASON}" != "PullRequest" ]; then
7676 mv ../LICENSE release/
ci/azure/pipelines.yml+1-1
......@@ -27,7 +27,7 @@ jobs:
2727 displayName: 'Build and test'
2828- job: BuildWindows
2929 pool:
30 vmImage: 'vs2017-win2016'
30 vmImage: 'windows-2019'
3131
3232 timeoutInMinutes: 360
3333
ci/azure/windows_script.bat+6-5
......@@ -10,17 +10,18 @@ SET "PATH=%PREVPATH%"
1010SET "MSYSTEM=%PREVMSYSTEM%"
1111
1212SET "ZIGBUILDDIR=%SRCROOT%\build"
13SET "ZIGINSTALLDIR=%ZIGBUILDDIR%\release"
13SET "ZIGINSTALLDIR=%ZIGBUILDDIR%\dist"
1414SET "ZIGPREFIXPATH=%SRCROOT%\llvm+clang-9.0.0-win64-msvc-release"
1515
16call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
16call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
1717
1818mkdir %ZIGBUILDDIR%
1919cd %ZIGBUILDDIR%
20cmake.exe .. -Thost=x64 -G"Visual Studio 15 2017 Win64" "-DCMAKE_INSTALL_PREFIX=%ZIGINSTALLDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release || exit /b
21msbuild /p:Configuration=Release INSTALL.vcxproj || exit /b
20REM Here we use MinSizeRel instead of Release to work around https://github.com/ziglang/zig/issues/3024
21cmake.exe .. -Thost=x64 -G"Visual Studio 16 2019" -A x64 "-DCMAKE_INSTALL_PREFIX=%ZIGINSTALLDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=MinSizeRel || exit /b
22msbuild /p:Configuration=MinSizeRel INSTALL.vcxproj || exit /b
2223
23"%ZIGINSTALLDIR%\bin\zig.exe" build --build-file ..\build.zig test || exit /b
24"%ZIGINSTALLDIR%\bin\zig.exe" build test || exit /b
2425
2526set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
2627SET "MSYSTEM=MINGW64"
ci/azure/windows_upload+6-7
......@@ -6,16 +6,15 @@ set -e
66if [ "${BUILD_REASON}" != "PullRequest" ]; then
77 cd "$ZIGBUILDDIR"
88
9 rm release/*.exe
10 mv ../LICENSE release/
11 mv ../zig-cache/langref.html release/
12 mv release/bin/zig.exe release/
13 rmdir release/bin
9 mv ../LICENSE dist/
10 mv ../zig-cache/langref.html dist/
11 mv dist/bin/zig.exe dist/
12 rmdir dist/bin
1413
15 VERSION=$(release/zig.exe version)
14 VERSION=$(dist/zig.exe version)
1615 DIRNAME="zig-windows-x86_64-$VERSION"
1716 TARBALL="$DIRNAME.zip"
18 mv release "$DIRNAME"
17 mv dist "$DIRNAME"
1918 7z a "$TARBALL" "$DIRNAME"
2019
2120 mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
lib/libc/include/any-windows-any/psdk_inc/intrin-impl.h-26
......@@ -1938,32 +1938,6 @@ __buildmov(__movsd, unsigned __LONG32, "d")
19381938#define __INTRINSIC_DEFINED___movsd
19391939#endif /* __INTRINSIC_PROLOG */
19401940
1941#if !defined(__GNUC__) || __GNUC__ < 8 /* GCC 8 has already defined _xgetbv */
1942/* NOTE: This should be in immintrin.h */
1943#if __INTRINSIC_PROLOG(_xgetbv)
1944unsigned __int64 _xgetbv(unsigned int);
1945#if !__has_builtin(_xgetbv)
1946__INTRINSICS_USEINLINE
1947unsigned __int64 _xgetbv(unsigned int index)
1948{
1949#if defined(__x86_64__) || defined(_AMD64_)
1950 unsigned __int64 val1, val2;
1951#else
1952 unsigned __LONG32 val1, val2;
1953#endif /* defined(__x86_64__) || defined(_AMD64_) */
1954
1955 __asm__ __volatile__(
1956 "xgetbv"
1957 : "=a" (val1), "=d" (val2)
1958 : "c" (index));
1959
1960 return (((unsigned __int64)val2) << 32) | val1;
1961}
1962#endif
1963#define __INTRINSIC_DEFINED__xgetbv
1964#endif /* __INTRINSIC_PROLOG */
1965#endif /* __GNUC__ < 8 */
1966
19671941#endif /* defined(__x86_64__) || defined(_AMD64_) || defined(__i386__) || defined(_X86_) */
19681942
19691943/* ***************************************************** */
src/buffer.cpp-1
......@@ -61,7 +61,6 @@ void buf_appendf(Buf *buf, const char *format, ...) {
6161
6262// these functions are not static inline so they can be better used as template parameters
6363bool buf_eql_buf(Buf *buf, Buf *other) {
64 assert(buf->list.length);
6564 return buf_eql_mem(buf, buf_ptr(other), buf_len(other));
6665}
6766
src/glibc.cpp+22-7
......@@ -50,7 +50,7 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
5050 }
5151
5252 {
53 SplitIterator it = memSplit(buf_to_slice(vers_txt_contents), str("\n"));
53 SplitIterator it = memSplit(buf_to_slice(vers_txt_contents), str("\r\n"));
5454 for (;;) {
5555 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
5656 if (!opt_component.is_some) break;
......@@ -65,7 +65,7 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
6565 }
6666 }
6767 {
68 SplitIterator it = memSplit(buf_to_slice(fns_txt_contents), str("\n"));
68 SplitIterator it = memSplit(buf_to_slice(fns_txt_contents), str("\r\n"));
6969 for (;;) {
7070 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
7171 if (!opt_component.is_some) break;
......@@ -91,17 +91,19 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
9191 }
9292 }
9393 {
94 SplitIterator it = memSplit(buf_to_slice(abi_txt_contents), str("\n"));
94 SplitIterator it = memSplit(buf_to_slice(abi_txt_contents), str("\r\n"));
9595 ZigGLibCVerList *ver_list_base = nullptr;
96 int line_num = 0;
9697 for (;;) {
9798 if (ver_list_base == nullptr) {
99 line_num += 1;
98100 Optional<Slice<uint8_t>> opt_line = SplitIterator_next_separate(&it);
99101 if (!opt_line.is_some) break;
100102
101103 ver_list_base = allocate<ZigGLibCVerList>(glibc_abi->all_functions.length);
102 ZigTarget *target = allocate<ZigTarget>(1);
103104 SplitIterator line_it = memSplit(opt_line.value, str(" "));
104105 for (;;) {
106 ZigTarget *target = allocate<ZigTarget>(1);
105107 Optional<Slice<uint8_t>> opt_target = SplitIterator_next(&line_it);
106108 if (!opt_target.is_some) break;
107109
......@@ -122,7 +124,19 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
122124 target->os = OsLinux;
123125
124126 err = target_parse_abi(&target->abi, (char*)opt_abi.value.ptr, opt_abi.value.len);
125 assert(err == ErrorNone);
127 if (err != ErrorNone) {
128 fprintf(stderr, "Error parsing %s:%d: %s\n", buf_ptr(glibc_abi->abi_txt_path),
129 line_num, err_str(err));
130 fprintf(stderr, "arch: '%.*s', os: '%.*s', abi: '%.*s'\n",
131 (int)opt_arch.value.len, (const char*)opt_arch.value.ptr,
132 (int)opt_os.value.len, (const char*)opt_os.value.ptr,
133 (int)opt_abi.value.len, (const char*)opt_abi.value.ptr);
134 fprintf(stderr, "parsed from target: '%.*s'\n",
135 (int)opt_target.value.len, (const char*)opt_target.value.ptr);
136 fprintf(stderr, "parsed from line:\n%.*s\n", (int)opt_line.value.len, opt_line.value.ptr);
137 fprintf(stderr, "Zig installation appears to be corrupted.\n");
138 exit(1);
139 }
126140
127141 glibc_abi->version_table.put(target, ver_list_base);
128142 }
......@@ -130,6 +144,7 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
130144 }
131145 for (size_t fn_i = 0; fn_i < glibc_abi->all_functions.length; fn_i += 1) {
132146 ZigGLibCVerList *ver_list = &ver_list_base[fn_i];
147 line_num += 1;
133148 Optional<Slice<uint8_t>> opt_line = SplitIterator_next_separate(&it);
134149 assert(opt_line.is_some);
135150
......@@ -266,7 +281,7 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
266281 // - If there are no versions, don't emit it
267282 // - Take the greatest one <= than the target one
268283 // - If none of them is <= than the
269 // specified one don't pick any default version
284 // specified one don't pick any default version
270285 if (ver_list->len == 0) continue;
271286 uint8_t chosen_def_ver_index = 255;
272287 for (uint8_t ver_i = 0; ver_i < ver_list->len; ver_i += 1) {
......@@ -322,7 +337,7 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
322337 codegen_set_lib_version(child_gen, lib->sover, 0, 0);
323338 child_gen->is_dynamic = true;
324339 child_gen->is_dummy_so = true;
325 child_gen->version_script_path = map_file_path;
340 child_gen->version_script_path = map_file_path;
326341 child_gen->enable_cache = false;
327342 child_gen->output_dir = dummy_dir;
328343 codegen_build_and_link(child_gen);
src/link.cpp+4
......@@ -1295,6 +1295,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
12951295 c_file->args.append("-include");
12961296 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));
12971297 c_file->args.append("-DMODULE_NAME=libc");
1298 c_file->args.append("-Wno-nonportable-include-path");
12981299 c_file->args.append("-include");
12991300 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));
13001301 c_file->args.append("-DTOP_NAMESPACE=glibc");
......@@ -1321,6 +1322,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
13211322 c_file->args.append("-include");
13221323 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));
13231324 c_file->args.append("-DMODULE_NAME=libc");
1325 c_file->args.append("-Wno-nonportable-include-path");
13241326 c_file->args.append("-include");
13251327 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));
13261328 c_file->args.append("-DPIC");
......@@ -1377,6 +1379,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
13771379 c_file->args.append("-include");
13781380 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));
13791381 c_file->args.append("-DMODULE_NAME=libc");
1382 c_file->args.append("-Wno-nonportable-include-path");
13801383 c_file->args.append("-include");
13811384 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));
13821385 c_file->args.append("-DPIC");
......@@ -1420,6 +1423,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
14201423 c_file->args.append("-include");
14211424 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));
14221425 c_file->args.append("-DMODULE_NAME=libc");
1426 c_file->args.append("-Wno-nonportable-include-path");
14231427 c_file->args.append("-include");
14241428 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));
14251429 c_file->args.append("-DPIC");
src/os.cpp+1-1
......@@ -116,7 +116,7 @@ static void os_spawn_process_posix(ZigList<const char *> &args, Termination *ter
116116 pid_t pid;
117117 int rc = posix_spawnp(&pid, args.at(0), nullptr, nullptr, const_cast<char *const*>(argv), environ);
118118 if (rc != 0) {
119 zig_panic("posix_spawn failed: %s", strerror(rc));
119 zig_panic("unable to spawn %s: %s", args.at(0), strerror(rc));
120120 }
121121
122122 int status;
src/util.cpp+1-8
......@@ -18,17 +18,10 @@ void zig_panic(const char *format, ...) {
1818 vfprintf(stderr, format, ap);
1919 fflush(stderr);
2020 va_end(ap);
21 stage2_panic(nullptr, 0);
21 stage2_panic("", 0);
2222 abort();
2323}
2424
25void assert(bool ok) {
26 if (!ok) {
27 const char *msg = "Assertion failed. This is a bug in the Zig compiler.";
28 stage2_panic(msg, strlen(msg));
29 }
30}
31
3225uint32_t int_hash(int i) {
3326 return (uint32_t)(i % UINT32_MAX);
3427}
src/util.hpp+8-2
......@@ -43,15 +43,21 @@ ATTRIBUTE_NORETURN
4343ATTRIBUTE_PRINTF(1, 2)
4444void zig_panic(const char *format, ...);
4545
46static inline void zig_assert(bool ok, const char *file, int line, const char *func) {
47 if (!ok) {
48 zig_panic("Assertion failed at %s:%d in %s. This is a bug in the Zig compiler.", file, line, func);
49 }
50}
51
4652#ifdef _WIN32
4753#define __func__ __FUNCTION__
4854#endif
4955
50#define zig_unreachable() zig_panic("unreachable: %s:%s:%d", __FILE__, __func__, __LINE__)
56#define zig_unreachable() zig_panic("Unreachable at %s:%d in %s. This is a bug in the Zig compiler.", __FILE__, __LINE__, __func__)
5157
5258// Assertions in stage1 are always on, and they call zig @panic.
5359#undef assert
54void assert(bool ok);
60#define assert(ok) zig_assert(ok, __FILE__, __LINE__, __func__)
5561
5662#if defined(_MSC_VER)
5763static inline int clzll(unsigned long long mask) {
std/build.zig+175-1
......@@ -1015,6 +1015,7 @@ pub const Target = union(enum) {
10151015 => return .msvc,
10161016 .linux,
10171017 .wasi,
1018 .emscripten,
10181019 => return .musl,
10191020 }
10201021 }
......@@ -1175,6 +1176,13 @@ pub const Target = union(enum) {
11751176 };
11761177 }
11771178
1179 pub fn isLinux(self: Target) bool {
1180 return switch (self.getOs()) {
1181 .linux => true,
1182 else => false,
1183 };
1184 }
1185
11781186 pub fn isUefi(self: Target) bool {
11791187 return switch (self.getOs()) {
11801188 .uefi => true,
......@@ -1196,9 +1204,125 @@ pub const Target = union(enum) {
11961204 };
11971205 }
11981206
1207 pub fn isNetBSD(self: Target) bool {
1208 return switch (self.getOs()) {
1209 .netbsd => true,
1210 else => false,
1211 };
1212 }
1213
11991214 pub fn wantSharedLibSymLinks(self: Target) bool {
12001215 return !self.isWindows();
12011216 }
1217
1218 pub fn osRequiresLibC(self: Target) bool {
1219 return self.isDarwin() or self.isFreeBSD() or self.isNetBSD();
1220 }
1221
1222 pub fn getArchPtrBitWidth(self: Target) u32 {
1223 switch (self.getArch()) {
1224 .avr,
1225 .msp430,
1226 => return 16,
1227
1228 .arc,
1229 .arm,
1230 .armeb,
1231 .hexagon,
1232 .le32,
1233 .mips,
1234 .mipsel,
1235 .powerpc,
1236 .r600,
1237 .riscv32,
1238 .sparc,
1239 .sparcel,
1240 .tce,
1241 .tcele,
1242 .thumb,
1243 .thumbeb,
1244 .i386,
1245 .xcore,
1246 .nvptx,
1247 .amdil,
1248 .hsail,
1249 .spir,
1250 .kalimba,
1251 .shave,
1252 .lanai,
1253 .wasm32,
1254 .renderscript32,
1255 .aarch64_32,
1256 => return 32,
1257
1258 .aarch64,
1259 .aarch64_be,
1260 .mips64,
1261 .mips64el,
1262 .powerpc64,
1263 .powerpc64le,
1264 .riscv64,
1265 .x86_64,
1266 .nvptx64,
1267 .le64,
1268 .amdil64,
1269 .hsail64,
1270 .spir64,
1271 .wasm64,
1272 .renderscript64,
1273 .amdgcn,
1274 .bpfel,
1275 .bpfeb,
1276 .sparcv9,
1277 .s390x,
1278 => return 64,
1279 }
1280 }
1281
1282 pub const Executor = union(enum) {
1283 native,
1284 qemu: []const u8,
1285 wine: []const u8,
1286 unavailable,
1287 };
1288
1289 pub fn getExternalExecutor(self: Target) Executor {
1290 if (@TagType(Target)(self) == .Native) return .native;
1291
1292 // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture.
1293 if (self.getOs() == builtin.os) {
1294 return switch (self.getArch()) {
1295 .aarch64 => Executor{ .qemu = "qemu-aarch64" },
1296 .aarch64_be => Executor{ .qemu = "qemu-aarch64_be" },
1297 .arm => Executor{ .qemu = "qemu-arm" },
1298 .armeb => Executor{ .qemu = "qemu-armeb" },
1299 .i386 => Executor{ .qemu = "qemu-i386" },
1300 .mips => Executor{ .qemu = "qemu-mips" },
1301 .mipsel => Executor{ .qemu = "qemu-mipsel" },
1302 .mips64 => Executor{ .qemu = "qemu-mips64" },
1303 .mips64el => Executor{ .qemu = "qemu-mips64el" },
1304 .powerpc => Executor{ .qemu = "qemu-ppc" },
1305 .powerpc64 => Executor{ .qemu = "qemu-ppc64" },
1306 .powerpc64le => Executor{ .qemu = "qemu-ppc64le" },
1307 .riscv32 => Executor{ .qemu = "qemu-riscv32" },
1308 .riscv64 => Executor{ .qemu = "qemu-riscv64" },
1309 .s390x => Executor{ .qemu = "qemu-s390x" },
1310 .sparc => Executor{ .qemu = "qemu-sparc" },
1311 .x86_64 => Executor{ .qemu = "qemu-x86_64" },
1312 else => return .unavailable,
1313 };
1314 }
1315
1316 if (self.isWindows()) {
1317 switch (self.getArchPtrBitWidth()) {
1318 32 => return Executor{ .wine = "wine" },
1319 64 => return Executor{ .wine = "wine64" },
1320 else => return .unavailable,
1321 }
1322 }
1323
1324 return .unavailable;
1325 }
12021326};
12031327
12041328const Pkg = struct {
......@@ -1266,6 +1390,7 @@ pub const LibExeObjStep = struct {
12661390 include_dirs: ArrayList(IncludeDir),
12671391 output_dir: ?[]const u8,
12681392 need_system_paths: bool,
1393 is_linking_libc: bool = false,
12691394
12701395 installed_path: ?[]const u8,
12711396 install_step: ?*InstallArtifactStep,
......@@ -1275,6 +1400,20 @@ pub const LibExeObjStep = struct {
12751400
12761401 valgrind_support: ?bool = null,
12771402
1403 /// Uses system Wine installation to run cross compiled Windows build artifacts.
1404 enable_wine: bool = false,
1405
1406 /// Uses system QEMU installation to run cross compiled foreign architecture build artifacts.
1407 enable_qemu: bool = false,
1408
1409 /// After following the steps in https://github.com/ziglang/zig/wiki/Updating-libc#glibc,
1410 /// this will be the directory $glibc-build-dir/install/glibcs
1411 /// Given the example of the aarch64 target, this is the directory
1412 /// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`.
1413 glibc_multi_install_dir: ?[]const u8 = null,
1414
1415 dynamic_linker: ?[]const u8 = null,
1416
12781417 const LinkObject = union(enum) {
12791418 StaticPath: []const u8,
12801419 OtherStep: *LibExeObjStep,
......@@ -1504,7 +1643,9 @@ pub const LibExeObjStep = struct {
15041643
15051644 pub fn linkSystemLibrary(self: *LibExeObjStep, name: []const u8) void {
15061645 self.link_objects.append(LinkObject{ .SystemLib = self.builder.dupe(name) }) catch unreachable;
1507 if (!isLibCLibrary(name)) {
1646 if (isLibCLibrary(name)) {
1647 self.is_linking_libc = true;
1648 } else {
15081649 self.need_system_paths = true;
15091650 }
15101651 }
......@@ -1840,6 +1981,11 @@ pub const LibExeObjStep = struct {
18401981 zig_args.append(builder.pathFromRoot(linker_script)) catch unreachable;
18411982 }
18421983
1984 if (self.dynamic_linker) |dynamic_linker| {
1985 try zig_args.append("--dynamic-linker");
1986 try zig_args.append(dynamic_linker);
1987 }
1988
18431989 if (self.version_script) |version_script| {
18441990 try zig_args.append("--version-script");
18451991 try zig_args.append(builder.pathFromRoot(version_script));
......@@ -1854,6 +2000,34 @@ pub const LibExeObjStep = struct {
18542000 try zig_args.append("--test-cmd-bin");
18552001 }
18562002 }
2003 } else switch (self.target.getExternalExecutor()) {
2004 .native, .unavailable => {},
2005 .qemu => |bin_name| if (self.enable_qemu) qemu: {
2006 const need_cross_glibc = self.target.isGnu() and self.target.isLinux() and self.is_linking_libc;
2007 const glibc_dir_arg = if (need_cross_glibc)
2008 self.glibc_multi_install_dir orelse break :qemu
2009 else
2010 null;
2011 try zig_args.append("--test-cmd");
2012 try zig_args.append(bin_name);
2013 if (glibc_dir_arg) |dir| {
2014 const full_dir = try fs.path.join(builder.allocator, [_][]const u8{
2015 dir,
2016 try self.target.linuxTriple(builder.allocator),
2017 });
2018
2019 try zig_args.append("--test-cmd");
2020 try zig_args.append("-L");
2021 try zig_args.append("--test-cmd");
2022 try zig_args.append(full_dir);
2023 }
2024 try zig_args.append("--test-cmd-bin");
2025 },
2026 .wine => |bin_name| if (self.enable_wine) {
2027 try zig_args.append("--test-cmd");
2028 try zig_args.append(bin_name);
2029 try zig_args.append("--test-cmd-bin");
2030 },
18572031 }
18582032 for (self.packages.toSliceConst()) |pkg| {
18592033 zig_args.append("--pkg-begin") catch unreachable;
std/c.zig+1-1
......@@ -63,7 +63,7 @@ pub extern "c" fn close(fd: fd_t) c_int;
6363pub extern "c" fn @"close$NOCANCEL"(fd: fd_t) c_int;
6464pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
6565pub extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
66pub extern "c" fn lseek(fd: fd_t, offset: isize, whence: c_int) isize;
66pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t;
6767pub extern "c" fn open(path: [*]const u8, oflag: c_uint, ...) c_int;
6868pub extern "c" fn openat(fd: c_int, path: [*]const u8, oflag: c_uint, ...) c_int;
6969pub extern "c" fn raise(sig: c_int) c_int;
std/fmt/parse_float.zig+4
......@@ -382,6 +382,10 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {
382382}
383383
384384test "fmt.parseFloat" {
385 if (@import("builtin").arch == .arm) {
386 // TODO https://github.com/ziglang/zig/issues/3289
387 return error.SkipZigTest;
388 }
385389 const testing = std.testing;
386390 const expect = testing.expect;
387391 const expectEqual = testing.expectEqual;
std/fs/path.zig+8
......@@ -646,6 +646,10 @@ test "resolve" {
646646}
647647
648648test "resolveWindows" {
649 if (@import("builtin").arch == .aarch64) {
650 // TODO https://github.com/ziglang/zig/issues/3288
651 return error.SkipZigTest;
652 }
649653 if (windows.is_the_target) {
650654 const cwd = try process.getCwdAlloc(debug.global_allocator);
651655 const parsed_cwd = windowsParsePath(cwd);
......@@ -1086,6 +1090,10 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![
10861090}
10871091
10881092test "relative" {
1093 if (@import("builtin").arch == .aarch64) {
1094 // TODO https://github.com/ziglang/zig/issues/3288
1095 return error.SkipZigTest;
1096 }
10891097 testRelativeWindows("c:/blah\\blah", "d:/games", "D:\\games");
10901098 testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa", "..");
10911099 testRelativeWindows("c:/aaaa/bbbb", "c:/cccc", "..\\..\\cccc");
std/io/test.zig+4
......@@ -11,6 +11,10 @@ const fs = std.fs;
1111const File = std.fs.File;
1212
1313test "write a file, read it, then delete it" {
14 if (builtin.arch == .aarch64 and builtin.glibc_version != null) {
15 // TODO https://github.com/ziglang/zig/issues/3288
16 return error.SkipZigTest;
17 }
1418 var raw_bytes: [200 * 1024]u8 = undefined;
1519 var allocator = &std.heap.FixedBufferAllocator.init(raw_bytes[0..]).allocator;
1620
std/os/bits/darwin.zig+3-1
......@@ -43,6 +43,8 @@ pub const mach_timebase_info_data = extern struct {
4343 denom: u32,
4444};
4545
46pub const off_t = i64;
47
4648/// Renamed to Stat to not conflict with the stat function.
4749/// atime, mtime, and ctime have functions to return `timespec`,
4850/// because although this is a POSIX API, the layout and names of
......@@ -65,7 +67,7 @@ pub const Stat = extern struct {
6567 ctimensec: isize,
6668 birthtimesec: isize,
6769 birthtimensec: isize,
68 size: i64,
70 size: off_t,
6971 blocks: i64,
7072 blksize: i32,
7173 flags: u32,
std/os/bits/freebsd.zig+3-1
......@@ -73,6 +73,8 @@ pub const msghdr_const = extern struct {
7373 msg_flags: i32,
7474};
7575
76pub const off_t = i64;
77
7678/// Renamed to Stat to not conflict with the stat function.
7779/// atime, mtime, and ctime have functions to return `timespec`,
7880/// because although this is a POSIX API, the layout and names of
......@@ -96,7 +98,7 @@ pub const Stat = extern struct {
9698 ctim: timespec,
9799 birthtim: timespec,
98100
99 size: i64,
101 size: off_t,
100102 blocks: i64,
101103 blksize: isize,
102104 flags: u32,
std/os/bits/linux/arm-eabi.zig+3-1
......@@ -511,6 +511,8 @@ pub const msghdr_const = extern struct {
511511 msg_flags: i32,
512512};
513513
514pub const off_t = i64;
515
514516/// Renamed to Stat to not conflict with the stat function.
515517/// atime, mtime, and ctime have functions to return `timespec`,
516518/// because although this is a POSIX API, the layout and names of
......@@ -527,7 +529,7 @@ pub const Stat = extern struct {
527529 gid: u32,
528530 rdev: u64,
529531 __rdev_padding: u32,
530 size: i64,
532 size: off_t,
531533 blksize: i32,
532534 blocks: u64,
533535 atim: timespec,
std/os/bits/linux/arm64.zig+26-16
......@@ -1,11 +1,13 @@
11// arm64-specific declarations that are intended to be imported into the POSIX namespace.
22// This does include Linux-only APIs.
33
4const std = @import("../../std.zig");
4const std = @import("../../../std.zig");
55const linux = std.os.linux;
66const socklen_t = linux.socklen_t;
77const iovec = linux.iovec;
88const iovec_const = linux.iovec_const;
9const uid_t = linux.uid_t;
10const gid_t = linux.gid_t;
911
1012pub const SYS_io_setup = 0;
1113pub const SYS_io_destroy = 1;
......@@ -382,6 +384,15 @@ pub const msghdr_const = extern struct {
382384 msg_flags: i32,
383385};
384386
387pub const blksize_t = i32;
388pub const nlink_t = u32;
389pub const time_t = isize;
390pub const mode_t = u32;
391pub const off_t = isize;
392pub const ino_t = usize;
393pub const dev_t = usize;
394pub const blkcnt_t = isize;
395
385396/// Renamed to Stat to not conflict with the stat function.
386397/// atime, mtime, and ctime have functions to return `timespec`,
387398/// because although this is a POSIX API, the layout and names of
......@@ -389,23 +400,22 @@ pub const msghdr_const = extern struct {
389400/// in C, macros are used to hide the differences. Here we use
390401/// methods to accomplish this.
391402pub const Stat = extern struct {
392 dev: u64,
393 ino: u64,
394 nlink: usize,
395
396 mode: u32,
397 uid: u32,
398 gid: u32,
399 __pad0: u32,
400 rdev: u64,
401 size: i64,
402 blksize: isize,
403 blocks: i64,
404
403 dev: dev_t,
404 ino: ino_t,
405 mode: mode_t,
406 nlink: nlink_t,
407 uid: uid_t,
408 gid: gid_t,
409 rdev: dev_t,
410 __pad: usize,
411 size: off_t,
412 blksize: blksize_t,
413 __pad2: i32,
414 blocks: blkcnt_t,
405415 atim: timespec,
406416 mtim: timespec,
407417 ctim: timespec,
408 __unused: [3]isize,
418 __unused: [2]u32,
409419
410420 pub fn atime(self: Stat) timespec {
411421 return self.atim;
......@@ -421,7 +431,7 @@ pub const Stat = extern struct {
421431};
422432
423433pub const timespec = extern struct {
424 tv_sec: isize,
434 tv_sec: time_t,
425435 tv_nsec: isize,
426436};
427437
std/os/bits/linux/x86_64.zig+3-1
......@@ -479,6 +479,8 @@ pub const msghdr_const = extern struct {
479479 msg_flags: i32,
480480};
481481
482pub const off_t = i64;
483
482484/// Renamed to Stat to not conflict with the stat function.
483485/// atime, mtime, and ctime have functions to return `timespec`,
484486/// because although this is a POSIX API, the layout and names of
......@@ -495,7 +497,7 @@ pub const Stat = extern struct {
495497 gid: u32,
496498 __pad0: u32,
497499 rdev: u64,
498 size: i64,
500 size: off_t,
499501 blksize: isize,
500502 blocks: i64,
501503
std/os/bits/netbsd.zig+3-1
......@@ -73,6 +73,8 @@ pub const msghdr_const = extern struct {
7373 msg_flags: i32,
7474};
7575
76pub const off_t = i64;
77
7678/// Renamed to Stat to not conflict with the stat function.
7779/// atime, mtime, and ctime have functions to return `timespec`,
7880/// because although this is a POSIX API, the layout and names of
......@@ -94,7 +96,7 @@ pub const Stat = extern struct {
9496 ctim: timespec,
9597 birthtim: timespec,
9698
97 size: i64,
99 size: off_t,
98100 blocks: i64,
99101 blksize: isize,
100102 flags: u32,
std/os/test.zig+4
......@@ -95,6 +95,10 @@ test "cpu count" {
9595}
9696
9797test "AtomicFile" {
98 if (builtin.arch == .aarch64 and builtin.glibc_version != null) {
99 // TODO https://github.com/ziglang/zig/issues/3288
100 return error.SkipZigTest;
101 }
98102 var buffer: [1024]u8 = undefined;
99103 const allocator = &std.heap.FixedBufferAllocator.init(buffer[0..]).allocator;
100104 const test_out_file = "tmp_atomic_file_test_dest.txt";
std/rb.zig+9
......@@ -511,6 +511,11 @@ fn testCompare(l: *Node, r: *Node) mem.Compare {
511511}
512512
513513test "rb" {
514 if (@import("builtin").arch == .aarch64) {
515 // TODO https://github.com/ziglang/zig/issues/3288
516 return error.SkipZigTest;
517 }
518
514519 var tree: Tree = undefined;
515520 var ns: [10]testNumber = undefined;
516521 ns[0].value = 42;
......@@ -571,6 +576,10 @@ test "inserting and looking up" {
571576}
572577
573578test "multiple inserts, followed by calling first and last" {
579 if (@import("builtin").arch == .aarch64) {
580 // TODO https://github.com/ziglang/zig/issues/3288
581 return error.SkipZigTest;
582 }
574583 var tree: Tree = undefined;
575584 tree.init(testCompare);
576585 var zeroth: testNumber = undefined;
std/special/compiler_rt.zig+7-4
......@@ -143,7 +143,7 @@ comptime {
143143 @export("__negsf2", @import("compiler_rt/negXf2.zig").__negsf2, linkage);
144144 @export("__negdf2", @import("compiler_rt/negXf2.zig").__negdf2, linkage);
145145
146 if (is_arm_arch and !is_arm_64) {
146 if (is_arm_arch and !is_arm_64 and !is_test) {
147147 @export("__aeabi_unwind_cpp_pr0", __aeabi_unwind_cpp_pr0, strong_linkage);
148148 @export("__aeabi_unwind_cpp_pr1", __aeabi_unwind_cpp_pr1, linkage);
149149 @export("__aeabi_unwind_cpp_pr2", __aeabi_unwind_cpp_pr2, linkage);
......@@ -233,7 +233,7 @@ comptime {
233233 @export("__aeabi_dcmpgt", @import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpgt, linkage);
234234 @export("__aeabi_dcmpun", @import("compiler_rt/comparedf2.zig").__unorddf2, linkage);
235235 }
236 if (builtin.os == builtin.Os.windows) {
236 if (builtin.os == .windows) {
237237 if (!builtin.link_libc) {
238238 @export("_chkstk", @import("compiler_rt/stack_probe.zig")._chkstk, strong_linkage);
239239 @export("__chkstk", @import("compiler_rt/stack_probe.zig").__chkstk, strong_linkage);
......@@ -247,11 +247,11 @@ comptime {
247247 }
248248
249249 switch (builtin.arch) {
250 builtin.Arch.i386 => {
250 .i386 => {
251251 @export("_aulldiv", @import("compiler_rt/aulldiv.zig")._aulldiv, strong_linkage);
252252 @export("_aullrem", @import("compiler_rt/aullrem.zig")._aullrem, strong_linkage);
253253 },
254 builtin.Arch.x86_64 => {
254 .x86_64 => {
255255 // The "ti" functions must use @Vector(2, u64) parameter types to adhere to the ABI
256256 // that LLVM expects compiler-rt to have.
257257 @export("__divti3", @import("compiler_rt/divti3.zig").__divti3_windows_x86_64, linkage);
......@@ -264,6 +264,9 @@ comptime {
264264 else => {},
265265 }
266266 } else {
267 if (builtin.glibc_version != null) {
268 @export("__stack_chk_guard", __stack_chk_guard, linkage);
269 }
267270 @export("__divti3", @import("compiler_rt/divti3.zig").__divti3, linkage);
268271 @export("__modti3", @import("compiler_rt/modti3.zig").__modti3, linkage);
269272 @export("__multi3", @import("compiler_rt/multi3.zig").__multi3, linkage);
std/special/compiler_rt/arm/aeabi_dcmp.zig+6-6
......@@ -14,31 +14,31 @@ const ConditionalOperator = enum {
1414
1515pub nakedcc fn __aeabi_dcmpeq() noreturn {
1616 @setRuntimeSafety(false);
17 aeabi_dcmp(.Eq);
17 @inlineCall(aeabi_dcmp, .Eq);
1818 unreachable;
1919}
2020
2121pub nakedcc fn __aeabi_dcmplt() noreturn {
2222 @setRuntimeSafety(false);
23 aeabi_dcmp(.Lt);
23 @inlineCall(aeabi_dcmp, .Lt);
2424 unreachable;
2525}
2626
2727pub nakedcc fn __aeabi_dcmple() noreturn {
2828 @setRuntimeSafety(false);
29 aeabi_dcmp(.Le);
29 @inlineCall(aeabi_dcmp, .Le);
3030 unreachable;
3131}
3232
3333pub nakedcc fn __aeabi_dcmpge() noreturn {
3434 @setRuntimeSafety(false);
35 aeabi_dcmp(.Ge);
35 @inlineCall(aeabi_dcmp, .Ge);
3636 unreachable;
3737}
3838
3939pub nakedcc fn __aeabi_dcmpgt() noreturn {
4040 @setRuntimeSafety(false);
41 aeabi_dcmp(.Gt);
41 @inlineCall(aeabi_dcmp, .Gt);
4242 unreachable;
4343}
4444
......@@ -49,7 +49,7 @@ inline fn convert_dcmp_args_to_df2_args() void {
4949 );
5050}
5151
52inline fn aeabi_dcmp(comptime cond: ConditionalOperator) void {
52fn aeabi_dcmp(comptime cond: ConditionalOperator) void {
5353 @setRuntimeSafety(false);
5454 asm volatile (
5555 \\ push { r4, lr }
std/special/compiler_rt/arm/aeabi_fcmp.zig+6-6
......@@ -14,31 +14,31 @@ const ConditionalOperator = enum {
1414
1515pub nakedcc fn __aeabi_fcmpeq() noreturn {
1616 @setRuntimeSafety(false);
17 aeabi_fcmp(.Eq);
17 @inlineCall(aeabi_fcmp, .Eq);
1818 unreachable;
1919}
2020
2121pub nakedcc fn __aeabi_fcmplt() noreturn {
2222 @setRuntimeSafety(false);
23 aeabi_fcmp(.Lt);
23 @inlineCall(aeabi_fcmp, .Lt);
2424 unreachable;
2525}
2626
2727pub nakedcc fn __aeabi_fcmple() noreturn {
2828 @setRuntimeSafety(false);
29 aeabi_fcmp(.Le);
29 @inlineCall(aeabi_fcmp, .Le);
3030 unreachable;
3131}
3232
3333pub nakedcc fn __aeabi_fcmpge() noreturn {
3434 @setRuntimeSafety(false);
35 aeabi_fcmp(.Ge);
35 @inlineCall(aeabi_fcmp, .Ge);
3636 unreachable;
3737}
3838
3939pub nakedcc fn __aeabi_fcmpgt() noreturn {
4040 @setRuntimeSafety(false);
41 aeabi_fcmp(.Gt);
41 @inlineCall(aeabi_fcmp, .Gt);
4242 unreachable;
4343}
4444
......@@ -49,7 +49,7 @@ inline fn convert_fcmp_args_to_sf2_args() void {
4949 );
5050}
5151
52inline fn aeabi_fcmp(comptime cond: ConditionalOperator) void {
52fn aeabi_fcmp(comptime cond: ConditionalOperator) void {
5353 @setRuntimeSafety(false);
5454 asm volatile (
5555 \\ push { r4, lr }
test/tests.zig+239-57
......@@ -23,21 +23,183 @@ const runtime_safety = @import("runtime_safety.zig");
2323const translate_c = @import("translate_c.zig");
2424const gen_h = @import("gen_h.zig");
2525
26const cross_targets = [_]CrossTarget{
27 CrossTarget{
28 .os = .linux,
29 .arch = .x86_64,
30 .abi = .gnu,
26const TestTarget = struct {
27 target: Target = .Native,
28 mode: builtin.Mode = .Debug,
29 link_libc: bool = false,
30 single_threaded: bool = false,
31 disable_native: bool = false,
32};
33
34const test_targets = [_]TestTarget{
35 TestTarget{},
36 TestTarget{
37 .link_libc = true,
38 },
39 TestTarget{
40 .single_threaded = true,
41 },
42
43 TestTarget{
44 .target = Target{
45 .Cross = CrossTarget{
46 .os = .linux,
47 .arch = .x86_64,
48 .abi = .none,
49 },
50 },
51 },
52 TestTarget{
53 .target = Target{
54 .Cross = CrossTarget{
55 .os = .linux,
56 .arch = .x86_64,
57 .abi = .gnu,
58 },
59 },
60 .link_libc = true,
61 },
62 TestTarget{
63 .target = Target{
64 .Cross = CrossTarget{
65 .os = .linux,
66 .arch = .x86_64,
67 .abi = .musl,
68 },
69 },
70 .link_libc = true,
71 },
72
73 TestTarget{
74 .target = Target{
75 .Cross = CrossTarget{
76 .os = .linux,
77 .arch = builtin.Arch{ .aarch64 = builtin.Arch.Arm64.v8_5a },
78 .abi = .none,
79 },
80 },
81 },
82 TestTarget{
83 .target = Target{
84 .Cross = CrossTarget{
85 .os = .linux,
86 .arch = builtin.Arch{ .aarch64 = builtin.Arch.Arm64.v8_5a },
87 .abi = .musl,
88 },
89 },
90 .link_libc = true,
91 },
92 TestTarget{
93 .target = Target{
94 .Cross = CrossTarget{
95 .os = .linux,
96 .arch = builtin.Arch{ .aarch64 = builtin.Arch.Arm64.v8_5a },
97 .abi = .gnu,
98 },
99 },
100 .link_libc = true,
101 },
102
103 TestTarget{
104 .target = Target{
105 .Cross = CrossTarget{
106 .os = .linux,
107 .arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v8_5a },
108 .abi = .none,
109 },
110 },
111 },
112 // TODO https://github.com/ziglang/zig/issues/3286
113 //TestTarget{
114 // .target = Target{
115 // .Cross = CrossTarget{
116 // .os = .linux,
117 // .arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v8_5a },
118 // .abi = .musleabihf,
119 // },
120 // },
121 // .link_libc = true,
122 //},
123 // TODO https://github.com/ziglang/zig/issues/3287
124 //TestTarget{
125 // .target = Target{
126 // .Cross = CrossTarget{
127 // .os = .linux,
128 // .arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v8_5a },
129 // .abi = .gnueabihf,
130 // },
131 // },
132 // .link_libc = true,
133 //},
134
135 TestTarget{
136 .target = Target{
137 .Cross = CrossTarget{
138 .os = .macosx,
139 .arch = .x86_64,
140 .abi = .gnu,
141 },
142 },
143 // TODO https://github.com/ziglang/zig/issues/3295
144 .disable_native = true,
145 },
146
147 TestTarget{
148 .target = Target{
149 .Cross = CrossTarget{
150 .os = .windows,
151 .arch = .x86_64,
152 .abi = .msvc,
153 },
154 },
155 },
156
157 TestTarget{
158 .target = Target{
159 .Cross = CrossTarget{
160 .os = .windows,
161 .arch = .x86_64,
162 .abi = .gnu,
163 },
164 },
165 .link_libc = true,
31166 },
32 CrossTarget{
33 .os = .macosx,
34 .arch = .x86_64,
35 .abi = .gnu,
167
168 // Do the release tests last because they take a long time
169 TestTarget{
170 .mode = .ReleaseFast,
171 },
172 TestTarget{
173 .link_libc = true,
174 .mode = .ReleaseFast,
175 },
176 TestTarget{
177 .mode = .ReleaseFast,
178 .single_threaded = true,
179 },
180
181 TestTarget{
182 .mode = .ReleaseSafe,
183 },
184 TestTarget{
185 .link_libc = true,
186 .mode = .ReleaseSafe,
187 },
188 TestTarget{
189 .mode = .ReleaseSafe,
190 .single_threaded = true,
36191 },
37 CrossTarget{
38 .os = .windows,
39 .arch = .x86_64,
40 .abi = .msvc,
192
193 TestTarget{
194 .mode = .ReleaseSmall,
195 },
196 TestTarget{
197 .link_libc = true,
198 .mode = .ReleaseSmall,
199 },
200 TestTarget{
201 .mode = .ReleaseSmall,
202 .single_threaded = true,
41203 },
42204};
43205
......@@ -182,57 +344,77 @@ pub fn addPkgTests(
182344 name: []const u8,
183345 desc: []const u8,
184346 modes: []const Mode,
185 single_threaded_list: []const bool,
347 skip_single_threaded: bool,
186348 skip_non_native: bool,
349 skip_libc: bool,
350 is_wine_enabled: bool,
351 is_qemu_enabled: bool,
352 glibc_dir: ?[]const u8,
187353) *build.Step {
188354 const step = b.step(b.fmt("test-{}", name), desc);
189355
190 var targets = std.ArrayList(*const CrossTarget).init(b.allocator);
191 defer targets.deinit();
192 const host = CrossTarget{ .os = builtin.os, .arch = builtin.arch, .abi = builtin.abi };
193 targets.append(&host) catch unreachable;
194 for (cross_targets) |*t| {
195 if (t.os == builtin.os and t.arch == builtin.arch and t.abi == builtin.abi) continue;
196 targets.append(t) catch unreachable;
197 }
356 for (test_targets) |test_target| {
357 if (skip_non_native and test_target.target != .Native)
358 continue;
198359
199 for (targets.toSliceConst()) |test_target| {
200 const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch);
201 if (skip_non_native and !is_native)
360 if (skip_libc and test_target.link_libc)
361 continue;
362
363 if (test_target.link_libc and test_target.target.osRequiresLibC()) {
364 // This would be a redundant test.
365 continue;
366 }
367
368 if (skip_single_threaded and test_target.single_threaded)
369 continue;
370
371 const ArchTag = @TagType(builtin.Arch);
372 if (test_target.disable_native and
373 test_target.target.getOs() == builtin.os and
374 ArchTag(test_target.target.getArch()) == ArchTag(builtin.arch))
375 {
202376 continue;
203 for (modes) |mode| {
204 for ([_]bool{ false, true }) |link_libc| {
205 for (single_threaded_list) |single_threaded| {
206 if (link_libc and !is_native) {
207 // don't assume we have a cross-compiling libc set up
208 continue;
209 }
210 const these_tests = b.addTest(root_src);
211 these_tests.setNamePrefix(b.fmt(
212 "{}-{}-{}-{}-{}-{} ",
213 name,
214 @tagName(test_target.os),
215 @tagName(test_target.arch),
216 @tagName(mode),
217 if (link_libc) "c" else "bare",
218 if (single_threaded) "single" else "multi",
219 ));
220 these_tests.single_threaded = single_threaded;
221 these_tests.setFilter(test_filter);
222 these_tests.setBuildMode(mode);
223 if (!is_native) {
224 these_tests.setTarget(test_target.arch, test_target.os, test_target.abi);
225 }
226 if (link_libc) {
227 these_tests.linkSystemLibrary("c");
228 }
229 if (mem.eql(u8, name, "std")) {
230 these_tests.overrideStdDir("std");
231 }
232 step.dependOn(&these_tests.step);
233 }
234 }
235377 }
378
379 const want_this_mode = for (modes) |m| {
380 if (m == test_target.mode) break true;
381 } else false;
382 if (!want_this_mode) continue;
383
384 const libc_prefix = if (test_target.target.osRequiresLibC())
385 ""
386 else if (test_target.link_libc)
387 "c"
388 else
389 "bare";
390
391 const triple_prefix = if (test_target.target == .Native)
392 ([]const u8)("native")
393 else
394 test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
395
396 const these_tests = b.addTest(root_src);
397 these_tests.setNamePrefix(b.fmt(
398 "{}-{}-{}-{}-{} ",
399 name,
400 triple_prefix,
401 @tagName(test_target.mode),
402 libc_prefix,
403 if (test_target.single_threaded) "single" else "multi",
404 ));
405 these_tests.single_threaded = test_target.single_threaded;
406 these_tests.setFilter(test_filter);
407 these_tests.setBuildMode(test_target.mode);
408 these_tests.setTheTarget(test_target.target);
409 if (test_target.link_libc) {
410 these_tests.linkSystemLibrary("c");
411 }
412 these_tests.overrideStdDir("std");
413 these_tests.enable_wine = is_wine_enabled;
414 these_tests.enable_qemu = is_qemu_enabled;
415 these_tests.glibc_multi_install_dir = glibc_dir;
416
417 step.dependOn(&these_tests.step);
236418 }
237419 return step;
238420}