2017-04-19 18:00:12 +00:00
|
|
|
const std = @import("std");
|
2021-10-05 06:47:27 +00:00
|
|
|
const builtin = @import("builtin");
|
2023-03-07 07:40:55 +00:00
|
|
|
const assert = std.debug.assert;
|
2020-02-26 06:18:23 +00:00
|
|
|
const CrossTarget = std.zig.CrossTarget;
|
2017-04-19 18:00:12 +00:00
|
|
|
const mem = std.mem;
|
2023-01-31 04:39:43 +00:00
|
|
|
const OptimizeMode = std.builtin.OptimizeMode;
|
2023-01-31 07:19:51 +00:00
|
|
|
const Step = std.Build.Step;
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2020-01-03 03:45:48 +00:00
|
|
|
// Cases
|
2017-04-19 20:59:20 +00:00
|
|
|
const compare_output = @import("compare_output.zig");
|
2019-07-16 16:15:46 +00:00
|
|
|
const standalone = @import("standalone.zig");
|
2019-09-03 14:08:39 +00:00
|
|
|
const stack_traces = @import("stack_traces.zig");
|
2017-04-19 20:59:20 +00:00
|
|
|
const assemble_and_link = @import("assemble_and_link.zig");
|
2017-11-24 19:56:05 +00:00
|
|
|
const translate_c = @import("translate_c.zig");
|
2020-01-03 03:45:48 +00:00
|
|
|
const run_translated_c = @import("run_translated_c.zig");
|
2022-05-28 09:44:53 +00:00
|
|
|
const link = @import("link.zig");
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2020-01-03 03:45:48 +00:00
|
|
|
// Implementations
|
2020-01-05 07:01:28 +00:00
|
|
|
pub const TranslateCContext = @import("src/translate_c.zig").TranslateCContext;
|
2020-01-03 03:45:48 +00:00
|
|
|
pub const RunTranslatedCContext = @import("src/run_translated_c.zig").RunTranslatedCContext;
|
2023-03-07 02:19:48 +00:00
|
|
|
pub const CompareOutputContext = @import("src/CompareOutput.zig");
|
2023-03-07 02:10:37 +00:00
|
|
|
pub const StackTracesContext = @import("src/StackTrace.zig");
|
2020-01-03 03:45:48 +00:00
|
|
|
|
2019-09-22 03:55:56 +00:00
|
|
|
const TestTarget = struct {
|
2020-02-26 06:18:23 +00:00
|
|
|
target: CrossTarget = @as(CrossTarget, .{}),
|
2023-01-31 04:39:43 +00:00
|
|
|
optimize_mode: std.builtin.OptimizeMode = .Debug,
|
2019-09-22 03:55:56 +00:00
|
|
|
link_libc: bool = false,
|
|
|
|
single_threaded: bool = false,
|
2019-09-22 18:40:54 +00:00
|
|
|
disable_native: bool = false,
|
2022-04-22 03:28:36 +00:00
|
|
|
backend: ?std.builtin.CompilerBackend = null,
|
2019-09-22 03:55:56 +00:00
|
|
|
};
|
|
|
|
|
2020-01-22 22:13:31 +00:00
|
|
|
const test_targets = blk: {
|
|
|
|
// getBaselineCpuFeatures calls populateDependencies which has a O(N ^ 2) algorithm
|
|
|
|
// (where N is roughly 160, which technically makes it O(1), but it adds up to a
|
|
|
|
// lot of branches)
|
|
|
|
@setEvalBranchQuota(50000);
|
|
|
|
break :blk [_]TestTarget{
|
2022-04-22 03:28:36 +00:00
|
|
|
.{},
|
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.single_threaded = true,
|
|
|
|
},
|
2019-09-22 03:55:56 +00:00
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2022-11-01 02:30:34 +00:00
|
|
|
.target = .{
|
|
|
|
.ofmt = .c,
|
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.link_libc = true,
|
|
|
|
.backend = .stage2_c,
|
|
|
|
},
|
2023-02-20 09:37:22 +00:00
|
|
|
.{
|
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
.backend = .stage2_x86_64,
|
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
},
|
|
|
|
.backend = .stage2_aarch64,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .wasm32,
|
|
|
|
.os_tag = .wasi,
|
|
|
|
},
|
|
|
|
.single_threaded = true,
|
|
|
|
.backend = .stage2_wasm,
|
|
|
|
},
|
2022-11-22 05:56:05 +00:00
|
|
|
// https://github.com/ziglang/zig/issues/13623
|
|
|
|
//.{
|
|
|
|
// .target = .{
|
|
|
|
// .cpu_arch = .arm,
|
|
|
|
// .os_tag = .linux,
|
|
|
|
// },
|
|
|
|
// .backend = .stage2_arm,
|
|
|
|
//},
|
|
|
|
// https://github.com/ziglang/zig/issues/13623
|
|
|
|
//.{
|
|
|
|
// .target = CrossTarget.parse(.{
|
|
|
|
// .arch_os_abi = "arm-linux-none",
|
|
|
|
// .cpu_features = "generic+v8a",
|
|
|
|
// }) catch unreachable,
|
|
|
|
// .backend = .stage2_arm,
|
|
|
|
//},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .macos,
|
2022-05-15 15:56:51 +00:00
|
|
|
.abi = .none,
|
2022-04-22 03:28:36 +00:00
|
|
|
},
|
|
|
|
.backend = .stage2_aarch64,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .macos,
|
2022-05-15 15:56:51 +00:00
|
|
|
.abi = .none,
|
2022-04-22 03:28:36 +00:00
|
|
|
},
|
|
|
|
.backend = .stage2_x86_64,
|
|
|
|
},
|
2022-09-06 15:53:21 +00:00
|
|
|
.{
|
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
.backend = .stage2_x86_64,
|
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
|
|
|
|
.{
|
Add/fix missing WASI functionality to pass libstd tests
This rather large commit adds/fixes missing WASI functionality
in `libstd` needed to pass the `libstd` tests. As such, now by
default tests targeting `wasm32-wasi` target are enabled in
`test/tests.zig` module. However, they can be disabled by passing
the `-Dskip-wasi=true` flag when invoking the `zig build test`
command. When the flag is set to `false`, i.e., when WASI tests are
included, `wasmtime` with `--dir=.` is used as the default testing
command.
Since the majority of `libstd` tests were relying on `fs.cwd()`
call to get current working directory handle wrapped in `Dir`
struct, in order to make the tests WASI-friendly, `fs.cwd()`
call was replaced with `testing.getTestDir()` function which
resolved to either `fs.cwd()` for non-WASI targets, or tries to
fetch the preopen list from the WASI runtime and extract a
preopen for '.' path.
The summary of changes introduced by this commit:
* implement `Dir.makeDir` and `Dir.openDir` targeting WASI
* implement `Dir.deleteFile` and `Dir.deleteDir` targeting WASI
* fix `os.close` and map errors in `unlinkat`
* move WASI-specific `mkdirat` and `unlinkat` from `std.fs.wasi`
to `std.os` module
* implement `lseek_{SET, CUR, END}` targeting WASI
* implement `futimens` targeting WASI
* implement `ftruncate` targeting WASI
* implement `readv`, `writev`, `pread{v}`, `pwrite{v}` targeting WASI
* make sure ANSI escape codes are _not_ used in stderr or stdout
in WASI, as WASI always sanitizes stderr, and sanitizes stdout if
fd is a TTY
* fix specifying WASI rights when opening/creating files/dirs
* tweak `AtomicFile` to be WASI-compatible
* implement `os.renameatWasi` for WASI-compliant `os.renameat` function
* implement sleep() targeting WASI
* fix `process.getEnvMap` targeting WASI
2020-05-05 15:23:49 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .wasm32,
|
|
|
|
.os_tag = .wasi,
|
|
|
|
},
|
|
|
|
.link_libc = false,
|
|
|
|
.single_threaded = true,
|
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2021-07-26 23:59:34 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .wasm32,
|
|
|
|
.os_tag = .wasi,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
.single_threaded = true,
|
|
|
|
},
|
Add/fix missing WASI functionality to pass libstd tests
This rather large commit adds/fixes missing WASI functionality
in `libstd` needed to pass the `libstd` tests. As such, now by
default tests targeting `wasm32-wasi` target are enabled in
`test/tests.zig` module. However, they can be disabled by passing
the `-Dskip-wasi=true` flag when invoking the `zig build test`
command. When the flag is set to `false`, i.e., when WASI tests are
included, `wasmtime` with `--dir=.` is used as the default testing
command.
Since the majority of `libstd` tests were relying on `fs.cwd()`
call to get current working directory handle wrapped in `Dir`
struct, in order to make the tests WASI-friendly, `fs.cwd()`
call was replaced with `testing.getTestDir()` function which
resolved to either `fs.cwd()` for non-WASI targets, or tries to
fetch the preopen list from the WASI runtime and extract a
preopen for '.' path.
The summary of changes introduced by this commit:
* implement `Dir.makeDir` and `Dir.openDir` targeting WASI
* implement `Dir.deleteFile` and `Dir.deleteDir` targeting WASI
* fix `os.close` and map errors in `unlinkat`
* move WASI-specific `mkdirat` and `unlinkat` from `std.fs.wasi`
to `std.os` module
* implement `lseek_{SET, CUR, END}` targeting WASI
* implement `futimens` targeting WASI
* implement `ftruncate` targeting WASI
* implement `readv`, `writev`, `pread{v}`, `pwrite{v}` targeting WASI
* make sure ANSI escape codes are _not_ used in stderr or stdout
in WASI, as WASI always sanitizes stderr, and sanitizes stdout if
fd is a TTY
* fix specifying WASI rights when opening/creating files/dirs
* tweak `AtomicFile` to be WASI-compatible
* implement `os.renameatWasi` for WASI-compliant `os.renameat` function
* implement sleep() targeting WASI
* fix `process.getEnvMap` targeting WASI
2020-05-05 15:23:49 +00:00
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .gnu,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
2022-10-07 17:54:44 +00:00
|
|
|
.cpu_arch = .x86,
|
2020-02-26 06:18:23 +00:00
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
2019-11-30 15:13:33 +00:00
|
|
|
},
|
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
2022-10-07 17:54:44 +00:00
|
|
|
.cpu_arch = .x86,
|
2020-02-26 06:18:23 +00:00
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
2019-11-30 15:13:33 +00:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-11-30 15:13:33 +00:00
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2021-06-06 09:12:41 +00:00
|
|
|
.target = .{
|
2022-10-07 17:54:44 +00:00
|
|
|
.cpu_arch = .x86,
|
2021-06-06 09:12:41 +00:00
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2019-11-30 15:13:33 +00:00
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .gnu,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2021-09-07 16:44:21 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2019-09-22 03:55:56 +00:00
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = CrossTarget.parse(.{
|
2020-02-20 02:30:36 +00:00
|
|
|
.arch_os_abi = "arm-linux-none",
|
2020-02-20 23:31:17 +00:00
|
|
|
.cpu_features = "generic+v8a",
|
2020-02-20 02:30:36 +00:00
|
|
|
}) catch unreachable,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = CrossTarget.parse(.{
|
2020-02-20 02:30:36 +00:00
|
|
|
.arch_os_abi = "arm-linux-musleabihf",
|
2020-02-20 23:31:17 +00:00
|
|
|
.cpu_features = "generic+v8a",
|
2020-02-20 02:30:36 +00:00
|
|
|
}) catch unreachable,
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-09-25 19:57:13 +00:00
|
|
|
},
|
2020-04-03 22:36:13 +00:00
|
|
|
// https://github.com/ziglang/zig/issues/3287
|
2022-04-22 03:28:36 +00:00
|
|
|
//.{
|
2020-02-26 06:18:23 +00:00
|
|
|
// .target = CrossTarget.parse(.{
|
2020-02-20 02:30:36 +00:00
|
|
|
// .arch_os_abi = "arm-linux-gnueabihf",
|
2020-02-20 23:31:17 +00:00
|
|
|
// .cpu_features = "generic+v8a",
|
2020-02-20 02:30:36 +00:00
|
|
|
// }) catch unreachable,
|
2020-01-22 22:13:31 +00:00
|
|
|
// .link_libc = true,
|
|
|
|
//},
|
2019-09-22 03:55:56 +00:00
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2021-08-31 17:36:33 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .mips,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
2021-04-02 23:33:07 +00:00
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2021-08-31 17:36:33 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .mips,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2021-04-02 23:33:07 +00:00
|
|
|
|
2020-04-21 16:42:21 +00:00
|
|
|
// https://github.com/ziglang/zig/issues/4927
|
2022-04-22 03:28:36 +00:00
|
|
|
//.{
|
2020-04-21 16:42:21 +00:00
|
|
|
// .target = .{
|
|
|
|
// .cpu_arch = .mips,
|
|
|
|
// .os_tag = .linux,
|
2021-12-16 01:59:59 +00:00
|
|
|
// .abi = .gnueabihf,
|
2020-04-21 16:42:21 +00:00
|
|
|
// },
|
|
|
|
// .link_libc = true,
|
|
|
|
//},
|
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2021-08-31 17:36:33 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .mipsel,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
2021-04-02 23:33:07 +00:00
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2021-08-31 17:36:33 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .mipsel,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2021-04-02 23:33:07 +00:00
|
|
|
|
2020-04-03 22:36:13 +00:00
|
|
|
// https://github.com/ziglang/zig/issues/4927
|
2022-04-22 03:28:36 +00:00
|
|
|
//.{
|
2020-04-03 22:36:13 +00:00
|
|
|
// .target = .{
|
|
|
|
// .cpu_arch = .mipsel,
|
|
|
|
// .os_tag = .linux,
|
2021-12-16 01:59:59 +00:00
|
|
|
// .abi = .gnueabihf,
|
2020-04-03 22:36:13 +00:00
|
|
|
// },
|
|
|
|
// .link_libc = true,
|
|
|
|
//},
|
2019-09-21 21:00:36 +00:00
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2021-04-20 20:08:19 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .powerpc,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2021-04-20 20:08:19 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .powerpc,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2021-12-16 02:25:26 +00:00
|
|
|
// https://github.com/ziglang/zig/issues/2256
|
2022-04-22 03:28:36 +00:00
|
|
|
//.{
|
2021-12-16 02:25:26 +00:00
|
|
|
// .target = .{
|
|
|
|
// .cpu_arch = .powerpc,
|
|
|
|
// .os_tag = .linux,
|
|
|
|
// .abi = .gnueabihf,
|
|
|
|
// },
|
|
|
|
// .link_libc = true,
|
|
|
|
//},
|
2021-04-20 20:08:19 +00:00
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-04-02 23:48:48 +00:00
|
|
|
.target = .{
|
2022-10-11 18:11:46 +00:00
|
|
|
.cpu_arch = .powerpc64le,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .powerpc64le,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .powerpc64le,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
|
|
|
|
|
|
|
.{
|
|
|
|
.target = .{
|
2020-04-02 23:48:48 +00:00
|
|
|
.cpu_arch = .riscv64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
2020-02-17 05:06:19 +00:00
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-04-03 15:02:22 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .riscv64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2020-02-17 05:06:19 +00:00
|
|
|
|
|
|
|
// https://github.com/ziglang/zig/issues/3340
|
2022-04-22 03:28:36 +00:00
|
|
|
//.{
|
2020-03-03 14:44:13 +00:00
|
|
|
// .target = .{
|
|
|
|
// .cpu_arch = .riscv64,
|
|
|
|
// .os = .linux,
|
|
|
|
// .abi = .gnu,
|
2020-02-17 05:06:19 +00:00
|
|
|
// },
|
|
|
|
// .link_libc = true,
|
|
|
|
//},
|
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
2020-10-12 08:59:43 +00:00
|
|
|
.os_tag = .macos,
|
2022-05-15 15:56:51 +00:00
|
|
|
.abi = .none,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
2021-12-01 23:11:29 +00:00
|
|
|
},
|
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2021-12-01 23:11:29 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .macos,
|
2022-05-15 15:56:51 +00:00
|
|
|
.abi = .none,
|
2021-12-01 23:11:29 +00:00
|
|
|
},
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
2022-10-07 17:54:44 +00:00
|
|
|
.cpu_arch = .x86,
|
2020-02-26 06:18:23 +00:00
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .msvc,
|
2019-10-11 17:13:59 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .msvc,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
2022-10-07 17:54:44 +00:00
|
|
|
.cpu_arch = .x86,
|
2020-02-26 06:18:23 +00:00
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .gnu,
|
2019-10-09 20:49:33 +00:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-10-09 20:49:33 +00:00
|
|
|
},
|
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .gnu,
|
2019-09-22 23:11:41 +00:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-09-22 23:11:41 +00:00
|
|
|
},
|
2019-09-22 18:41:47 +00:00
|
|
|
|
2020-01-22 22:13:31 +00:00
|
|
|
// Do the release tests last because they take a long time
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize_mode = .ReleaseFast,
|
2020-01-22 22:13:31 +00:00
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize_mode = .ReleaseFast,
|
2020-01-22 22:13:31 +00:00
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize_mode = .ReleaseFast,
|
2020-01-22 22:13:31 +00:00
|
|
|
.single_threaded = true,
|
|
|
|
},
|
2019-09-22 18:41:47 +00:00
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize_mode = .ReleaseSafe,
|
2020-01-22 22:13:31 +00:00
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize_mode = .ReleaseSafe,
|
2020-01-22 22:13:31 +00:00
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize_mode = .ReleaseSafe,
|
2020-01-22 22:13:31 +00:00
|
|
|
.single_threaded = true,
|
|
|
|
},
|
2019-09-22 18:41:47 +00:00
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize_mode = .ReleaseSmall,
|
2020-01-22 22:13:31 +00:00
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize_mode = .ReleaseSmall,
|
2020-01-22 22:13:31 +00:00
|
|
|
},
|
2022-04-22 03:28:36 +00:00
|
|
|
.{
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize_mode = .ReleaseSmall,
|
2020-01-22 22:13:31 +00:00
|
|
|
.single_threaded = true,
|
|
|
|
},
|
|
|
|
};
|
2017-08-30 18:55:26 +00:00
|
|
|
};
|
|
|
|
|
2023-03-07 02:10:37 +00:00
|
|
|
const c_abi_targets = [_]CrossTarget{
|
|
|
|
.{},
|
|
|
|
.{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.cpu_arch = .x86,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.cpu_arch = .arm,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musleabihf,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.cpu_arch = .mips,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.cpu_arch = .riscv64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.cpu_arch = .wasm32,
|
|
|
|
.os_tag = .wasi,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.cpu_arch = .powerpc,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.cpu_arch = .powerpc64le,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.cpu_arch = .x86,
|
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
};
|
2017-10-31 08:47:55 +00:00
|
|
|
|
2023-03-07 02:10:37 +00:00
|
|
|
pub fn addCompareOutputTests(
|
|
|
|
b: *std.Build,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
optimize_modes: []const OptimizeMode,
|
|
|
|
) *Step {
|
|
|
|
const cases = b.allocator.create(CompareOutputContext) catch @panic("OOM");
|
2019-02-03 21:13:28 +00:00
|
|
|
cases.* = CompareOutputContext{
|
2017-04-19 18:00:12 +00:00
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-compare-output", "Run the compare output tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize_modes = optimize_modes,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
compare_output.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2023-03-07 02:10:37 +00:00
|
|
|
pub fn addStackTraceTests(
|
|
|
|
b: *std.Build,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
optimize_modes: []const OptimizeMode,
|
|
|
|
) *Step {
|
|
|
|
const check_exe = b.addExecutable(.{
|
|
|
|
.name = "check-stack-trace",
|
|
|
|
.root_source_file = .{ .path = "test/src/check-stack-trace.zig" },
|
|
|
|
.target = .{},
|
|
|
|
.optimize = .Debug,
|
|
|
|
});
|
|
|
|
|
|
|
|
const cases = b.allocator.create(StackTracesContext) catch @panic("OOM");
|
|
|
|
cases.* = .{
|
2019-05-28 00:07:05 +00:00
|
|
|
.b = b,
|
2019-09-03 14:08:39 +00:00
|
|
|
.step = b.step("test-stack-traces", "Run the stack trace tests"),
|
2019-05-28 00:07:05 +00:00
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize_modes = optimize_modes,
|
2023-03-07 02:10:37 +00:00
|
|
|
.check_exe = check_exe,
|
2019-05-28 00:07:05 +00:00
|
|
|
};
|
|
|
|
|
2019-09-03 14:08:39 +00:00
|
|
|
stack_traces.addCases(cases);
|
2019-05-28 00:07:05 +00:00
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2021-08-02 08:04:54 +00:00
|
|
|
pub fn addStandaloneTests(
|
2023-01-31 07:19:51 +00:00
|
|
|
b: *std.Build,
|
2023-01-31 04:39:43 +00:00
|
|
|
optimize_modes: []const OptimizeMode,
|
2021-08-02 08:04:54 +00:00
|
|
|
enable_macos_sdk: bool,
|
2022-08-18 05:17:19 +00:00
|
|
|
omit_stage2: bool,
|
2022-11-26 19:23:32 +00:00
|
|
|
enable_symlinks_windows: bool,
|
2023-01-31 07:19:51 +00:00
|
|
|
) *Step {
|
2023-03-08 05:40:53 +00:00
|
|
|
const step = b.step("test-standalone", "Run the standalone tests");
|
2023-03-08 07:16:16 +00:00
|
|
|
const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows;
|
2023-03-08 05:40:53 +00:00
|
|
|
|
|
|
|
for (standalone.simple_cases) |case| {
|
|
|
|
for (optimize_modes) |optimize| {
|
|
|
|
if (!case.all_modes and optimize != .Debug) continue;
|
2023-03-10 21:32:49 +00:00
|
|
|
if (case.os_filter) |os_tag| {
|
|
|
|
if (os_tag != builtin.os.tag) continue;
|
|
|
|
}
|
2023-03-08 05:40:53 +00:00
|
|
|
|
2023-03-08 07:16:16 +00:00
|
|
|
if (case.is_exe) {
|
|
|
|
const exe = b.addExecutable(.{
|
|
|
|
.name = std.fs.path.stem(case.src_path),
|
|
|
|
.root_source_file = .{ .path = case.src_path },
|
|
|
|
.optimize = optimize,
|
|
|
|
.target = case.target,
|
|
|
|
});
|
|
|
|
if (case.link_libc) exe.linkLibC();
|
|
|
|
|
|
|
|
step.dependOn(&exe.step);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (case.is_test) {
|
|
|
|
const exe = b.addTest(.{
|
|
|
|
.name = std.fs.path.stem(case.src_path),
|
|
|
|
.root_source_file = .{ .path = case.src_path },
|
|
|
|
.optimize = optimize,
|
|
|
|
.target = case.target,
|
|
|
|
});
|
|
|
|
if (case.link_libc) exe.linkLibC();
|
|
|
|
|
2023-03-12 07:39:21 +00:00
|
|
|
step.dependOn(&exe.run().step);
|
2023-03-08 07:16:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-08 05:40:53 +00:00
|
|
|
|
2023-03-08 07:16:16 +00:00
|
|
|
inline for (standalone.build_cases) |case| {
|
|
|
|
const requires_stage2 = @hasDecl(case.import, "requires_stage2") and
|
|
|
|
case.import.requires_stage2;
|
|
|
|
const requires_symlinks = @hasDecl(case.import, "requires_symlinks") and
|
|
|
|
case.import.requires_symlinks;
|
|
|
|
const requires_macos_sdk = @hasDecl(case.import, "requires_macos_sdk") and
|
|
|
|
case.import.requires_macos_sdk;
|
|
|
|
const bad =
|
|
|
|
(requires_stage2 and omit_stage2) or
|
|
|
|
(requires_symlinks and omit_symlinks) or
|
|
|
|
(requires_macos_sdk and !enable_macos_sdk);
|
|
|
|
if (!bad) {
|
|
|
|
const dep = b.anonymousDependency(case.build_root, case.import, .{});
|
|
|
|
const dep_step = dep.builder.default_step;
|
|
|
|
assert(mem.startsWith(u8, dep.builder.dep_prefix, "test."));
|
|
|
|
const dep_prefix_adjusted = dep.builder.dep_prefix["test.".len..];
|
|
|
|
dep_step.name = b.fmt("{s}{s}", .{ dep_prefix_adjusted, dep_step.name });
|
|
|
|
step.dependOn(dep_step);
|
2023-03-08 05:40:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return step;
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
2022-05-28 09:44:53 +00:00
|
|
|
pub fn addLinkTests(
|
2023-01-31 07:19:51 +00:00
|
|
|
b: *std.Build,
|
2022-05-28 09:44:53 +00:00
|
|
|
enable_macos_sdk: bool,
|
2022-08-18 05:17:19 +00:00
|
|
|
omit_stage2: bool,
|
2022-11-26 19:23:32 +00:00
|
|
|
enable_symlinks_windows: bool,
|
2023-01-31 07:19:51 +00:00
|
|
|
) *Step {
|
2023-03-07 07:40:55 +00:00
|
|
|
const step = b.step("test-link", "Run the linker tests");
|
2023-03-08 03:23:11 +00:00
|
|
|
const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows;
|
2023-03-07 07:40:55 +00:00
|
|
|
|
2023-03-08 07:16:16 +00:00
|
|
|
inline for (link.cases) |case| {
|
|
|
|
const requires_stage2 = @hasDecl(case.import, "requires_stage2") and
|
|
|
|
case.import.requires_stage2;
|
|
|
|
const requires_symlinks = @hasDecl(case.import, "requires_symlinks") and
|
|
|
|
case.import.requires_symlinks;
|
|
|
|
const requires_macos_sdk = @hasDecl(case.import, "requires_macos_sdk") and
|
|
|
|
case.import.requires_macos_sdk;
|
2023-03-08 03:23:11 +00:00
|
|
|
const bad =
|
|
|
|
(requires_stage2 and omit_stage2) or
|
|
|
|
(requires_symlinks and omit_symlinks) or
|
|
|
|
(requires_macos_sdk and !enable_macos_sdk);
|
|
|
|
if (!bad) {
|
2023-03-08 07:16:16 +00:00
|
|
|
const dep = b.anonymousDependency(case.build_root, case.import, .{});
|
2023-03-08 00:00:35 +00:00
|
|
|
const dep_step = dep.builder.default_step;
|
|
|
|
assert(mem.startsWith(u8, dep.builder.dep_prefix, "test."));
|
|
|
|
const dep_prefix_adjusted = dep.builder.dep_prefix["test.".len..];
|
|
|
|
dep_step.name = b.fmt("{s}{s}", .{ dep_prefix_adjusted, dep_step.name });
|
|
|
|
step.dependOn(dep_step);
|
|
|
|
}
|
2023-03-07 07:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return step;
|
2022-05-28 09:44:53 +00:00
|
|
|
}
|
|
|
|
|
2023-03-08 07:16:16 +00:00
|
|
|
pub fn addCliTests(b: *std.Build) *Step {
|
2018-09-17 21:08:56 +00:00
|
|
|
const step = b.step("test-cli", "Test the command line interface");
|
2023-03-14 21:44:38 +00:00
|
|
|
const s = std.fs.path.sep_str;
|
2018-09-17 21:08:56 +00:00
|
|
|
|
2023-03-07 05:44:36 +00:00
|
|
|
{
|
2023-03-14 21:44:38 +00:00
|
|
|
|
2023-03-07 05:44:36 +00:00
|
|
|
// Test `zig init-lib`.
|
|
|
|
const tmp_path = b.makeTempPath();
|
|
|
|
const init_lib = b.addSystemCommand(&.{ b.zig_exe, "init-lib" });
|
|
|
|
init_lib.cwd = tmp_path;
|
|
|
|
init_lib.setName("zig init-lib");
|
|
|
|
init_lib.expectStdOutEqual("");
|
2023-03-14 21:44:38 +00:00
|
|
|
init_lib.expectStdErrEqual("info: Created build.zig\n" ++
|
|
|
|
"info: Created src" ++ s ++ "main.zig\n" ++
|
|
|
|
"info: Next, try `zig build --help` or `zig build test`\n");
|
2023-03-07 05:44:36 +00:00
|
|
|
|
|
|
|
const run_test = b.addSystemCommand(&.{ b.zig_exe, "build", "test" });
|
|
|
|
run_test.cwd = tmp_path;
|
|
|
|
run_test.setName("zig build test");
|
|
|
|
run_test.expectStdOutEqual("");
|
|
|
|
run_test.step.dependOn(&init_lib.step);
|
|
|
|
|
|
|
|
const cleanup = b.addRemoveDirTree(tmp_path);
|
|
|
|
cleanup.step.dependOn(&run_test.step);
|
|
|
|
|
|
|
|
step.dependOn(&cleanup.step);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Test `zig init-exe`.
|
|
|
|
const tmp_path = b.makeTempPath();
|
|
|
|
const init_exe = b.addSystemCommand(&.{ b.zig_exe, "init-exe" });
|
|
|
|
init_exe.cwd = tmp_path;
|
|
|
|
init_exe.setName("zig init-exe");
|
|
|
|
init_exe.expectStdOutEqual("");
|
2023-03-14 21:44:38 +00:00
|
|
|
init_exe.expectStdErrEqual("info: Created build.zig\n" ++
|
|
|
|
"info: Created src" ++ s ++ "main.zig\n" ++
|
|
|
|
"info: Next, try `zig build --help` or `zig build run`\n");
|
2023-03-07 05:44:36 +00:00
|
|
|
|
|
|
|
// Test missing output path.
|
|
|
|
const bad_out_arg = "-femit-bin=does" ++ s ++ "not" ++ s ++ "exist" ++ s ++ "foo.exe";
|
|
|
|
const ok_src_arg = "src" ++ s ++ "main.zig";
|
|
|
|
const expected = "error: unable to open output directory 'does" ++ s ++ "not" ++ s ++ "exist': FileNotFound\n";
|
|
|
|
const run_bad = b.addSystemCommand(&.{ b.zig_exe, "build-exe", ok_src_arg, bad_out_arg });
|
|
|
|
run_bad.setName("zig build-exe error message for bad -femit-bin arg");
|
|
|
|
run_bad.expectExitCode(1);
|
|
|
|
run_bad.expectStdErrEqual(expected);
|
|
|
|
run_bad.expectStdOutEqual("");
|
|
|
|
run_bad.step.dependOn(&init_exe.step);
|
|
|
|
|
|
|
|
const run_test = b.addSystemCommand(&.{ b.zig_exe, "build", "test" });
|
|
|
|
run_test.cwd = tmp_path;
|
|
|
|
run_test.setName("zig build test");
|
|
|
|
run_test.expectStdOutEqual("");
|
|
|
|
run_test.step.dependOn(&init_exe.step);
|
|
|
|
|
|
|
|
const run_run = b.addSystemCommand(&.{ b.zig_exe, "build", "run" });
|
|
|
|
run_run.cwd = tmp_path;
|
|
|
|
run_run.setName("zig build run");
|
|
|
|
run_run.expectStdOutEqual("Run `zig build test` to run the tests.\n");
|
|
|
|
run_run.expectStdErrEqual("All your codebase are belong to us.\n");
|
|
|
|
run_run.step.dependOn(&init_exe.step);
|
|
|
|
|
|
|
|
const cleanup = b.addRemoveDirTree(tmp_path);
|
|
|
|
cleanup.step.dependOn(&run_test.step);
|
|
|
|
cleanup.step.dependOn(&run_run.step);
|
|
|
|
cleanup.step.dependOn(&run_bad.step);
|
|
|
|
|
|
|
|
step.dependOn(&cleanup.step);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test Godbolt API
|
|
|
|
if (builtin.os.tag == .linux and builtin.cpu.arch == .x86_64) {
|
|
|
|
const tmp_path = b.makeTempPath();
|
|
|
|
|
|
|
|
const writefile = b.addWriteFile("example.zig",
|
|
|
|
\\// Type your code here, or load an example.
|
|
|
|
\\export fn square(num: i32) i32 {
|
|
|
|
\\ return num * num;
|
|
|
|
\\}
|
|
|
|
\\extern fn zig_panic() noreturn;
|
|
|
|
\\pub fn panic(msg: []const u8, error_return_trace: ?*@import("std").builtin.StackTrace, _: ?usize) noreturn {
|
|
|
|
\\ _ = msg;
|
|
|
|
\\ _ = error_return_trace;
|
|
|
|
\\ zig_panic();
|
|
|
|
\\}
|
|
|
|
);
|
|
|
|
|
|
|
|
// This is intended to be the exact CLI usage used by godbolt.org.
|
|
|
|
const run = b.addSystemCommand(&.{
|
|
|
|
b.zig_exe, "build-obj",
|
|
|
|
"--cache-dir", tmp_path,
|
|
|
|
"--name", "example",
|
|
|
|
"-fno-emit-bin", "-fno-emit-h",
|
|
|
|
"-fstrip", "-OReleaseFast",
|
|
|
|
});
|
|
|
|
run.addFileSourceArg(writefile.getFileSource("example.zig").?);
|
|
|
|
const example_s = run.addPrefixedOutputFileArg("-femit-asm=", "example.s");
|
|
|
|
|
|
|
|
const checkfile = b.addCheckFile(example_s, .{
|
|
|
|
.expected_matches = &.{
|
|
|
|
"square:",
|
|
|
|
"mov\teax, edi",
|
|
|
|
"imul\teax, edi",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
checkfile.setName("check godbolt.org CLI usage generating valid asm");
|
|
|
|
|
|
|
|
const cleanup = b.addRemoveDirTree(tmp_path);
|
|
|
|
cleanup.step.dependOn(&checkfile.step);
|
|
|
|
|
|
|
|
step.dependOn(&cleanup.step);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Test `zig fmt`.
|
|
|
|
// This test must use a temporary directory rather than a cache
|
|
|
|
// directory because this test will be mutating the files. The cache
|
|
|
|
// system relies on cache directories being mutated only by their
|
|
|
|
// owners.
|
|
|
|
const tmp_path = b.makeTempPath();
|
|
|
|
const unformatted_code = " // no reason for indent";
|
|
|
|
|
2023-03-07 07:40:55 +00:00
|
|
|
var dir = std.fs.cwd().openDir(tmp_path, .{}) catch @panic("unhandled");
|
2023-03-07 05:44:36 +00:00
|
|
|
defer dir.close();
|
|
|
|
dir.writeFile("fmt1.zig", unformatted_code) catch @panic("unhandled");
|
|
|
|
dir.writeFile("fmt2.zig", unformatted_code) catch @panic("unhandled");
|
|
|
|
|
|
|
|
// Test zig fmt affecting only the appropriate files.
|
|
|
|
const run1 = b.addSystemCommand(&.{ b.zig_exe, "fmt", "fmt1.zig" });
|
|
|
|
run1.setName("run zig fmt one file");
|
|
|
|
run1.cwd = tmp_path;
|
|
|
|
run1.has_side_effects = true;
|
|
|
|
// stdout should be file path + \n
|
|
|
|
run1.expectStdOutEqual("fmt1.zig\n");
|
|
|
|
|
|
|
|
// running it on the dir, only the new file should be changed
|
|
|
|
const run2 = b.addSystemCommand(&.{ b.zig_exe, "fmt", "." });
|
|
|
|
run2.setName("run zig fmt the directory");
|
|
|
|
run2.cwd = tmp_path;
|
|
|
|
run2.has_side_effects = true;
|
|
|
|
run2.expectStdOutEqual("." ++ s ++ "fmt2.zig\n");
|
|
|
|
run2.step.dependOn(&run1.step);
|
|
|
|
|
|
|
|
// both files have been formatted, nothing should change now
|
|
|
|
const run3 = b.addSystemCommand(&.{ b.zig_exe, "fmt", "." });
|
|
|
|
run3.setName("run zig fmt with nothing to do");
|
|
|
|
run3.cwd = tmp_path;
|
|
|
|
run3.has_side_effects = true;
|
|
|
|
run3.expectStdOutEqual("");
|
|
|
|
run3.step.dependOn(&run2.step);
|
|
|
|
|
|
|
|
const unformatted_code_utf16 = "\xff\xfe \x00 \x00 \x00 \x00/\x00/\x00 \x00n\x00o\x00 \x00r\x00e\x00a\x00s\x00o\x00n\x00";
|
2023-03-07 07:40:55 +00:00
|
|
|
const fmt4_path = std.fs.path.join(b.allocator, &.{ tmp_path, "fmt4.zig" }) catch @panic("OOM");
|
2023-03-07 05:44:36 +00:00
|
|
|
const write4 = b.addWriteFiles();
|
|
|
|
write4.addBytesToSource(unformatted_code_utf16, fmt4_path);
|
|
|
|
write4.step.dependOn(&run3.step);
|
|
|
|
|
|
|
|
// Test `zig fmt` handling UTF-16 decoding.
|
|
|
|
const run4 = b.addSystemCommand(&.{ b.zig_exe, "fmt", "." });
|
|
|
|
run4.setName("run zig fmt convert UTF-16 to UTF-8");
|
|
|
|
run4.cwd = tmp_path;
|
|
|
|
run4.has_side_effects = true;
|
|
|
|
run4.expectStdOutEqual("." ++ s ++ "fmt4.zig\n");
|
|
|
|
run4.step.dependOn(&write4.step);
|
|
|
|
|
|
|
|
// TODO change this to an exact match
|
|
|
|
const check4 = b.addCheckFile(.{ .path = fmt4_path }, .{
|
|
|
|
.expected_matches = &.{
|
|
|
|
"// no reason",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
check4.step.dependOn(&run4.step);
|
|
|
|
|
|
|
|
const cleanup = b.addRemoveDirTree(tmp_path);
|
|
|
|
cleanup.step.dependOn(&check4.step);
|
|
|
|
|
|
|
|
step.dependOn(&cleanup.step);
|
|
|
|
}
|
2018-09-17 21:08:56 +00:00
|
|
|
|
2023-03-08 07:16:16 +00:00
|
|
|
{
|
|
|
|
// TODO this should move to become a CLI test rather than standalone
|
|
|
|
// cases.addBuildFile("test/standalone/options/build.zig", .{
|
|
|
|
// .extra_argv = &.{
|
|
|
|
// "-Dbool_true",
|
|
|
|
// "-Dbool_false=false",
|
|
|
|
// "-Dint=1234",
|
|
|
|
// "-De=two",
|
|
|
|
// "-Dstring=hello",
|
|
|
|
// },
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:08:56 +00:00
|
|
|
return step;
|
|
|
|
}
|
|
|
|
|
2023-01-31 07:19:51 +00:00
|
|
|
pub fn addAssembleAndLinkTests(b: *std.Build, test_filter: ?[]const u8, optimize_modes: []const OptimizeMode) *Step {
|
2023-03-07 02:10:37 +00:00
|
|
|
const cases = b.allocator.create(CompareOutputContext) catch @panic("OOM");
|
2019-02-03 21:13:28 +00:00
|
|
|
cases.* = CompareOutputContext{
|
2017-04-19 18:00:12 +00:00
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-asm-link", "Run the assemble and link tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize_modes = optimize_modes,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
assemble_and_link.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2023-01-31 07:19:51 +00:00
|
|
|
pub fn addTranslateCTests(b: *std.Build, test_filter: ?[]const u8) *Step {
|
2023-03-07 02:10:37 +00:00
|
|
|
const cases = b.allocator.create(TranslateCContext) catch @panic("OOM");
|
2019-02-03 21:13:28 +00:00
|
|
|
cases.* = TranslateCContext{
|
2017-04-19 20:59:20 +00:00
|
|
|
.b = b,
|
2021-09-24 17:39:20 +00:00
|
|
|
.step = b.step("test-translate-c", "Run the C translation tests"),
|
2017-04-19 20:59:20 +00:00
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 20:59:20 +00:00
|
|
|
|
2017-11-24 19:56:05 +00:00
|
|
|
translate_c.addCases(cases);
|
2017-04-19 20:59:20 +00:00
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2020-12-08 20:46:05 +00:00
|
|
|
pub fn addRunTranslatedCTests(
|
2023-01-31 07:19:51 +00:00
|
|
|
b: *std.Build,
|
2020-12-08 20:46:05 +00:00
|
|
|
test_filter: ?[]const u8,
|
|
|
|
target: std.zig.CrossTarget,
|
2023-01-31 07:19:51 +00:00
|
|
|
) *Step {
|
2023-03-07 02:10:37 +00:00
|
|
|
const cases = b.allocator.create(RunTranslatedCContext) catch @panic("OOM");
|
2020-01-03 03:45:48 +00:00
|
|
|
cases.* = .{
|
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-run-translated-c", "Run the Run-Translated-C tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2020-12-08 20:46:05 +00:00
|
|
|
.target = target,
|
2020-01-03 03:45:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
run_translated_c.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2023-03-06 07:27:46 +00:00
|
|
|
const ModuleTestOptions = struct {
|
2019-05-15 01:21:59 +00:00
|
|
|
test_filter: ?[]const u8,
|
|
|
|
root_src: []const u8,
|
|
|
|
name: []const u8,
|
|
|
|
desc: []const u8,
|
2023-01-31 04:39:43 +00:00
|
|
|
optimize_modes: []const OptimizeMode,
|
2019-09-22 03:55:56 +00:00
|
|
|
skip_single_threaded: bool,
|
2019-05-15 01:21:59 +00:00
|
|
|
skip_non_native: bool,
|
2019-09-22 03:55:56 +00:00
|
|
|
skip_libc: bool,
|
2022-04-22 03:28:36 +00:00
|
|
|
skip_stage1: bool,
|
|
|
|
skip_stage2: bool,
|
2023-03-06 07:27:46 +00:00
|
|
|
max_rss: usize = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
|
|
|
|
const step = b.step(b.fmt("test-{s}", .{options.name}), options.desc);
|
2019-09-09 21:57:32 +00:00
|
|
|
|
2019-09-22 03:55:56 +00:00
|
|
|
for (test_targets) |test_target| {
|
2023-03-06 07:27:46 +00:00
|
|
|
if (options.skip_non_native and !test_target.target.isNative())
|
2019-09-22 03:55:56 +00:00
|
|
|
continue;
|
2019-09-09 21:57:32 +00:00
|
|
|
|
2023-03-06 07:27:46 +00:00
|
|
|
if (options.skip_libc and test_target.link_libc)
|
2019-09-22 03:55:56 +00:00
|
|
|
continue;
|
|
|
|
|
2020-02-26 06:18:23 +00:00
|
|
|
if (test_target.link_libc and test_target.target.getOs().requiresLibC()) {
|
2019-09-22 03:55:56 +00:00
|
|
|
// This would be a redundant test.
|
2019-05-15 01:21:59 +00:00
|
|
|
continue;
|
2017-04-20 06:26:36 +00:00
|
|
|
}
|
2019-09-22 03:55:56 +00:00
|
|
|
|
2023-03-06 07:27:46 +00:00
|
|
|
if (options.skip_single_threaded and test_target.single_threaded)
|
2019-09-22 03:55:56 +00:00
|
|
|
continue;
|
|
|
|
|
2019-09-22 18:40:54 +00:00
|
|
|
if (test_target.disable_native and
|
2021-10-05 06:47:27 +00:00
|
|
|
test_target.target.getOsTag() == builtin.os.tag and
|
|
|
|
test_target.target.getCpuArch() == builtin.cpu.arch)
|
2019-09-22 18:40:54 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-04-22 03:28:36 +00:00
|
|
|
if (test_target.backend) |backend| switch (backend) {
|
2023-03-06 07:27:46 +00:00
|
|
|
.stage1 => if (options.skip_stage1) continue,
|
2022-08-22 21:10:45 +00:00
|
|
|
.stage2_llvm => {},
|
2023-03-06 07:27:46 +00:00
|
|
|
else => if (options.skip_stage2) continue,
|
2022-08-22 21:10:45 +00:00
|
|
|
};
|
2022-04-22 03:28:36 +00:00
|
|
|
|
2023-03-06 07:27:46 +00:00
|
|
|
const want_this_mode = for (options.optimize_modes) |m| {
|
2023-01-31 04:39:43 +00:00
|
|
|
if (m == test_target.optimize_mode) break true;
|
2019-09-22 03:55:56 +00:00
|
|
|
} else false;
|
|
|
|
if (!want_this_mode) continue;
|
|
|
|
|
2020-02-26 06:18:23 +00:00
|
|
|
const libc_prefix = if (test_target.target.getOs().requiresLibC())
|
2019-09-22 03:55:56 +00:00
|
|
|
""
|
|
|
|
else if (test_target.link_libc)
|
|
|
|
"c"
|
|
|
|
else
|
|
|
|
"bare";
|
|
|
|
|
2023-03-07 02:10:37 +00:00
|
|
|
const triple_prefix = test_target.target.zigTriple(b.allocator) catch @panic("OOM");
|
2019-09-22 03:55:56 +00:00
|
|
|
|
2023-03-06 07:27:46 +00:00
|
|
|
// wasm32-wasi builds need more RAM, idk why
|
|
|
|
const max_rss = if (test_target.target.getOs().tag == .wasi)
|
|
|
|
options.max_rss * 2
|
|
|
|
else
|
|
|
|
options.max_rss;
|
|
|
|
|
2023-01-31 04:39:43 +00:00
|
|
|
const these_tests = b.addTest(.{
|
2023-03-06 07:27:46 +00:00
|
|
|
.root_source_file = .{ .path = options.root_src },
|
2023-01-31 04:39:43 +00:00
|
|
|
.optimize = test_target.optimize_mode,
|
|
|
|
.target = test_target.target,
|
2023-03-06 07:27:46 +00:00
|
|
|
.max_rss = max_rss,
|
2023-01-31 04:39:43 +00:00
|
|
|
});
|
2019-12-09 03:53:51 +00:00
|
|
|
const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
|
2022-04-22 03:28:36 +00:00
|
|
|
const backend_txt = if (test_target.backend) |backend| @tagName(backend) else "default";
|
2019-09-22 03:55:56 +00:00
|
|
|
these_tests.single_threaded = test_target.single_threaded;
|
2023-03-06 07:27:46 +00:00
|
|
|
these_tests.setFilter(options.test_filter);
|
2019-09-22 03:55:56 +00:00
|
|
|
if (test_target.link_libc) {
|
|
|
|
these_tests.linkSystemLibrary("c");
|
|
|
|
}
|
2019-09-26 03:57:47 +00:00
|
|
|
these_tests.overrideZigLibDir("lib");
|
2022-01-24 18:15:32 +00:00
|
|
|
these_tests.addIncludePath("test");
|
2022-04-22 03:28:36 +00:00
|
|
|
if (test_target.backend) |backend| switch (backend) {
|
|
|
|
.stage1 => {
|
2022-11-01 03:29:55 +00:00
|
|
|
@panic("stage1 testing requested");
|
2022-04-22 03:28:36 +00:00
|
|
|
},
|
|
|
|
.stage2_llvm => {
|
|
|
|
these_tests.use_llvm = true;
|
|
|
|
},
|
|
|
|
.stage2_c => {
|
|
|
|
these_tests.use_llvm = false;
|
|
|
|
},
|
|
|
|
else => {
|
|
|
|
these_tests.use_llvm = false;
|
2022-11-01 03:29:55 +00:00
|
|
|
// TODO: force self-hosted linkers to avoid LLD creeping in
|
|
|
|
// until the auto-select mechanism deems them worthy
|
2022-09-07 21:16:42 +00:00
|
|
|
these_tests.use_lld = false;
|
2022-04-22 03:28:36 +00:00
|
|
|
},
|
|
|
|
};
|
2019-09-22 03:55:56 +00:00
|
|
|
|
2023-03-12 07:39:21 +00:00
|
|
|
const run = these_tests.run();
|
|
|
|
run.skip_foreign_checks = true;
|
|
|
|
run.setName(b.fmt("run test {s}-{s}-{s}-{s}-{s}-{s}", .{
|
|
|
|
options.name,
|
|
|
|
triple_prefix,
|
|
|
|
@tagName(test_target.optimize_mode),
|
|
|
|
libc_prefix,
|
|
|
|
single_threaded_txt,
|
|
|
|
backend_txt,
|
|
|
|
}));
|
|
|
|
|
|
|
|
step.dependOn(&run.step);
|
2017-04-20 06:26:36 +00:00
|
|
|
}
|
|
|
|
return step;
|
|
|
|
}
|
|
|
|
|
2023-01-31 07:19:51 +00:00
|
|
|
pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *Step {
|
2022-10-21 20:01:49 +00:00
|
|
|
const step = b.step("test-c-abi", "Run the C ABI tests");
|
|
|
|
|
2023-01-31 04:39:43 +00:00
|
|
|
const optimize_modes: [2]OptimizeMode = .{ .Debug, .ReleaseFast };
|
2023-01-11 15:25:02 +00:00
|
|
|
|
2023-03-07 05:57:53 +00:00
|
|
|
for (optimize_modes) |optimize_mode| {
|
|
|
|
if (optimize_mode != .Debug and skip_release) continue;
|
|
|
|
|
|
|
|
for (c_abi_targets) |c_abi_target| {
|
|
|
|
if (skip_non_native and !c_abi_target.isNative()) continue;
|
|
|
|
|
2023-03-15 17:47:36 +00:00
|
|
|
if (c_abi_target.isWindows() and c_abi_target.getCpuArch() == .aarch64) {
|
|
|
|
// https://github.com/ziglang/zig/issues/14908
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-03-07 05:57:53 +00:00
|
|
|
const test_step = b.addTest(.{
|
|
|
|
.root_source_file = .{ .path = "test/c_abi/main.zig" },
|
|
|
|
.optimize = optimize_mode,
|
|
|
|
.target = c_abi_target,
|
|
|
|
});
|
|
|
|
if (c_abi_target.abi != null and c_abi_target.abi.?.isMusl()) {
|
|
|
|
// TODO NativeTargetInfo insists on dynamically linking musl
|
|
|
|
// for some reason?
|
|
|
|
test_step.target_info.dynamic_linker.max_byte = null;
|
|
|
|
}
|
|
|
|
test_step.linkLibC();
|
|
|
|
test_step.addCSourceFile("test/c_abi/cfuncs.c", &.{"-std=c99"});
|
2023-03-14 06:41:41 +00:00
|
|
|
|
|
|
|
// test-c-abi should test both with LTO on and with LTO off. Only
|
|
|
|
// some combinations are passing currently:
|
|
|
|
// https://github.com/ziglang/zig/issues/14908
|
2023-03-15 04:02:52 +00:00
|
|
|
if (c_abi_target.isWindows()) {
|
2023-03-14 06:41:41 +00:00
|
|
|
test_step.want_lto = false;
|
|
|
|
}
|
2023-01-19 05:37:20 +00:00
|
|
|
|
2023-03-07 05:57:53 +00:00
|
|
|
const triple_prefix = c_abi_target.zigTriple(b.allocator) catch @panic("OOM");
|
2023-03-14 06:42:15 +00:00
|
|
|
test_step.setName(b.fmt("test-c-abi-{s}-{s} ", .{
|
|
|
|
triple_prefix, @tagName(optimize_mode),
|
2023-03-07 05:57:53 +00:00
|
|
|
}));
|
2022-10-21 20:01:49 +00:00
|
|
|
|
2023-03-12 07:39:21 +00:00
|
|
|
const run = test_step.run();
|
|
|
|
run.skip_foreign_checks = true;
|
|
|
|
step.dependOn(&run.step);
|
2023-03-07 05:57:53 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-21 20:01:49 +00:00
|
|
|
return step;
|
|
|
|
}
|
re-enable test-cases and get them all passing
Instead of using `zig test` to build a special version of the compiler
that runs all the test-cases, the zig build system is now used as much
as possible - all with the basic steps found in the standard library.
For incremental compilation tests (the ones that look like foo.0.zig,
foo.1.zig, foo.2.zig, etc.), a special version of the compiler is
compiled into a utility executable called "check-case" which checks
exactly one sequence of incremental updates in an independent
subprocess. Previously, all incremental and non-incremental test cases
were done in the same test runner process.
The compile error checking code is now simpler, but also a bit
rudimentary, and so it additionally makes sure that the actual compile
errors do not include *extra* messages, and it makes sure that the
actual compile errors output in the same order as expected. It is also
based on the "ends-with" property of each line rather than the previous
logic, which frankly I didn't want to touch with a ten-meter pole. The
compile error test cases have been updated to pass in light of these
differences.
Previously, 'error' mode with 0 compile errors was used to shoehorn in a
different kind of test-case - one that only checks if a piece of code
compiles without errors. Now there is a 'compile' mode of test-cases,
and 'error' must be only used when there are greater than 0 errors.
link test cases are updated to omit the target object format argument
when calling checkObject since that is no longer needed.
The test/stage2 directory is removed; the 2 files within are moved to be
directly in the test/ directory.
2023-03-10 01:22:51 +00:00
|
|
|
|
|
|
|
pub fn addCases(
|
|
|
|
b: *std.Build,
|
|
|
|
parent_step: *Step,
|
|
|
|
opt_test_filter: ?[]const u8,
|
|
|
|
check_case_exe: *std.Build.CompileStep,
|
|
|
|
) !void {
|
|
|
|
const arena = b.allocator;
|
|
|
|
const gpa = b.allocator;
|
|
|
|
|
|
|
|
var cases = @import("src/Cases.zig").init(gpa, arena);
|
|
|
|
|
|
|
|
var dir = try b.build_root.handle.openIterableDir("test/cases", .{});
|
|
|
|
defer dir.close();
|
|
|
|
|
|
|
|
cases.addFromDir(dir);
|
|
|
|
try @import("cases.zig").addCases(&cases);
|
|
|
|
|
|
|
|
const cases_dir_path = try b.build_root.join(b.allocator, &.{ "test", "cases" });
|
|
|
|
cases.lowerToBuildSteps(
|
|
|
|
b,
|
|
|
|
parent_step,
|
|
|
|
opt_test_filter,
|
|
|
|
cases_dir_path,
|
|
|
|
check_case_exe,
|
|
|
|
);
|
|
|
|
}
|