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 @@...@@ -1,4 +1,5 @@
1*.zig text eol=lf 1*.zig text eol=lf
2*.txt text eol=lf
2langref.html.in text eol=lf 3langref.html.in text eol=lf
3 4
4deps/* linguist-vendored 5deps/* linguist-vendored
build.zig+8-6
...@@ -70,6 +70,7 @@ pub fn build(b: *Builder) !void {...@@ -70,6 +70,7 @@ pub fn build(b: *Builder) !void {
70 const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release;70 const skip_release_fast = b.option(bool, "skip-release-fast", "Main test suite skips release-fast builds") orelse skip_release;
71 const skip_release_safe = b.option(bool, "skip-release-safe", "Main test suite skips release-safe builds") orelse skip_release;71 const skip_release_safe = b.option(bool, "skip-release-safe", "Main test suite skips release-safe builds") orelse skip_release;
72 const skip_non_native = b.option(bool, "skip-non-native", "Main test suite skips non-native builds") orelse false;72 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;
73 const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") orelse false;74 const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") orelse false;
74 if (!skip_self_hosted) {75 if (!skip_self_hosted) {
75 // TODO re-enable this after https://github.com/ziglang/zig/issues/237776 // TODO re-enable this after https://github.com/ziglang/zig/issues/2377
...@@ -96,6 +97,10 @@ pub fn build(b: *Builder) !void {...@@ -96,6 +97,10 @@ pub fn build(b: *Builder) !void {
9697
97 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");98 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
99 const test_stage2_step = b.step("test-stage2", "Run the stage2 compiler tests");104 const test_stage2_step = b.step("test-stage2", "Run the stage2 compiler tests");
100 test_stage2_step.dependOn(&test_stage2.step);105 test_stage2_step.dependOn(&test_stage2.step);
101106
...@@ -122,19 +127,16 @@ pub fn build(b: *Builder) !void {...@@ -122,19 +127,16 @@ pub fn build(b: *Builder) !void {
122 }127 }
123 const modes = chosen_modes[0..chosen_mode_index];128 const modes = chosen_modes[0..chosen_mode_index];
124129
125 const multi_and_single = [_]bool{ false, true };
126 const just_multi = [_]bool{false};
127
128 // run stage1 `zig fmt` on this build.zig file just to make sure it works130 // run stage1 `zig fmt` on this build.zig file just to make sure it works
129 test_step.dependOn(&fmt_build_zig.step);131 test_step.dependOn(&fmt_build_zig.step);
130 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");132 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");
131 fmt_step.dependOn(&fmt_build_zig.step);133 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
139 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));141 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
140 test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));142 test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));
ci/azure/linux_script+2-2
...@@ -12,7 +12,7 @@ sudo apt-get update -q...@@ -12,7 +12,7 @@ sudo apt-get update -q
1212
13sudo apt-get remove -y llvm-*13sudo apt-get remove -y llvm-*
14sudo rm -rf /usr/local/*14sudo rm -rf /usr/local/*
15sudo apt-get install -y libxml2-dev libclang-9-dev llvm-9 llvm-9-dev cmake s3cmd gcc-7 g++-715sudo apt-get install -y libxml2-dev libclang-9-dev llvm-9 llvm-9-dev cmake s3cmd gcc-7 g++-7 qemu
1616
17export CC=gcc-717export CC=gcc-7
18export CXX=g++-718export CXX=g++-7
...@@ -20,7 +20,7 @@ mkdir build...@@ -20,7 +20,7 @@ mkdir build
20cd build20cd build
21cmake .. -DCMAKE_BUILD_TYPE=Release21cmake .. -DCMAKE_BUILD_TYPE=Release
22make -j2 install22make -j2 install
23./zig build --build-file ../build.zig test23./zig build test -Denable-qemu
2424
25if [ "${BUILD_REASON}" != "PullRequest" ]; then25if [ "${BUILD_REASON}" != "PullRequest" ]; then
26 ARTIFACTSDIR="$BUILDDIR/artifacts"26 ARTIFACTSDIR="$BUILDDIR/artifacts"
ci/azure/macos_script+1-1
...@@ -70,7 +70,7 @@ mkdir build...@@ -70,7 +70,7 @@ mkdir build
70cd build70cd build
71cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_INSTALL_PREFIX=$(pwd)/release -DZIG_STATIC=ON71cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_INSTALL_PREFIX=$(pwd)/release -DZIG_STATIC=ON
72make $JOBS install72make $JOBS install
73release/bin/zig build --build-file ../build.zig test73release/bin/zig build test
7474
75if [ "${BUILD_REASON}" != "PullRequest" ]; then75if [ "${BUILD_REASON}" != "PullRequest" ]; then
76 mv ../LICENSE release/76 mv ../LICENSE release/
ci/azure/pipelines.yml+1-1
...@@ -27,7 +27,7 @@ jobs:...@@ -27,7 +27,7 @@ jobs:
27 displayName: 'Build and test'27 displayName: 'Build and test'
28- job: BuildWindows28- job: BuildWindows
29 pool:29 pool:
30 vmImage: 'vs2017-win2016'30 vmImage: 'windows-2019'
3131
32 timeoutInMinutes: 36032 timeoutInMinutes: 360
3333
ci/azure/windows_script.bat+6-5
...@@ -10,17 +10,18 @@ SET "PATH=%PREVPATH%"...@@ -10,17 +10,18 @@ SET "PATH=%PREVPATH%"
10SET "MSYSTEM=%PREVMSYSTEM%"10SET "MSYSTEM=%PREVMSYSTEM%"
1111
12SET "ZIGBUILDDIR=%SRCROOT%\build"12SET "ZIGBUILDDIR=%SRCROOT%\build"
13SET "ZIGINSTALLDIR=%ZIGBUILDDIR%\release"13SET "ZIGINSTALLDIR=%ZIGBUILDDIR%\dist"
14SET "ZIGPREFIXPATH=%SRCROOT%\llvm+clang-9.0.0-win64-msvc-release"14SET "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" x6416call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
1717
18mkdir %ZIGBUILDDIR%18mkdir %ZIGBUILDDIR%
19cd %ZIGBUILDDIR%19cd %ZIGBUILDDIR%
20cmake.exe .. -Thost=x64 -G"Visual Studio 15 2017 Win64" "-DCMAKE_INSTALL_PREFIX=%ZIGINSTALLDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release || exit /b20REM Here we use MinSizeRel instead of Release to work around https://github.com/ziglang/zig/issues/3024
21msbuild /p:Configuration=Release INSTALL.vcxproj || exit /b21cmake.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 /b24"%ZIGINSTALLDIR%\bin\zig.exe" build test || exit /b
2425
25set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"26set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
26SET "MSYSTEM=MINGW64"27SET "MSYSTEM=MINGW64"
ci/azure/windows_upload+6-7
...@@ -6,16 +6,15 @@ set -e...@@ -6,16 +6,15 @@ set -e
6if [ "${BUILD_REASON}" != "PullRequest" ]; then6if [ "${BUILD_REASON}" != "PullRequest" ]; then
7 cd "$ZIGBUILDDIR"7 cd "$ZIGBUILDDIR"
88
9 rm release/*.exe9 mv ../LICENSE dist/
10 mv ../LICENSE release/10 mv ../zig-cache/langref.html dist/
11 mv ../zig-cache/langref.html release/11 mv dist/bin/zig.exe dist/
12 mv release/bin/zig.exe release/12 rmdir dist/bin
13 rmdir release/bin
1413
15 VERSION=$(release/zig.exe version)14 VERSION=$(dist/zig.exe version)
16 DIRNAME="zig-windows-x86_64-$VERSION"15 DIRNAME="zig-windows-x86_64-$VERSION"
17 TARBALL="$DIRNAME.zip"16 TARBALL="$DIRNAME.zip"
18 mv release "$DIRNAME"17 mv dist "$DIRNAME"
19 7z a "$TARBALL" "$DIRNAME"18 7z a "$TARBALL" "$DIRNAME"
2019
21 mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"20 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")...@@ -1938,32 +1938,6 @@ __buildmov(__movsd, unsigned __LONG32, "d")
1938#define __INTRINSIC_DEFINED___movsd1938#define __INTRINSIC_DEFINED___movsd
1939#endif /* __INTRINSIC_PROLOG */1939#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
1967#endif /* defined(__x86_64__) || defined(_AMD64_) || defined(__i386__) || defined(_X86_) */1941#endif /* defined(__x86_64__) || defined(_AMD64_) || defined(__i386__) || defined(_X86_) */
19681942
1969/* ***************************************************** */1943/* ***************************************************** */
src/buffer.cpp-1
...@@ -61,7 +61,6 @@ void buf_appendf(Buf *buf, const char *format, ...) {...@@ -61,7 +61,6 @@ void buf_appendf(Buf *buf, const char *format, ...) {
6161
62// these functions are not static inline so they can be better used as template parameters62// these functions are not static inline so they can be better used as template parameters
63bool buf_eql_buf(Buf *buf, Buf *other) {63bool buf_eql_buf(Buf *buf, Buf *other) {
64 assert(buf->list.length);
65 return buf_eql_mem(buf, buf_ptr(other), buf_len(other));64 return buf_eql_mem(buf, buf_ptr(other), buf_len(other));
66}65}
6766
src/glibc.cpp+22-7
...@@ -50,7 +50,7 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo...@@ -50,7 +50,7 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
50 }50 }
5151
52 {52 {
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"));
54 for (;;) {54 for (;;) {
55 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);55 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
56 if (!opt_component.is_some) break;56 if (!opt_component.is_some) break;
...@@ -65,7 +65,7 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo...@@ -65,7 +65,7 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
65 }65 }
66 }66 }
67 {67 {
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"));
69 for (;;) {69 for (;;) {
70 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);70 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
71 if (!opt_component.is_some) break;71 if (!opt_component.is_some) break;
...@@ -91,17 +91,19 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo...@@ -91,17 +91,19 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
91 }91 }
92 }92 }
93 {93 {
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"));
95 ZigGLibCVerList *ver_list_base = nullptr;95 ZigGLibCVerList *ver_list_base = nullptr;
96 int line_num = 0;
96 for (;;) {97 for (;;) {
97 if (ver_list_base == nullptr) {98 if (ver_list_base == nullptr) {
99 line_num += 1;
98 Optional<Slice<uint8_t>> opt_line = SplitIterator_next_separate(&it);100 Optional<Slice<uint8_t>> opt_line = SplitIterator_next_separate(&it);
99 if (!opt_line.is_some) break;101 if (!opt_line.is_some) break;
100102
101 ver_list_base = allocate<ZigGLibCVerList>(glibc_abi->all_functions.length);103 ver_list_base = allocate<ZigGLibCVerList>(glibc_abi->all_functions.length);
102 ZigTarget *target = allocate<ZigTarget>(1);
103 SplitIterator line_it = memSplit(opt_line.value, str(" "));104 SplitIterator line_it = memSplit(opt_line.value, str(" "));
104 for (;;) {105 for (;;) {
106 ZigTarget *target = allocate<ZigTarget>(1);
105 Optional<Slice<uint8_t>> opt_target = SplitIterator_next(&line_it);107 Optional<Slice<uint8_t>> opt_target = SplitIterator_next(&line_it);
106 if (!opt_target.is_some) break;108 if (!opt_target.is_some) break;
107109
...@@ -122,7 +124,19 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo...@@ -122,7 +124,19 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
122 target->os = OsLinux;124 target->os = OsLinux;
123125
124 err = target_parse_abi(&target->abi, (char*)opt_abi.value.ptr, opt_abi.value.len);126 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
127 glibc_abi->version_table.put(target, ver_list_base);141 glibc_abi->version_table.put(target, ver_list_base);
128 }142 }
...@@ -130,6 +144,7 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo...@@ -130,6 +144,7 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
130 }144 }
131 for (size_t fn_i = 0; fn_i < glibc_abi->all_functions.length; fn_i += 1) {145 for (size_t fn_i = 0; fn_i < glibc_abi->all_functions.length; fn_i += 1) {
132 ZigGLibCVerList *ver_list = &ver_list_base[fn_i];146 ZigGLibCVerList *ver_list = &ver_list_base[fn_i];
147 line_num += 1;
133 Optional<Slice<uint8_t>> opt_line = SplitIterator_next_separate(&it);148 Optional<Slice<uint8_t>> opt_line = SplitIterator_next_separate(&it);
134 assert(opt_line.is_some);149 assert(opt_line.is_some);
135150
...@@ -266,7 +281,7 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con...@@ -266,7 +281,7 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
266 // - If there are no versions, don't emit it281 // - If there are no versions, don't emit it
267 // - Take the greatest one <= than the target one282 // - Take the greatest one <= than the target one
268 // - If none of them is <= than the283 // - 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
270 if (ver_list->len == 0) continue;285 if (ver_list->len == 0) continue;
271 uint8_t chosen_def_ver_index = 255;286 uint8_t chosen_def_ver_index = 255;
272 for (uint8_t ver_i = 0; ver_i < ver_list->len; ver_i += 1) {287 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...@@ -322,7 +337,7 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
322 codegen_set_lib_version(child_gen, lib->sover, 0, 0);337 codegen_set_lib_version(child_gen, lib->sover, 0, 0);
323 child_gen->is_dynamic = true;338 child_gen->is_dynamic = true;
324 child_gen->is_dummy_so = true;339 child_gen->is_dummy_so = true;
325 child_gen->version_script_path = map_file_path; 340 child_gen->version_script_path = map_file_path;
326 child_gen->enable_cache = false;341 child_gen->enable_cache = false;
327 child_gen->output_dir = dummy_dir;342 child_gen->output_dir = dummy_dir;
328 codegen_build_and_link(child_gen);343 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) {...@@ -1295,6 +1295,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
1295 c_file->args.append("-include");1295 c_file->args.append("-include");
1296 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));1296 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));
1297 c_file->args.append("-DMODULE_NAME=libc");1297 c_file->args.append("-DMODULE_NAME=libc");
1298 c_file->args.append("-Wno-nonportable-include-path");
1298 c_file->args.append("-include");1299 c_file->args.append("-include");
1299 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));1300 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));
1300 c_file->args.append("-DTOP_NAMESPACE=glibc");1301 c_file->args.append("-DTOP_NAMESPACE=glibc");
...@@ -1321,6 +1322,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {...@@ -1321,6 +1322,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
1321 c_file->args.append("-include");1322 c_file->args.append("-include");
1322 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));1323 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));
1323 c_file->args.append("-DMODULE_NAME=libc");1324 c_file->args.append("-DMODULE_NAME=libc");
1325 c_file->args.append("-Wno-nonportable-include-path");
1324 c_file->args.append("-include");1326 c_file->args.append("-include");
1325 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));1327 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));
1326 c_file->args.append("-DPIC");1328 c_file->args.append("-DPIC");
...@@ -1377,6 +1379,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {...@@ -1377,6 +1379,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
1377 c_file->args.append("-include");1379 c_file->args.append("-include");
1378 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));1380 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));
1379 c_file->args.append("-DMODULE_NAME=libc");1381 c_file->args.append("-DMODULE_NAME=libc");
1382 c_file->args.append("-Wno-nonportable-include-path");
1380 c_file->args.append("-include");1383 c_file->args.append("-include");
1381 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));1384 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));
1382 c_file->args.append("-DPIC");1385 c_file->args.append("-DPIC");
...@@ -1420,6 +1423,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {...@@ -1420,6 +1423,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) {
1420 c_file->args.append("-include");1423 c_file->args.append("-include");
1421 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));1424 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));
1422 c_file->args.append("-DMODULE_NAME=libc");1425 c_file->args.append("-DMODULE_NAME=libc");
1426 c_file->args.append("-Wno-nonportable-include-path");
1423 c_file->args.append("-include");1427 c_file->args.append("-include");
1424 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));1428 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));
1425 c_file->args.append("-DPIC");1429 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...@@ -116,7 +116,7 @@ static void os_spawn_process_posix(ZigList<const char *> &args, Termination *ter
116 pid_t pid;116 pid_t pid;
117 int rc = posix_spawnp(&pid, args.at(0), nullptr, nullptr, const_cast<char *const*>(argv), environ);117 int rc = posix_spawnp(&pid, args.at(0), nullptr, nullptr, const_cast<char *const*>(argv), environ);
118 if (rc != 0) {118 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));
120 }120 }
121121
122 int status;122 int status;
src/util.cpp+1-8
...@@ -18,17 +18,10 @@ void zig_panic(const char *format, ...) {...@@ -18,17 +18,10 @@ void zig_panic(const char *format, ...) {
18 vfprintf(stderr, format, ap);18 vfprintf(stderr, format, ap);
19 fflush(stderr);19 fflush(stderr);
20 va_end(ap);20 va_end(ap);
21 stage2_panic(nullptr, 0);21 stage2_panic("", 0);
22 abort();22 abort();
23}23}
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
32uint32_t int_hash(int i) {25uint32_t int_hash(int i) {
33 return (uint32_t)(i % UINT32_MAX);26 return (uint32_t)(i % UINT32_MAX);
34}27}
src/util.hpp+8-2
...@@ -43,15 +43,21 @@ ATTRIBUTE_NORETURN...@@ -43,15 +43,21 @@ ATTRIBUTE_NORETURN
43ATTRIBUTE_PRINTF(1, 2)43ATTRIBUTE_PRINTF(1, 2)
44void zig_panic(const char *format, ...);44void 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
46#ifdef _WIN3252#ifdef _WIN32
47#define __func__ __FUNCTION__53#define __func__ __FUNCTION__
48#endif54#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
52// Assertions in stage1 are always on, and they call zig @panic.58// Assertions in stage1 are always on, and they call zig @panic.
53#undef assert59#undef assert
54void assert(bool ok);60#define assert(ok) zig_assert(ok, __FILE__, __LINE__, __func__)
5561
56#if defined(_MSC_VER)62#if defined(_MSC_VER)
57static inline int clzll(unsigned long long mask) {63static inline int clzll(unsigned long long mask) {
std/build.zig+175-1
...@@ -1015,6 +1015,7 @@ pub const Target = union(enum) {...@@ -1015,6 +1015,7 @@ pub const Target = union(enum) {
1015 => return .msvc,1015 => return .msvc,
1016 .linux,1016 .linux,
1017 .wasi,1017 .wasi,
1018 .emscripten,
1018 => return .musl,1019 => return .musl,
1019 }1020 }
1020 }1021 }
...@@ -1175,6 +1176,13 @@ pub const Target = union(enum) {...@@ -1175,6 +1176,13 @@ pub const Target = union(enum) {
1175 };1176 };
1176 }1177 }
11771178
1179 pub fn isLinux(self: Target) bool {
1180 return switch (self.getOs()) {
1181 .linux => true,
1182 else => false,
1183 };
1184 }
1185
1178 pub fn isUefi(self: Target) bool {1186 pub fn isUefi(self: Target) bool {
1179 return switch (self.getOs()) {1187 return switch (self.getOs()) {
1180 .uefi => true,1188 .uefi => true,
...@@ -1196,9 +1204,125 @@ pub const Target = union(enum) {...@@ -1196,9 +1204,125 @@ pub const Target = union(enum) {
1196 };1204 };
1197 }1205 }
11981206
1207 pub fn isNetBSD(self: Target) bool {
1208 return switch (self.getOs()) {
1209 .netbsd => true,
1210 else => false,
1211 };
1212 }
1213
1199 pub fn wantSharedLibSymLinks(self: Target) bool {1214 pub fn wantSharedLibSymLinks(self: Target) bool {
1200 return !self.isWindows();1215 return !self.isWindows();
1201 }1216 }
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 }
1202};1326};
12031327
1204const Pkg = struct {1328const Pkg = struct {
...@@ -1266,6 +1390,7 @@ pub const LibExeObjStep = struct {...@@ -1266,6 +1390,7 @@ pub const LibExeObjStep = struct {
1266 include_dirs: ArrayList(IncludeDir),1390 include_dirs: ArrayList(IncludeDir),
1267 output_dir: ?[]const u8,1391 output_dir: ?[]const u8,
1268 need_system_paths: bool,1392 need_system_paths: bool,
1393 is_linking_libc: bool = false,
12691394
1270 installed_path: ?[]const u8,1395 installed_path: ?[]const u8,
1271 install_step: ?*InstallArtifactStep,1396 install_step: ?*InstallArtifactStep,
...@@ -1275,6 +1400,20 @@ pub const LibExeObjStep = struct {...@@ -1275,6 +1400,20 @@ pub const LibExeObjStep = struct {
12751400
1276 valgrind_support: ?bool = null,1401 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
1278 const LinkObject = union(enum) {1417 const LinkObject = union(enum) {
1279 StaticPath: []const u8,1418 StaticPath: []const u8,
1280 OtherStep: *LibExeObjStep,1419 OtherStep: *LibExeObjStep,
...@@ -1504,7 +1643,9 @@ pub const LibExeObjStep = struct {...@@ -1504,7 +1643,9 @@ pub const LibExeObjStep = struct {
15041643
1505 pub fn linkSystemLibrary(self: *LibExeObjStep, name: []const u8) void {1644 pub fn linkSystemLibrary(self: *LibExeObjStep, name: []const u8) void {
1506 self.link_objects.append(LinkObject{ .SystemLib = self.builder.dupe(name) }) catch unreachable;1645 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 {
1508 self.need_system_paths = true;1649 self.need_system_paths = true;
1509 }1650 }
1510 }1651 }
...@@ -1840,6 +1981,11 @@ pub const LibExeObjStep = struct {...@@ -1840,6 +1981,11 @@ pub const LibExeObjStep = struct {
1840 zig_args.append(builder.pathFromRoot(linker_script)) catch unreachable;1981 zig_args.append(builder.pathFromRoot(linker_script)) catch unreachable;
1841 }1982 }
18421983
1984 if (self.dynamic_linker) |dynamic_linker| {
1985 try zig_args.append("--dynamic-linker");
1986 try zig_args.append(dynamic_linker);
1987 }
1988
1843 if (self.version_script) |version_script| {1989 if (self.version_script) |version_script| {
1844 try zig_args.append("--version-script");1990 try zig_args.append("--version-script");
1845 try zig_args.append(builder.pathFromRoot(version_script));1991 try zig_args.append(builder.pathFromRoot(version_script));
...@@ -1854,6 +2000,34 @@ pub const LibExeObjStep = struct {...@@ -1854,6 +2000,34 @@ pub const LibExeObjStep = struct {
1854 try zig_args.append("--test-cmd-bin");2000 try zig_args.append("--test-cmd-bin");
1855 }2001 }
1856 }2002 }
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 },
1857 }2031 }
1858 for (self.packages.toSliceConst()) |pkg| {2032 for (self.packages.toSliceConst()) |pkg| {
1859 zig_args.append("--pkg-begin") catch unreachable;2033 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;...@@ -63,7 +63,7 @@ pub extern "c" fn close(fd: fd_t) c_int;
63pub extern "c" fn @"close$NOCANCEL"(fd: fd_t) c_int;63pub extern "c" fn @"close$NOCANCEL"(fd: fd_t) c_int;
64pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;64pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
65pub extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;65pub 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;
67pub extern "c" fn open(path: [*]const u8, oflag: c_uint, ...) c_int;67pub extern "c" fn open(path: [*]const u8, oflag: c_uint, ...) c_int;
68pub extern "c" fn openat(fd: c_int, path: [*]const u8, oflag: c_uint, ...) c_int;68pub extern "c" fn openat(fd: c_int, path: [*]const u8, oflag: c_uint, ...) c_int;
69pub extern "c" fn raise(sig: c_int) c_int;69pub 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 {...@@ -382,6 +382,10 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {
382}382}
383383
384test "fmt.parseFloat" {384test "fmt.parseFloat" {
385 if (@import("builtin").arch == .arm) {
386 // TODO https://github.com/ziglang/zig/issues/3289
387 return error.SkipZigTest;
388 }
385 const testing = std.testing;389 const testing = std.testing;
386 const expect = testing.expect;390 const expect = testing.expect;
387 const expectEqual = testing.expectEqual;391 const expectEqual = testing.expectEqual;
std/fs/path.zig+8
...@@ -646,6 +646,10 @@ test "resolve" {...@@ -646,6 +646,10 @@ test "resolve" {
646}646}
647647
648test "resolveWindows" {648test "resolveWindows" {
649 if (@import("builtin").arch == .aarch64) {
650 // TODO https://github.com/ziglang/zig/issues/3288
651 return error.SkipZigTest;
652 }
649 if (windows.is_the_target) {653 if (windows.is_the_target) {
650 const cwd = try process.getCwdAlloc(debug.global_allocator);654 const cwd = try process.getCwdAlloc(debug.global_allocator);
651 const parsed_cwd = windowsParsePath(cwd);655 const parsed_cwd = windowsParsePath(cwd);
...@@ -1086,6 +1090,10 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![...@@ -1086,6 +1090,10 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![
1086}1090}
10871091
1088test "relative" {1092test "relative" {
1093 if (@import("builtin").arch == .aarch64) {
1094 // TODO https://github.com/ziglang/zig/issues/3288
1095 return error.SkipZigTest;
1096 }
1089 testRelativeWindows("c:/blah\\blah", "d:/games", "D:\\games");1097 testRelativeWindows("c:/blah\\blah", "d:/games", "D:\\games");
1090 testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa", "..");1098 testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa", "..");
1091 testRelativeWindows("c:/aaaa/bbbb", "c:/cccc", "..\\..\\cccc");1099 testRelativeWindows("c:/aaaa/bbbb", "c:/cccc", "..\\..\\cccc");
std/io/test.zig+4
...@@ -11,6 +11,10 @@ const fs = std.fs;...@@ -11,6 +11,10 @@ const fs = std.fs;
11const File = std.fs.File;11const File = std.fs.File;
1212
13test "write a file, read it, then delete it" {13test "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 }
14 var raw_bytes: [200 * 1024]u8 = undefined;18 var raw_bytes: [200 * 1024]u8 = undefined;
15 var allocator = &std.heap.FixedBufferAllocator.init(raw_bytes[0..]).allocator;19 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 {...@@ -43,6 +43,8 @@ pub const mach_timebase_info_data = extern struct {
43 denom: u32,43 denom: u32,
44};44};
4545
46pub const off_t = i64;
47
46/// Renamed to Stat to not conflict with the stat function.48/// Renamed to Stat to not conflict with the stat function.
47/// atime, mtime, and ctime have functions to return `timespec`,49/// atime, mtime, and ctime have functions to return `timespec`,
48/// because although this is a POSIX API, the layout and names of50/// because although this is a POSIX API, the layout and names of
...@@ -65,7 +67,7 @@ pub const Stat = extern struct {...@@ -65,7 +67,7 @@ pub const Stat = extern struct {
65 ctimensec: isize,67 ctimensec: isize,
66 birthtimesec: isize,68 birthtimesec: isize,
67 birthtimensec: isize,69 birthtimensec: isize,
68 size: i64,70 size: off_t,
69 blocks: i64,71 blocks: i64,
70 blksize: i32,72 blksize: i32,
71 flags: u32,73 flags: u32,
std/os/bits/freebsd.zig+3-1
...@@ -73,6 +73,8 @@ pub const msghdr_const = extern struct {...@@ -73,6 +73,8 @@ pub const msghdr_const = extern struct {
73 msg_flags: i32,73 msg_flags: i32,
74};74};
7575
76pub const off_t = i64;
77
76/// Renamed to Stat to not conflict with the stat function.78/// Renamed to Stat to not conflict with the stat function.
77/// atime, mtime, and ctime have functions to return `timespec`,79/// atime, mtime, and ctime have functions to return `timespec`,
78/// because although this is a POSIX API, the layout and names of80/// because although this is a POSIX API, the layout and names of
...@@ -96,7 +98,7 @@ pub const Stat = extern struct {...@@ -96,7 +98,7 @@ pub const Stat = extern struct {
96 ctim: timespec,98 ctim: timespec,
97 birthtim: timespec,99 birthtim: timespec,
98100
99 size: i64,101 size: off_t,
100 blocks: i64,102 blocks: i64,
101 blksize: isize,103 blksize: isize,
102 flags: u32,104 flags: u32,
std/os/bits/linux/arm-eabi.zig+3-1
...@@ -511,6 +511,8 @@ pub const msghdr_const = extern struct {...@@ -511,6 +511,8 @@ pub const msghdr_const = extern struct {
511 msg_flags: i32,511 msg_flags: i32,
512};512};
513513
514pub const off_t = i64;
515
514/// Renamed to Stat to not conflict with the stat function.516/// Renamed to Stat to not conflict with the stat function.
515/// atime, mtime, and ctime have functions to return `timespec`,517/// atime, mtime, and ctime have functions to return `timespec`,
516/// because although this is a POSIX API, the layout and names of518/// because although this is a POSIX API, the layout and names of
...@@ -527,7 +529,7 @@ pub const Stat = extern struct {...@@ -527,7 +529,7 @@ pub const Stat = extern struct {
527 gid: u32,529 gid: u32,
528 rdev: u64,530 rdev: u64,
529 __rdev_padding: u32,531 __rdev_padding: u32,
530 size: i64,532 size: off_t,
531 blksize: i32,533 blksize: i32,
532 blocks: u64,534 blocks: u64,
533 atim: timespec,535 atim: timespec,
std/os/bits/linux/arm64.zig+26-16
...@@ -1,11 +1,13 @@...@@ -1,11 +1,13 @@
1// arm64-specific declarations that are intended to be imported into the POSIX namespace.1// arm64-specific declarations that are intended to be imported into the POSIX namespace.
2// This does include Linux-only APIs.2// This does include Linux-only APIs.
33
4const std = @import("../../std.zig");4const std = @import("../../../std.zig");
5const linux = std.os.linux;5const linux = std.os.linux;
6const socklen_t = linux.socklen_t;6const socklen_t = linux.socklen_t;
7const iovec = linux.iovec;7const iovec = linux.iovec;
8const iovec_const = linux.iovec_const;8const iovec_const = linux.iovec_const;
9const uid_t = linux.uid_t;
10const gid_t = linux.gid_t;
911
10pub const SYS_io_setup = 0;12pub const SYS_io_setup = 0;
11pub const SYS_io_destroy = 1;13pub const SYS_io_destroy = 1;
...@@ -382,6 +384,15 @@ pub const msghdr_const = extern struct {...@@ -382,6 +384,15 @@ pub const msghdr_const = extern struct {
382 msg_flags: i32,384 msg_flags: i32,
383};385};
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
385/// Renamed to Stat to not conflict with the stat function.396/// Renamed to Stat to not conflict with the stat function.
386/// atime, mtime, and ctime have functions to return `timespec`,397/// atime, mtime, and ctime have functions to return `timespec`,
387/// because although this is a POSIX API, the layout and names of398/// because although this is a POSIX API, the layout and names of
...@@ -389,23 +400,22 @@ pub const msghdr_const = extern struct {...@@ -389,23 +400,22 @@ pub const msghdr_const = extern struct {
389/// in C, macros are used to hide the differences. Here we use400/// in C, macros are used to hide the differences. Here we use
390/// methods to accomplish this.401/// methods to accomplish this.
391pub const Stat = extern struct {402pub const Stat = extern struct {
392 dev: u64,403 dev: dev_t,
393 ino: u64,404 ino: ino_t,
394 nlink: usize,405 mode: mode_t,
395406 nlink: nlink_t,
396 mode: u32,407 uid: uid_t,
397 uid: u32,408 gid: gid_t,
398 gid: u32,409 rdev: dev_t,
399 __pad0: u32,410 __pad: usize,
400 rdev: u64,411 size: off_t,
401 size: i64,412 blksize: blksize_t,
402 blksize: isize,413 __pad2: i32,
403 blocks: i64,414 blocks: blkcnt_t,
404
405 atim: timespec,415 atim: timespec,
406 mtim: timespec,416 mtim: timespec,
407 ctim: timespec,417 ctim: timespec,
408 __unused: [3]isize,418 __unused: [2]u32,
409419
410 pub fn atime(self: Stat) timespec {420 pub fn atime(self: Stat) timespec {
411 return self.atim;421 return self.atim;
...@@ -421,7 +431,7 @@ pub const Stat = extern struct {...@@ -421,7 +431,7 @@ pub const Stat = extern struct {
421};431};
422432
423pub const timespec = extern struct {433pub const timespec = extern struct {
424 tv_sec: isize,434 tv_sec: time_t,
425 tv_nsec: isize,435 tv_nsec: isize,
426};436};
427437
std/os/bits/linux/x86_64.zig+3-1
...@@ -479,6 +479,8 @@ pub const msghdr_const = extern struct {...@@ -479,6 +479,8 @@ pub const msghdr_const = extern struct {
479 msg_flags: i32,479 msg_flags: i32,
480};480};
481481
482pub const off_t = i64;
483
482/// Renamed to Stat to not conflict with the stat function.484/// Renamed to Stat to not conflict with the stat function.
483/// atime, mtime, and ctime have functions to return `timespec`,485/// atime, mtime, and ctime have functions to return `timespec`,
484/// because although this is a POSIX API, the layout and names of486/// because although this is a POSIX API, the layout and names of
...@@ -495,7 +497,7 @@ pub const Stat = extern struct {...@@ -495,7 +497,7 @@ pub const Stat = extern struct {
495 gid: u32,497 gid: u32,
496 __pad0: u32,498 __pad0: u32,
497 rdev: u64,499 rdev: u64,
498 size: i64,500 size: off_t,
499 blksize: isize,501 blksize: isize,
500 blocks: i64,502 blocks: i64,
501503
std/os/bits/netbsd.zig+3-1
...@@ -73,6 +73,8 @@ pub const msghdr_const = extern struct {...@@ -73,6 +73,8 @@ pub const msghdr_const = extern struct {
73 msg_flags: i32,73 msg_flags: i32,
74};74};
7575
76pub const off_t = i64;
77
76/// Renamed to Stat to not conflict with the stat function.78/// Renamed to Stat to not conflict with the stat function.
77/// atime, mtime, and ctime have functions to return `timespec`,79/// atime, mtime, and ctime have functions to return `timespec`,
78/// because although this is a POSIX API, the layout and names of80/// because although this is a POSIX API, the layout and names of
...@@ -94,7 +96,7 @@ pub const Stat = extern struct {...@@ -94,7 +96,7 @@ pub const Stat = extern struct {
94 ctim: timespec,96 ctim: timespec,
95 birthtim: timespec,97 birthtim: timespec,
9698
97 size: i64,99 size: off_t,
98 blocks: i64,100 blocks: i64,
99 blksize: isize,101 blksize: isize,
100 flags: u32,102 flags: u32,
std/os/test.zig+4
...@@ -95,6 +95,10 @@ test "cpu count" {...@@ -95,6 +95,10 @@ test "cpu count" {
95}95}
9696
97test "AtomicFile" {97test "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 }
98 var buffer: [1024]u8 = undefined;102 var buffer: [1024]u8 = undefined;
99 const allocator = &std.heap.FixedBufferAllocator.init(buffer[0..]).allocator;103 const allocator = &std.heap.FixedBufferAllocator.init(buffer[0..]).allocator;
100 const test_out_file = "tmp_atomic_file_test_dest.txt";104 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 {...@@ -511,6 +511,11 @@ fn testCompare(l: *Node, r: *Node) mem.Compare {
511}511}
512512
513test "rb" {513test "rb" {
514 if (@import("builtin").arch == .aarch64) {
515 // TODO https://github.com/ziglang/zig/issues/3288
516 return error.SkipZigTest;
517 }
518
514 var tree: Tree = undefined;519 var tree: Tree = undefined;
515 var ns: [10]testNumber = undefined;520 var ns: [10]testNumber = undefined;
516 ns[0].value = 42;521 ns[0].value = 42;
...@@ -571,6 +576,10 @@ test "inserting and looking up" {...@@ -571,6 +576,10 @@ test "inserting and looking up" {
571}576}
572577
573test "multiple inserts, followed by calling first and last" {578test "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 }
574 var tree: Tree = undefined;583 var tree: Tree = undefined;
575 tree.init(testCompare);584 tree.init(testCompare);
576 var zeroth: testNumber = undefined;585 var zeroth: testNumber = undefined;
std/special/compiler_rt.zig+7-4
...@@ -143,7 +143,7 @@ comptime {...@@ -143,7 +143,7 @@ comptime {
143 @export("__negsf2", @import("compiler_rt/negXf2.zig").__negsf2, linkage);143 @export("__negsf2", @import("compiler_rt/negXf2.zig").__negsf2, linkage);
144 @export("__negdf2", @import("compiler_rt/negXf2.zig").__negdf2, linkage);144 @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) {
147 @export("__aeabi_unwind_cpp_pr0", __aeabi_unwind_cpp_pr0, strong_linkage);147 @export("__aeabi_unwind_cpp_pr0", __aeabi_unwind_cpp_pr0, strong_linkage);
148 @export("__aeabi_unwind_cpp_pr1", __aeabi_unwind_cpp_pr1, linkage);148 @export("__aeabi_unwind_cpp_pr1", __aeabi_unwind_cpp_pr1, linkage);
149 @export("__aeabi_unwind_cpp_pr2", __aeabi_unwind_cpp_pr2, linkage);149 @export("__aeabi_unwind_cpp_pr2", __aeabi_unwind_cpp_pr2, linkage);
...@@ -233,7 +233,7 @@ comptime {...@@ -233,7 +233,7 @@ comptime {
233 @export("__aeabi_dcmpgt", @import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpgt, linkage);233 @export("__aeabi_dcmpgt", @import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpgt, linkage);
234 @export("__aeabi_dcmpun", @import("compiler_rt/comparedf2.zig").__unorddf2, linkage);234 @export("__aeabi_dcmpun", @import("compiler_rt/comparedf2.zig").__unorddf2, linkage);
235 }235 }
236 if (builtin.os == builtin.Os.windows) {236 if (builtin.os == .windows) {
237 if (!builtin.link_libc) {237 if (!builtin.link_libc) {
238 @export("_chkstk", @import("compiler_rt/stack_probe.zig")._chkstk, strong_linkage);238 @export("_chkstk", @import("compiler_rt/stack_probe.zig")._chkstk, strong_linkage);
239 @export("__chkstk", @import("compiler_rt/stack_probe.zig").__chkstk, strong_linkage);239 @export("__chkstk", @import("compiler_rt/stack_probe.zig").__chkstk, strong_linkage);
...@@ -247,11 +247,11 @@ comptime {...@@ -247,11 +247,11 @@ comptime {
247 }247 }
248248
249 switch (builtin.arch) {249 switch (builtin.arch) {
250 builtin.Arch.i386 => {250 .i386 => {
251 @export("_aulldiv", @import("compiler_rt/aulldiv.zig")._aulldiv, strong_linkage);251 @export("_aulldiv", @import("compiler_rt/aulldiv.zig")._aulldiv, strong_linkage);
252 @export("_aullrem", @import("compiler_rt/aullrem.zig")._aullrem, strong_linkage);252 @export("_aullrem", @import("compiler_rt/aullrem.zig")._aullrem, strong_linkage);
253 },253 },
254 builtin.Arch.x86_64 => {254 .x86_64 => {
255 // The "ti" functions must use @Vector(2, u64) parameter types to adhere to the ABI255 // The "ti" functions must use @Vector(2, u64) parameter types to adhere to the ABI
256 // that LLVM expects compiler-rt to have.256 // that LLVM expects compiler-rt to have.
257 @export("__divti3", @import("compiler_rt/divti3.zig").__divti3_windows_x86_64, linkage);257 @export("__divti3", @import("compiler_rt/divti3.zig").__divti3_windows_x86_64, linkage);
...@@ -264,6 +264,9 @@ comptime {...@@ -264,6 +264,9 @@ comptime {
264 else => {},264 else => {},
265 }265 }
266 } else {266 } else {
267 if (builtin.glibc_version != null) {
268 @export("__stack_chk_guard", __stack_chk_guard, linkage);
269 }
267 @export("__divti3", @import("compiler_rt/divti3.zig").__divti3, linkage);270 @export("__divti3", @import("compiler_rt/divti3.zig").__divti3, linkage);
268 @export("__modti3", @import("compiler_rt/modti3.zig").__modti3, linkage);271 @export("__modti3", @import("compiler_rt/modti3.zig").__modti3, linkage);
269 @export("__multi3", @import("compiler_rt/multi3.zig").__multi3, linkage);272 @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 {...@@ -14,31 +14,31 @@ const ConditionalOperator = enum {
1414
15pub nakedcc fn __aeabi_dcmpeq() noreturn {15pub nakedcc fn __aeabi_dcmpeq() noreturn {
16 @setRuntimeSafety(false);16 @setRuntimeSafety(false);
17 aeabi_dcmp(.Eq);17 @inlineCall(aeabi_dcmp, .Eq);
18 unreachable;18 unreachable;
19}19}
2020
21pub nakedcc fn __aeabi_dcmplt() noreturn {21pub nakedcc fn __aeabi_dcmplt() noreturn {
22 @setRuntimeSafety(false);22 @setRuntimeSafety(false);
23 aeabi_dcmp(.Lt);23 @inlineCall(aeabi_dcmp, .Lt);
24 unreachable;24 unreachable;
25}25}
2626
27pub nakedcc fn __aeabi_dcmple() noreturn {27pub nakedcc fn __aeabi_dcmple() noreturn {
28 @setRuntimeSafety(false);28 @setRuntimeSafety(false);
29 aeabi_dcmp(.Le);29 @inlineCall(aeabi_dcmp, .Le);
30 unreachable;30 unreachable;
31}31}
3232
33pub nakedcc fn __aeabi_dcmpge() noreturn {33pub nakedcc fn __aeabi_dcmpge() noreturn {
34 @setRuntimeSafety(false);34 @setRuntimeSafety(false);
35 aeabi_dcmp(.Ge);35 @inlineCall(aeabi_dcmp, .Ge);
36 unreachable;36 unreachable;
37}37}
3838
39pub nakedcc fn __aeabi_dcmpgt() noreturn {39pub nakedcc fn __aeabi_dcmpgt() noreturn {
40 @setRuntimeSafety(false);40 @setRuntimeSafety(false);
41 aeabi_dcmp(.Gt);41 @inlineCall(aeabi_dcmp, .Gt);
42 unreachable;42 unreachable;
43}43}
4444
...@@ -49,7 +49,7 @@ inline fn convert_dcmp_args_to_df2_args() void {...@@ -49,7 +49,7 @@ inline fn convert_dcmp_args_to_df2_args() void {
49 );49 );
50}50}
5151
52inline fn aeabi_dcmp(comptime cond: ConditionalOperator) void {52fn aeabi_dcmp(comptime cond: ConditionalOperator) void {
53 @setRuntimeSafety(false);53 @setRuntimeSafety(false);
54 asm volatile (54 asm volatile (
55 \\ push { r4, lr }55 \\ push { r4, lr }
std/special/compiler_rt/arm/aeabi_fcmp.zig+6-6
...@@ -14,31 +14,31 @@ const ConditionalOperator = enum {...@@ -14,31 +14,31 @@ const ConditionalOperator = enum {
1414
15pub nakedcc fn __aeabi_fcmpeq() noreturn {15pub nakedcc fn __aeabi_fcmpeq() noreturn {
16 @setRuntimeSafety(false);16 @setRuntimeSafety(false);
17 aeabi_fcmp(.Eq);17 @inlineCall(aeabi_fcmp, .Eq);
18 unreachable;18 unreachable;
19}19}
2020
21pub nakedcc fn __aeabi_fcmplt() noreturn {21pub nakedcc fn __aeabi_fcmplt() noreturn {
22 @setRuntimeSafety(false);22 @setRuntimeSafety(false);
23 aeabi_fcmp(.Lt);23 @inlineCall(aeabi_fcmp, .Lt);
24 unreachable;24 unreachable;
25}25}
2626
27pub nakedcc fn __aeabi_fcmple() noreturn {27pub nakedcc fn __aeabi_fcmple() noreturn {
28 @setRuntimeSafety(false);28 @setRuntimeSafety(false);
29 aeabi_fcmp(.Le);29 @inlineCall(aeabi_fcmp, .Le);
30 unreachable;30 unreachable;
31}31}
3232
33pub nakedcc fn __aeabi_fcmpge() noreturn {33pub nakedcc fn __aeabi_fcmpge() noreturn {
34 @setRuntimeSafety(false);34 @setRuntimeSafety(false);
35 aeabi_fcmp(.Ge);35 @inlineCall(aeabi_fcmp, .Ge);
36 unreachable;36 unreachable;
37}37}
3838
39pub nakedcc fn __aeabi_fcmpgt() noreturn {39pub nakedcc fn __aeabi_fcmpgt() noreturn {
40 @setRuntimeSafety(false);40 @setRuntimeSafety(false);
41 aeabi_fcmp(.Gt);41 @inlineCall(aeabi_fcmp, .Gt);
42 unreachable;42 unreachable;
43}43}
4444
...@@ -49,7 +49,7 @@ inline fn convert_fcmp_args_to_sf2_args() void {...@@ -49,7 +49,7 @@ inline fn convert_fcmp_args_to_sf2_args() void {
49 );49 );
50}50}
5151
52inline fn aeabi_fcmp(comptime cond: ConditionalOperator) void {52fn aeabi_fcmp(comptime cond: ConditionalOperator) void {
53 @setRuntimeSafety(false);53 @setRuntimeSafety(false);
54 asm volatile (54 asm volatile (
55 \\ push { r4, lr }55 \\ push { r4, lr }
test/tests.zig+239-57
...@@ -23,21 +23,183 @@ const runtime_safety = @import("runtime_safety.zig");...@@ -23,21 +23,183 @@ const runtime_safety = @import("runtime_safety.zig");
23const translate_c = @import("translate_c.zig");23const translate_c = @import("translate_c.zig");
24const gen_h = @import("gen_h.zig");24const gen_h = @import("gen_h.zig");
2525
26const cross_targets = [_]CrossTarget{26const TestTarget = struct {
27 CrossTarget{27 target: Target = .Native,
28 .os = .linux,28 mode: builtin.Mode = .Debug,
29 .arch = .x86_64,29 link_libc: bool = false,
30 .abi = .gnu,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,
31 },166 },
32 CrossTarget{167
33 .os = .macosx,168 // Do the release tests last because they take a long time
34 .arch = .x86_64,169 TestTarget{
35 .abi = .gnu,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,
36 },191 },
37 CrossTarget{192
38 .os = .windows,193 TestTarget{
39 .arch = .x86_64,194 .mode = .ReleaseSmall,
40 .abi = .msvc,195 },
196 TestTarget{
197 .link_libc = true,
198 .mode = .ReleaseSmall,
199 },
200 TestTarget{
201 .mode = .ReleaseSmall,
202 .single_threaded = true,
41 },203 },
42};204};
43205
...@@ -182,57 +344,77 @@ pub fn addPkgTests(...@@ -182,57 +344,77 @@ pub fn addPkgTests(
182 name: []const u8,344 name: []const u8,
183 desc: []const u8,345 desc: []const u8,
184 modes: []const Mode,346 modes: []const Mode,
185 single_threaded_list: []const bool,347 skip_single_threaded: bool,
186 skip_non_native: bool,348 skip_non_native: bool,
349 skip_libc: bool,
350 is_wine_enabled: bool,
351 is_qemu_enabled: bool,
352 glibc_dir: ?[]const u8,
187) *build.Step {353) *build.Step {
188 const step = b.step(b.fmt("test-{}", name), desc);354 const step = b.step(b.fmt("test-{}", name), desc);
189355
190 var targets = std.ArrayList(*const CrossTarget).init(b.allocator);356 for (test_targets) |test_target| {
191 defer targets.deinit();357 if (skip_non_native and test_target.target != .Native)
192 const host = CrossTarget{ .os = builtin.os, .arch = builtin.arch, .abi = builtin.abi };358 continue;
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 }
198359
199 for (targets.toSliceConst()) |test_target| {360 if (skip_libc and test_target.link_libc)
200 const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch);361 continue;
201 if (skip_non_native and !is_native)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 {
202 continue;376 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 }
235 }377 }
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);
236 }418 }
237 return step;419 return step;
238}420}