2017-04-19 19:00:12 +01:00
|
|
|
const std = @import("std");
|
2021-10-05 07:47:27 +01:00
|
|
|
const builtin = @import("builtin");
|
2017-04-19 19:00:12 +01:00
|
|
|
const debug = std.debug;
|
|
|
|
const build = std.build;
|
2020-02-26 06:18:23 +00:00
|
|
|
const CrossTarget = std.zig.CrossTarget;
|
2017-04-19 19:00:12 +01:00
|
|
|
const io = std.io;
|
2019-05-26 18:17:34 +01:00
|
|
|
const fs = std.fs;
|
2017-04-19 19:00:12 +01:00
|
|
|
const mem = std.mem;
|
|
|
|
const fmt = std.fmt;
|
2017-05-04 19:05:06 +01:00
|
|
|
const ArrayList = std.ArrayList;
|
2021-10-05 07:47:27 +01:00
|
|
|
const Mode = std.builtin.Mode;
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const LibExeObjStep = build.LibExeObjStep;
|
2022-02-03 22:27:01 +00:00
|
|
|
const Allocator = mem.Allocator;
|
|
|
|
const ExecError = build.Builder.ExecError;
|
2017-04-19 19:00:12 +01:00
|
|
|
|
2020-01-03 03:45:48 +00:00
|
|
|
// Cases
|
2017-04-19 21:59:20 +01:00
|
|
|
const compare_output = @import("compare_output.zig");
|
2019-07-16 17:15:46 +01:00
|
|
|
const standalone = @import("standalone.zig");
|
2019-09-03 15:08:39 +01:00
|
|
|
const stack_traces = @import("stack_traces.zig");
|
2017-04-19 21:59:20 +01: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");
|
2018-01-23 03:24:07 +00:00
|
|
|
const gen_h = @import("gen_h.zig");
|
2022-05-28 10:44:53 +01:00
|
|
|
const link = @import("link.zig");
|
2017-04-19 19:00:12 +01: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;
|
2020-01-05 07:01:28 +00:00
|
|
|
pub const CompareOutputContext = @import("src/compare_output.zig").CompareOutputContext;
|
2020-01-03 03:45:48 +00:00
|
|
|
|
2019-09-22 04:55:56 +01:00
|
|
|
const TestTarget = struct {
|
2020-02-26 06:18:23 +00:00
|
|
|
target: CrossTarget = @as(CrossTarget, .{}),
|
2021-10-05 07:47:27 +01:00
|
|
|
mode: std.builtin.Mode = .Debug,
|
2019-09-22 04:55:56 +01:00
|
|
|
link_libc: bool = false,
|
|
|
|
single_threaded: bool = false,
|
2019-09-22 19:40:54 +01:00
|
|
|
disable_native: bool = false,
|
2022-04-22 04:28:36 +01:00
|
|
|
backend: ?std.builtin.CompilerBackend = null,
|
2019-09-22 04:55:56 +01: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 04:28:36 +01:00
|
|
|
.{},
|
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.single_threaded = true,
|
|
|
|
},
|
2019-09-22 04:55:56 +01:00
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2022-11-01 02:30:34 +00:00
|
|
|
.target = .{
|
|
|
|
.ofmt = .c,
|
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.link_libc = true,
|
|
|
|
.backend = .stage2_c,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
.backend = .stage2_x86_64,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.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 04:28:36 +01:00
|
|
|
.{
|
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .macos,
|
2022-05-15 16:56:51 +01:00
|
|
|
.abi = .none,
|
2022-04-22 04:28:36 +01:00
|
|
|
},
|
|
|
|
.backend = .stage2_aarch64,
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .macos,
|
2022-05-15 16:56:51 +01:00
|
|
|
.abi = .none,
|
2022-04-22 04:28:36 +01:00
|
|
|
},
|
|
|
|
.backend = .stage2_x86_64,
|
|
|
|
},
|
2022-09-06 16:53:21 +01:00
|
|
|
.{
|
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
.backend = .stage2_x86_64,
|
|
|
|
},
|
2022-04-22 04:28:36 +01: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 16:23:49 +01:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .wasm32,
|
|
|
|
.os_tag = .wasi,
|
|
|
|
},
|
|
|
|
.link_libc = false,
|
|
|
|
.single_threaded = true,
|
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2021-07-27 00:59:34 +01: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 16:23:49 +01:00
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .gnu,
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
2022-10-07 18:54:44 +01: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 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
2022-10-07 18:54:44 +01: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 04:28:36 +01:00
|
|
|
.{
|
2021-06-06 10:12:41 +01:00
|
|
|
.target = .{
|
2022-10-07 18:54:44 +01:00
|
|
|
.cpu_arch = .x86,
|
2021-06-06 10:12:41 +01:00
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2019-11-30 15:13:33 +00:00
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .gnu,
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2021-09-07 17:44:21 +01:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2019-09-22 04:55:56 +01:00
|
|
|
|
2022-04-22 04:28:36 +01: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 04:55:56 +01:00
|
|
|
},
|
2022-04-22 04:28:36 +01: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 20:57:13 +01:00
|
|
|
},
|
2020-04-03 23:36:13 +01:00
|
|
|
// https://github.com/ziglang/zig/issues/3287
|
2022-04-22 04:28:36 +01: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 04:55:56 +01:00
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2021-08-31 18:36:33 +01:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .mips,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
2021-04-03 00:33:07 +01:00
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2021-08-31 18:36:33 +01:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .mips,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2021-04-03 00:33:07 +01:00
|
|
|
|
2020-04-21 17:42:21 +01:00
|
|
|
// https://github.com/ziglang/zig/issues/4927
|
2022-04-22 04:28:36 +01:00
|
|
|
//.{
|
2020-04-21 17:42:21 +01:00
|
|
|
// .target = .{
|
|
|
|
// .cpu_arch = .mips,
|
|
|
|
// .os_tag = .linux,
|
2021-12-16 01:59:59 +00:00
|
|
|
// .abi = .gnueabihf,
|
2020-04-21 17:42:21 +01:00
|
|
|
// },
|
|
|
|
// .link_libc = true,
|
|
|
|
//},
|
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2021-08-31 18:36:33 +01:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .mipsel,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
2021-04-03 00:33:07 +01:00
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2021-08-31 18:36:33 +01:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .mipsel,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2021-04-03 00:33:07 +01:00
|
|
|
|
2020-04-03 23:36:13 +01:00
|
|
|
// https://github.com/ziglang/zig/issues/4927
|
2022-04-22 04:28:36 +01:00
|
|
|
//.{
|
2020-04-03 23:36:13 +01:00
|
|
|
// .target = .{
|
|
|
|
// .cpu_arch = .mipsel,
|
|
|
|
// .os_tag = .linux,
|
2021-12-16 01:59:59 +00:00
|
|
|
// .abi = .gnueabihf,
|
2020-04-03 23:36:13 +01:00
|
|
|
// },
|
|
|
|
// .link_libc = true,
|
|
|
|
//},
|
2019-09-21 22:00:36 +01:00
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2021-04-20 21:08:19 +01:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .powerpc,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2021-04-20 21:08:19 +01: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 04:28:36 +01:00
|
|
|
//.{
|
2021-12-16 02:25:26 +00:00
|
|
|
// .target = .{
|
|
|
|
// .cpu_arch = .powerpc,
|
|
|
|
// .os_tag = .linux,
|
|
|
|
// .abi = .gnueabihf,
|
|
|
|
// },
|
|
|
|
// .link_libc = true,
|
|
|
|
//},
|
2021-04-20 21:08:19 +01:00
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-04-03 00:48:48 +01:00
|
|
|
.target = .{
|
2022-10-11 19:11:46 +01: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-03 00:48:48 +01:00
|
|
|
.cpu_arch = .riscv64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
2020-02-17 05:06:19 +00:00
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-04-03 16:02:22 +01: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 04:28:36 +01: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 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
2020-10-12 09:59:43 +01:00
|
|
|
.os_tag = .macos,
|
2022-05-15 16:56:51 +01:00
|
|
|
.abi = .none,
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
2021-12-01 23:11:29 +00:00
|
|
|
},
|
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2021-12-01 23:11:29 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .aarch64,
|
|
|
|
.os_tag = .macos,
|
2022-05-15 16:56:51 +01:00
|
|
|
.abi = .none,
|
2021-12-01 23:11:29 +00:00
|
|
|
},
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
2022-10-07 18:54:44 +01:00
|
|
|
.cpu_arch = .x86,
|
2020-02-26 06:18:23 +00:00
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .msvc,
|
2019-10-11 18:13:59 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .msvc,
|
2019-09-22 04:55:56 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
2022-10-07 18:54:44 +01:00
|
|
|
.cpu_arch = .x86,
|
2020-02-26 06:18:23 +00:00
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .gnu,
|
2019-10-09 21:49:33 +01:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-10-09 21:49:33 +01:00
|
|
|
},
|
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-02-26 06:18:23 +00:00
|
|
|
.target = .{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .windows,
|
|
|
|
.abi = .gnu,
|
2019-09-23 00:11:41 +01:00
|
|
|
},
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
2019-09-23 00:11:41 +01:00
|
|
|
},
|
2019-09-22 19:41:47 +01:00
|
|
|
|
2020-01-22 22:13:31 +00:00
|
|
|
// Do the release tests last because they take a long time
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.mode = .ReleaseFast,
|
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
|
|
|
.mode = .ReleaseFast,
|
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.mode = .ReleaseFast,
|
|
|
|
.single_threaded = true,
|
|
|
|
},
|
2019-09-22 19:41:47 +01:00
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.mode = .ReleaseSafe,
|
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
|
|
|
.mode = .ReleaseSafe,
|
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.mode = .ReleaseSafe,
|
|
|
|
.single_threaded = true,
|
|
|
|
},
|
2019-09-22 19:41:47 +01:00
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.mode = .ReleaseSmall,
|
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.link_libc = true,
|
|
|
|
.mode = .ReleaseSmall,
|
|
|
|
},
|
2022-04-22 04:28:36 +01:00
|
|
|
.{
|
2020-01-22 22:13:31 +00:00
|
|
|
.mode = .ReleaseSmall,
|
|
|
|
.single_threaded = true,
|
|
|
|
},
|
|
|
|
};
|
2017-08-30 19:55:26 +01:00
|
|
|
};
|
|
|
|
|
2017-10-31 08:47:55 +00:00
|
|
|
const max_stdout_size = 1 * 1024 * 1024; // 1 MB
|
|
|
|
|
2018-07-12 00:38:01 +01:00
|
|
|
pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
|
2019-02-03 21:13:28 +00:00
|
|
|
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
|
|
|
cases.* = CompareOutputContext{
|
2017-04-19 19:00:12 +01:00
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-compare-output", "Run the compare output tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2018-07-12 00:38:01 +01:00
|
|
|
.modes = modes,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 19:00:12 +01:00
|
|
|
|
|
|
|
compare_output.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2019-09-03 15:08:39 +01:00
|
|
|
pub fn addStackTraceTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
|
|
|
|
const cases = b.allocator.create(StackTracesContext) catch unreachable;
|
|
|
|
cases.* = StackTracesContext{
|
2019-05-28 01:07:05 +01:00
|
|
|
.b = b,
|
2019-09-03 15:08:39 +01:00
|
|
|
.step = b.step("test-stack-traces", "Run the stack trace tests"),
|
2019-05-28 01:07:05 +01:00
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
|
|
|
.modes = modes,
|
|
|
|
};
|
|
|
|
|
2019-09-03 15:08:39 +01:00
|
|
|
stack_traces.addCases(cases);
|
2019-05-28 01:07:05 +01:00
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2021-08-02 09:04:54 +01:00
|
|
|
pub fn addStandaloneTests(
|
|
|
|
b: *build.Builder,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
modes: []const Mode,
|
|
|
|
skip_non_native: bool,
|
|
|
|
enable_macos_sdk: bool,
|
|
|
|
target: std.zig.CrossTarget,
|
2022-08-18 06:17:19 +01:00
|
|
|
omit_stage2: bool,
|
2022-07-20 20:51:18 +01:00
|
|
|
enable_darling: bool,
|
|
|
|
enable_qemu: bool,
|
|
|
|
enable_rosetta: bool,
|
|
|
|
enable_wasmtime: bool,
|
|
|
|
enable_wine: bool,
|
2021-08-02 09:04:54 +01:00
|
|
|
) *build.Step {
|
2019-07-16 17:15:46 +01:00
|
|
|
const cases = b.allocator.create(StandaloneContext) catch unreachable;
|
|
|
|
cases.* = StandaloneContext{
|
2017-04-19 19:00:12 +01:00
|
|
|
.b = b,
|
2019-07-16 17:15:46 +01:00
|
|
|
.step = b.step("test-standalone", "Run the standalone tests"),
|
2017-04-19 19:00:12 +01:00
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2018-07-18 09:28:14 +01:00
|
|
|
.modes = modes,
|
2021-05-03 07:48:14 +01:00
|
|
|
.skip_non_native = skip_non_native,
|
2021-08-02 09:04:54 +01:00
|
|
|
.enable_macos_sdk = enable_macos_sdk,
|
2021-05-03 07:48:14 +01:00
|
|
|
.target = target,
|
2022-08-18 06:17:19 +01:00
|
|
|
.omit_stage2 = omit_stage2,
|
2022-07-20 20:51:18 +01:00
|
|
|
.enable_darling = enable_darling,
|
|
|
|
.enable_qemu = enable_qemu,
|
|
|
|
.enable_rosetta = enable_rosetta,
|
|
|
|
.enable_wasmtime = enable_wasmtime,
|
|
|
|
.enable_wine = enable_wine,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 19:00:12 +01:00
|
|
|
|
2019-07-16 17:15:46 +01:00
|
|
|
standalone.addCases(cases);
|
2017-04-19 19:00:12 +01:00
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2022-05-28 10:44:53 +01:00
|
|
|
pub fn addLinkTests(
|
|
|
|
b: *build.Builder,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
modes: []const Mode,
|
|
|
|
enable_macos_sdk: bool,
|
2022-08-18 06:17:19 +01:00
|
|
|
omit_stage2: bool,
|
2022-05-28 10:44:53 +01:00
|
|
|
) *build.Step {
|
|
|
|
const cases = b.allocator.create(StandaloneContext) catch unreachable;
|
|
|
|
cases.* = StandaloneContext{
|
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-link", "Run the linker tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
|
|
|
.modes = modes,
|
|
|
|
.skip_non_native = true,
|
|
|
|
.enable_macos_sdk = enable_macos_sdk,
|
|
|
|
.target = .{},
|
2022-08-18 06:17:19 +01:00
|
|
|
.omit_stage2 = omit_stage2,
|
2022-05-28 10:44:53 +01:00
|
|
|
};
|
|
|
|
link.addCases(cases);
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2018-09-17 22:08:56 +01:00
|
|
|
pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
|
2021-06-20 02:10:22 +01:00
|
|
|
_ = test_filter;
|
|
|
|
_ = modes;
|
2018-09-17 22:08:56 +01:00
|
|
|
const step = b.step("test-cli", "Test the command line interface");
|
|
|
|
|
|
|
|
const exe = b.addExecutable("test-cli", "test/cli.zig");
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const run_cmd = exe.run();
|
2019-11-27 08:30:39 +00:00
|
|
|
run_cmd.addArgs(&[_][]const u8{
|
2019-05-26 18:37:34 +01:00
|
|
|
fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable,
|
2018-09-17 22:08:56 +01:00
|
|
|
b.pathFromRoot(b.cache_root),
|
|
|
|
});
|
|
|
|
|
|
|
|
step.dependOn(&run_cmd.step);
|
|
|
|
return step;
|
|
|
|
}
|
|
|
|
|
2018-07-12 00:38:01 +01:00
|
|
|
pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
|
2019-02-03 21:13:28 +00:00
|
|
|
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
|
|
|
cases.* = CompareOutputContext{
|
2017-04-19 19:00:12 +01:00
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-asm-link", "Run the assemble and link tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2018-07-12 00:38:01 +01:00
|
|
|
.modes = modes,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 19:00:12 +01:00
|
|
|
|
|
|
|
assemble_and_link.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:56:59 +01:00
|
|
|
pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
|
2019-02-03 21:13:28 +00:00
|
|
|
const cases = b.allocator.create(TranslateCContext) catch unreachable;
|
|
|
|
cases.* = TranslateCContext{
|
2017-04-19 21:59:20 +01:00
|
|
|
.b = b,
|
2021-09-24 18:39:20 +01:00
|
|
|
.step = b.step("test-translate-c", "Run the C translation tests"),
|
2017-04-19 21:59:20 +01:00
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 21:59:20 +01:00
|
|
|
|
2017-11-24 19:56:05 +00:00
|
|
|
translate_c.addCases(cases);
|
2017-04-19 21:59:20 +01:00
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2020-12-08 20:46:05 +00:00
|
|
|
pub fn addRunTranslatedCTests(
|
|
|
|
b: *build.Builder,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
target: std.zig.CrossTarget,
|
|
|
|
) *build.Step {
|
2020-01-03 03:45:48 +00:00
|
|
|
const cases = b.allocator.create(RunTranslatedCContext) catch unreachable;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:56:59 +01:00
|
|
|
pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
|
2019-02-03 21:13:28 +00:00
|
|
|
const cases = b.allocator.create(GenHContext) catch unreachable;
|
|
|
|
cases.* = GenHContext{
|
2018-01-23 03:24:07 +00:00
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-gen-h", "Run the C header file generation tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2018-01-23 03:24:07 +00:00
|
|
|
|
|
|
|
gen_h.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2019-05-15 02:21:59 +01:00
|
|
|
pub fn addPkgTests(
|
|
|
|
b: *build.Builder,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
root_src: []const u8,
|
|
|
|
name: []const u8,
|
|
|
|
desc: []const u8,
|
|
|
|
modes: []const Mode,
|
2019-09-22 04:55:56 +01:00
|
|
|
skip_single_threaded: bool,
|
2019-05-15 02:21:59 +01:00
|
|
|
skip_non_native: bool,
|
2019-09-22 04:55:56 +01:00
|
|
|
skip_libc: bool,
|
2022-04-22 04:28:36 +01:00
|
|
|
skip_stage1: bool,
|
|
|
|
skip_stage2: bool,
|
2019-05-15 02:21:59 +01:00
|
|
|
) *build.Step {
|
2020-11-26 12:28:38 +00:00
|
|
|
const step = b.step(b.fmt("test-{s}", .{name}), desc);
|
2019-09-09 22:57:32 +01:00
|
|
|
|
2019-09-22 04:55:56 +01:00
|
|
|
for (test_targets) |test_target| {
|
2020-02-26 06:18:23 +00:00
|
|
|
if (skip_non_native and !test_target.target.isNative())
|
2019-09-22 04:55:56 +01:00
|
|
|
continue;
|
2019-09-09 22:57:32 +01:00
|
|
|
|
2019-09-22 04:55:56 +01:00
|
|
|
if (skip_libc and test_target.link_libc)
|
|
|
|
continue;
|
|
|
|
|
2020-02-26 06:18:23 +00:00
|
|
|
if (test_target.link_libc and test_target.target.getOs().requiresLibC()) {
|
2019-09-22 04:55:56 +01:00
|
|
|
// This would be a redundant test.
|
2019-05-15 02:21:59 +01:00
|
|
|
continue;
|
2017-04-20 07:26:36 +01:00
|
|
|
}
|
2019-09-22 04:55:56 +01:00
|
|
|
|
|
|
|
if (skip_single_threaded and test_target.single_threaded)
|
|
|
|
continue;
|
|
|
|
|
2019-09-22 19:40:54 +01:00
|
|
|
if (test_target.disable_native and
|
2021-10-05 07:47:27 +01:00
|
|
|
test_target.target.getOsTag() == builtin.os.tag and
|
|
|
|
test_target.target.getCpuArch() == builtin.cpu.arch)
|
2019-09-22 19:40:54 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-04-22 04:28:36 +01:00
|
|
|
if (test_target.backend) |backend| switch (backend) {
|
|
|
|
.stage1 => if (skip_stage1) continue,
|
2022-08-22 22:10:45 +01:00
|
|
|
.stage2_llvm => {},
|
2022-04-22 04:28:36 +01:00
|
|
|
else => if (skip_stage2) continue,
|
2022-08-22 22:10:45 +01:00
|
|
|
};
|
2022-04-22 04:28:36 +01:00
|
|
|
|
2019-09-22 04:55:56 +01:00
|
|
|
const want_this_mode = for (modes) |m| {
|
|
|
|
if (m == test_target.mode) break true;
|
|
|
|
} else false;
|
|
|
|
if (!want_this_mode) continue;
|
|
|
|
|
2022-08-11 20:56:46 +01:00
|
|
|
if (test_target.backend) |backend| {
|
|
|
|
if (backend == .stage2_c and builtin.os.tag == .windows) {
|
|
|
|
// https://github.com/ziglang/zig/issues/12415
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-26 06:18:23 +00:00
|
|
|
const libc_prefix = if (test_target.target.getOs().requiresLibC())
|
2019-09-22 04:55:56 +01:00
|
|
|
""
|
|
|
|
else if (test_target.link_libc)
|
|
|
|
"c"
|
|
|
|
else
|
|
|
|
"bare";
|
|
|
|
|
2020-02-26 06:18:23 +00:00
|
|
|
const triple_prefix = test_target.target.zigTriple(b.allocator) catch unreachable;
|
2019-09-22 04:55:56 +01:00
|
|
|
|
|
|
|
const these_tests = b.addTest(root_src);
|
2019-12-09 03:53:51 +00:00
|
|
|
const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
|
2022-04-22 04:28:36 +01:00
|
|
|
const backend_txt = if (test_target.backend) |backend| @tagName(backend) else "default";
|
|
|
|
these_tests.setNamePrefix(b.fmt("{s}-{s}-{s}-{s}-{s}-{s} ", .{
|
2019-09-22 04:55:56 +01:00
|
|
|
name,
|
|
|
|
triple_prefix,
|
|
|
|
@tagName(test_target.mode),
|
|
|
|
libc_prefix,
|
2019-12-09 03:53:51 +00:00
|
|
|
single_threaded_txt,
|
2022-04-22 04:28:36 +01:00
|
|
|
backend_txt,
|
2019-12-09 03:53:51 +00:00
|
|
|
}));
|
2019-09-22 04:55:56 +01:00
|
|
|
these_tests.single_threaded = test_target.single_threaded;
|
|
|
|
these_tests.setFilter(test_filter);
|
|
|
|
these_tests.setBuildMode(test_target.mode);
|
2020-02-26 06:18:23 +00:00
|
|
|
these_tests.setTarget(test_target.target);
|
2019-09-22 04:55:56 +01:00
|
|
|
if (test_target.link_libc) {
|
|
|
|
these_tests.linkSystemLibrary("c");
|
|
|
|
}
|
2019-09-26 04:57:47 +01:00
|
|
|
these_tests.overrideZigLibDir("lib");
|
2022-01-24 18:15:32 +00:00
|
|
|
these_tests.addIncludePath("test");
|
2022-04-22 04:28:36 +01:00
|
|
|
if (test_target.backend) |backend| switch (backend) {
|
|
|
|
.stage1 => {
|
|
|
|
these_tests.use_stage1 = true;
|
|
|
|
},
|
|
|
|
.stage2_llvm => {
|
|
|
|
these_tests.use_stage1 = false;
|
|
|
|
these_tests.use_llvm = true;
|
|
|
|
},
|
|
|
|
.stage2_c => {
|
|
|
|
these_tests.use_stage1 = false;
|
|
|
|
these_tests.use_llvm = false;
|
|
|
|
},
|
|
|
|
else => {
|
|
|
|
these_tests.use_stage1 = false;
|
|
|
|
these_tests.use_llvm = false;
|
2022-09-07 22:16:42 +01:00
|
|
|
// TODO: force self-hosted linkers to avoid LLD creeping in until the auto-select mechanism deems them worthy
|
|
|
|
these_tests.use_lld = false;
|
2022-04-22 04:28:36 +01:00
|
|
|
},
|
|
|
|
};
|
2019-09-22 04:55:56 +01:00
|
|
|
|
|
|
|
step.dependOn(&these_tests.step);
|
2017-04-20 07:26:36 +01:00
|
|
|
}
|
|
|
|
return step;
|
|
|
|
}
|
|
|
|
|
2019-09-03 15:08:39 +01:00
|
|
|
pub const StackTracesContext = struct {
|
2019-05-28 01:07:05 +01:00
|
|
|
b: *build.Builder,
|
|
|
|
step: *build.Step,
|
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
modes: []const Mode,
|
|
|
|
|
|
|
|
const Expect = [@typeInfo(Mode).Enum.fields.len][]const u8;
|
|
|
|
|
2021-04-11 00:51:27 +01:00
|
|
|
pub fn addCase(self: *StackTracesContext, config: anytype) void {
|
|
|
|
if (@hasField(@TypeOf(config), "exclude")) {
|
|
|
|
if (config.exclude.exclude()) return;
|
|
|
|
}
|
|
|
|
if (@hasField(@TypeOf(config), "exclude_arch")) {
|
2021-04-16 03:12:39 +01:00
|
|
|
const exclude_arch: []const std.Target.Cpu.Arch = &config.exclude_arch;
|
2021-04-11 00:51:27 +01:00
|
|
|
for (exclude_arch) |arch| if (arch == builtin.cpu.arch) return;
|
|
|
|
}
|
|
|
|
if (@hasField(@TypeOf(config), "exclude_os")) {
|
2021-04-16 03:12:39 +01:00
|
|
|
const exclude_os: []const std.Target.Os.Tag = &config.exclude_os;
|
2021-04-11 00:51:27 +01:00
|
|
|
for (exclude_os) |os| if (os == builtin.os.tag) return;
|
|
|
|
}
|
|
|
|
for (self.modes) |mode| {
|
|
|
|
switch (mode) {
|
|
|
|
.Debug => {
|
|
|
|
if (@hasField(@TypeOf(config), "Debug")) {
|
|
|
|
self.addExpect(config.name, config.source, mode, config.Debug);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.ReleaseSafe => {
|
|
|
|
if (@hasField(@TypeOf(config), "ReleaseSafe")) {
|
|
|
|
self.addExpect(config.name, config.source, mode, config.ReleaseSafe);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.ReleaseFast => {
|
|
|
|
if (@hasField(@TypeOf(config), "ReleaseFast")) {
|
|
|
|
self.addExpect(config.name, config.source, mode, config.ReleaseFast);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.ReleaseSmall => {
|
|
|
|
if (@hasField(@TypeOf(config), "ReleaseSmall")) {
|
|
|
|
self.addExpect(config.name, config.source, mode, config.ReleaseSmall);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn addExpect(
|
2019-09-03 15:08:39 +01:00
|
|
|
self: *StackTracesContext,
|
2019-05-28 01:07:05 +01:00
|
|
|
name: []const u8,
|
|
|
|
source: []const u8,
|
2021-04-11 00:51:27 +01:00
|
|
|
mode: Mode,
|
|
|
|
mode_config: anytype,
|
2019-05-28 01:07:05 +01:00
|
|
|
) void {
|
2021-04-11 00:51:27 +01:00
|
|
|
if (@hasField(@TypeOf(mode_config), "exclude")) {
|
|
|
|
if (mode_config.exclude.exclude()) return;
|
|
|
|
}
|
|
|
|
if (@hasField(@TypeOf(mode_config), "exclude_arch")) {
|
2021-04-16 03:12:39 +01:00
|
|
|
const exclude_arch: []const std.Target.Cpu.Arch = &mode_config.exclude_arch;
|
2021-04-11 00:51:27 +01:00
|
|
|
for (exclude_arch) |arch| if (arch == builtin.cpu.arch) return;
|
|
|
|
}
|
|
|
|
if (@hasField(@TypeOf(mode_config), "exclude_os")) {
|
2021-04-16 03:12:39 +01:00
|
|
|
const exclude_os: []const std.Target.Os.Tag = &mode_config.exclude_os;
|
2021-04-11 00:51:27 +01:00
|
|
|
for (exclude_os) |os| if (os == builtin.os.tag) return;
|
|
|
|
}
|
2019-05-28 01:07:05 +01:00
|
|
|
|
2021-04-11 00:51:27 +01:00
|
|
|
const annotated_case_name = fmt.allocPrint(self.b.allocator, "{s} {s} ({s})", .{
|
|
|
|
"stack-trace",
|
|
|
|
name,
|
|
|
|
@tagName(mode),
|
|
|
|
}) catch unreachable;
|
|
|
|
if (self.test_filter) |filter| {
|
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
2019-05-28 01:07:05 +01:00
|
|
|
}
|
2021-04-11 00:51:27 +01:00
|
|
|
|
|
|
|
const b = self.b;
|
|
|
|
const src_basename = "source.zig";
|
|
|
|
const write_src = b.addWriteFile(src_basename, source);
|
2021-03-12 03:53:39 +00:00
|
|
|
const exe = b.addExecutableSource("test", write_src.getFileSource(src_basename).?);
|
2021-04-11 00:51:27 +01:00
|
|
|
exe.setBuildMode(mode);
|
|
|
|
|
|
|
|
const run_and_compare = RunAndCompareStep.create(
|
|
|
|
self,
|
|
|
|
exe,
|
|
|
|
annotated_case_name,
|
|
|
|
mode,
|
|
|
|
mode_config.expect,
|
|
|
|
);
|
|
|
|
|
|
|
|
self.step.dependOn(&run_and_compare.step);
|
2019-05-28 01:07:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const RunAndCompareStep = struct {
|
2021-06-11 09:50:48 +01:00
|
|
|
pub const base_id = .custom;
|
|
|
|
|
2019-05-28 01:07:05 +01:00
|
|
|
step: build.Step,
|
2019-09-03 15:08:39 +01:00
|
|
|
context: *StackTracesContext,
|
2019-05-28 01:07:05 +01:00
|
|
|
exe: *LibExeObjStep,
|
|
|
|
name: []const u8,
|
|
|
|
mode: Mode,
|
|
|
|
expect_output: []const u8,
|
|
|
|
test_index: usize,
|
|
|
|
|
|
|
|
pub fn create(
|
2019-09-03 15:08:39 +01:00
|
|
|
context: *StackTracesContext,
|
2019-05-28 01:07:05 +01:00
|
|
|
exe: *LibExeObjStep,
|
|
|
|
name: []const u8,
|
|
|
|
mode: Mode,
|
|
|
|
expect_output: []const u8,
|
|
|
|
) *RunAndCompareStep {
|
|
|
|
const allocator = context.b.allocator;
|
|
|
|
const ptr = allocator.create(RunAndCompareStep) catch unreachable;
|
|
|
|
ptr.* = RunAndCompareStep{
|
2021-06-11 09:50:48 +01:00
|
|
|
.step = build.Step.init(.custom, "StackTraceCompareOutputStep", allocator, make),
|
2019-05-28 01:07:05 +01:00
|
|
|
.context = context,
|
|
|
|
.exe = exe,
|
|
|
|
.name = name,
|
|
|
|
.mode = mode,
|
|
|
|
.expect_output = expect_output,
|
|
|
|
.test_index = context.test_index,
|
|
|
|
};
|
|
|
|
ptr.step.dependOn(&exe.step);
|
|
|
|
context.test_index += 1;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make(step: *build.Step) !void {
|
|
|
|
const self = @fieldParentPtr(RunAndCompareStep, "step", step);
|
|
|
|
const b = self.context.b;
|
|
|
|
|
2021-02-26 10:28:23 +00:00
|
|
|
const full_exe_path = self.exe.getOutputSource().getPath(b);
|
2019-05-28 01:07:05 +01:00
|
|
|
var args = ArrayList([]const u8).init(b.allocator);
|
|
|
|
defer args.deinit();
|
|
|
|
args.append(full_exe_path) catch unreachable;
|
|
|
|
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
2019-05-28 01:07:05 +01:00
|
|
|
|
2022-02-03 22:27:01 +00:00
|
|
|
if (!std.process.can_spawn) {
|
2022-02-05 16:09:55 +00:00
|
|
|
const cmd = try std.mem.join(b.allocator, " ", args.items);
|
2022-02-03 22:27:01 +00:00
|
|
|
std.debug.print("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
|
|
|
|
b.allocator.free(cmd);
|
|
|
|
return ExecError.ExecNotSupported;
|
|
|
|
}
|
|
|
|
|
2022-04-29 16:07:51 +01:00
|
|
|
var child = std.ChildProcess.init(args.items, b.allocator);
|
2019-05-28 01:07:05 +01:00
|
|
|
child.stdin_behavior = .Ignore;
|
|
|
|
child.stdout_behavior = .Pipe;
|
|
|
|
child.stderr_behavior = .Pipe;
|
|
|
|
child.env_map = b.env_map;
|
|
|
|
|
2020-01-26 23:28:52 +00:00
|
|
|
if (b.verbose) {
|
2020-09-27 05:03:38 +01:00
|
|
|
printInvocation(args.items);
|
2020-01-26 23:28:52 +00:00
|
|
|
}
|
2020-11-26 12:28:38 +00:00
|
|
|
child.spawn() catch |err| debug.panic("Unable to spawn {s}: {s}\n", .{ full_exe_path, @errorName(err) });
|
2019-05-28 01:07:05 +01:00
|
|
|
|
2021-01-06 01:57:18 +00:00
|
|
|
const stdout = child.stdout.?.reader().readAllAlloc(b.allocator, max_stdout_size) catch unreachable;
|
2020-02-07 05:11:57 +00:00
|
|
|
defer b.allocator.free(stdout);
|
2021-01-06 01:57:18 +00:00
|
|
|
const stderrFull = child.stderr.?.reader().readAllAlloc(b.allocator, max_stdout_size) catch unreachable;
|
2020-06-03 22:55:18 +01:00
|
|
|
defer b.allocator.free(stderrFull);
|
|
|
|
var stderr = stderrFull;
|
2019-05-28 01:07:05 +01:00
|
|
|
|
|
|
|
const term = child.wait() catch |err| {
|
2020-11-26 12:28:38 +00:00
|
|
|
debug.panic("Unable to spawn {s}: {s}\n", .{ full_exe_path, @errorName(err) });
|
2019-05-28 01:07:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
switch (term) {
|
|
|
|
.Exited => |code| {
|
|
|
|
const expect_code: u32 = 1;
|
|
|
|
if (code != expect_code) {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Process {s} exited with error code {d} but expected code {d}\n", .{
|
2019-12-09 03:53:51 +00:00
|
|
|
full_exe_path,
|
|
|
|
code,
|
|
|
|
expect_code,
|
|
|
|
});
|
2020-09-27 05:03:38 +01:00
|
|
|
printInvocation(args.items);
|
2019-05-28 01:07:05 +01:00
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.Signal => |signum| {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Process {s} terminated on signal {d}\n", .{ full_exe_path, signum });
|
2020-09-27 05:03:38 +01:00
|
|
|
printInvocation(args.items);
|
2019-05-28 01:07:05 +01:00
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
.Stopped => |signum| {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Process {s} stopped on signal {d}\n", .{ full_exe_path, signum });
|
2020-09-27 05:03:38 +01:00
|
|
|
printInvocation(args.items);
|
2019-05-28 01:07:05 +01:00
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
.Unknown => |code| {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Process {s} terminated unexpectedly with error code {d}\n", .{ full_exe_path, code });
|
2020-09-27 05:03:38 +01:00
|
|
|
printInvocation(args.items);
|
2019-05-28 01:07:05 +01:00
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// process result
|
|
|
|
// - keep only basename of source file path
|
|
|
|
// - replace address with symbolic string
|
2021-04-11 00:51:27 +01:00
|
|
|
// - replace function name with symbolic string when mode != .Debug
|
2019-05-28 01:07:05 +01:00
|
|
|
// - skip empty lines
|
|
|
|
const got: []const u8 = got_result: {
|
2020-04-01 17:44:45 +01:00
|
|
|
var buf = ArrayList(u8).init(b.allocator);
|
2019-05-28 01:07:05 +01:00
|
|
|
defer buf.deinit();
|
2020-02-07 05:11:57 +00:00
|
|
|
if (stderr.len != 0 and stderr[stderr.len - 1] == '\n') stderr = stderr[0 .. stderr.len - 1];
|
2021-08-06 10:01:47 +01:00
|
|
|
var it = mem.split(u8, stderr, "\n");
|
2019-05-28 01:07:05 +01:00
|
|
|
process_lines: while (it.next()) |line| {
|
|
|
|
if (line.len == 0) continue;
|
2021-02-23 20:14:50 +00:00
|
|
|
|
2019-05-28 01:07:05 +01:00
|
|
|
// offset search past `[drive]:` on windows
|
2021-10-05 07:47:27 +01:00
|
|
|
var pos: usize = if (builtin.os.tag == .windows) 2 else 0;
|
2021-04-11 00:51:27 +01:00
|
|
|
// locate delims/anchor
|
|
|
|
const delims = [_][]const u8{ ":", ":", ":", " in ", "(", ")" };
|
|
|
|
var marks = [_]usize{0} ** delims.len;
|
2019-05-28 01:07:05 +01:00
|
|
|
for (delims) |delim, i| {
|
|
|
|
marks[i] = mem.indexOfPos(u8, line, pos, delim) orelse {
|
2021-04-11 00:51:27 +01:00
|
|
|
// unexpected pattern: emit raw line and cont
|
2020-04-01 17:44:45 +01:00
|
|
|
try buf.appendSlice(line);
|
|
|
|
try buf.appendSlice("\n");
|
2019-05-28 01:07:05 +01:00
|
|
|
continue :process_lines;
|
|
|
|
};
|
|
|
|
pos = marks[i] + delim.len;
|
|
|
|
}
|
2021-04-11 00:51:27 +01:00
|
|
|
// locate source basename
|
2022-08-19 11:13:04 +01:00
|
|
|
pos = mem.lastIndexOfScalar(u8, line[0..marks[0]], fs.path.sep) orelse {
|
2021-04-11 00:51:27 +01:00
|
|
|
// unexpected pattern: emit raw line and cont
|
2020-04-01 17:44:45 +01:00
|
|
|
try buf.appendSlice(line);
|
|
|
|
try buf.appendSlice("\n");
|
2019-05-28 01:07:05 +01:00
|
|
|
continue :process_lines;
|
|
|
|
};
|
2021-04-11 00:51:27 +01:00
|
|
|
// end processing if source basename changes
|
|
|
|
if (!mem.eql(u8, "source.zig", line[pos + 1 .. marks[0]])) break;
|
|
|
|
// emit substituted line
|
2020-04-01 17:44:45 +01:00
|
|
|
try buf.appendSlice(line[pos + 1 .. marks[2] + delims[2].len]);
|
|
|
|
try buf.appendSlice(" [address]");
|
2021-04-11 00:51:27 +01:00
|
|
|
if (self.mode == .Debug) {
|
2022-08-19 03:40:08 +01:00
|
|
|
// On certain platforms (windows) or possibly depending on how we choose to link main
|
|
|
|
// the object file extension may be present so we simply strip any extension.
|
|
|
|
if (mem.indexOfScalar(u8, line[marks[4]..marks[5]], '.')) |idot| {
|
2021-04-11 00:51:27 +01:00
|
|
|
try buf.appendSlice(line[marks[3] .. marks[4] + idot]);
|
|
|
|
try buf.appendSlice(line[marks[5]..]);
|
|
|
|
} else {
|
|
|
|
try buf.appendSlice(line[marks[3]..]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try buf.appendSlice(line[marks[3] .. marks[3] + delims[3].len]);
|
|
|
|
try buf.appendSlice("[function]");
|
|
|
|
}
|
2020-04-01 17:44:45 +01:00
|
|
|
try buf.appendSlice("\n");
|
2019-05-28 01:07:05 +01:00
|
|
|
}
|
|
|
|
break :got_result buf.toOwnedSlice();
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!mem.eql(u8, self.expect_output, got)) {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print(
|
2019-05-28 01:07:05 +01:00
|
|
|
\\
|
|
|
|
\\========= Expected this output: =========
|
2020-11-26 12:28:38 +00:00
|
|
|
\\{s}
|
2019-05-28 01:07:05 +01:00
|
|
|
\\================================================
|
2020-11-26 12:28:38 +00:00
|
|
|
\\{s}
|
2019-05-28 01:07:05 +01:00
|
|
|
\\
|
2019-12-09 03:53:51 +00:00
|
|
|
, .{ self.expect_output, got });
|
2019-05-28 01:07:05 +01:00
|
|
|
return error.TestFailed;
|
|
|
|
}
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("OK\n", .{});
|
2019-05-28 01:07:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-07-16 17:15:46 +01:00
|
|
|
pub const StandaloneContext = struct {
|
2018-05-31 15:56:59 +01:00
|
|
|
b: *build.Builder,
|
|
|
|
step: *build.Step,
|
2017-04-19 19:00:12 +01:00
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
2018-07-18 09:28:14 +01:00
|
|
|
modes: []const Mode,
|
2021-05-03 07:48:14 +01:00
|
|
|
skip_non_native: bool,
|
2021-08-02 09:04:54 +01:00
|
|
|
enable_macos_sdk: bool,
|
2021-05-03 07:48:14 +01:00
|
|
|
target: std.zig.CrossTarget,
|
2022-08-18 06:17:19 +01:00
|
|
|
omit_stage2: bool,
|
2022-07-20 20:51:18 +01:00
|
|
|
enable_darling: bool = false,
|
|
|
|
enable_qemu: bool = false,
|
|
|
|
enable_rosetta: bool = false,
|
|
|
|
enable_wasmtime: bool = false,
|
|
|
|
enable_wine: bool = false,
|
2017-04-19 19:00:12 +01:00
|
|
|
|
2019-07-16 17:15:46 +01:00
|
|
|
pub fn addC(self: *StandaloneContext, root_src: []const u8) void {
|
2017-04-19 19:00:12 +01:00
|
|
|
self.addAllArgs(root_src, true);
|
|
|
|
}
|
|
|
|
|
2019-07-16 17:15:46 +01:00
|
|
|
pub fn add(self: *StandaloneContext, root_src: []const u8) void {
|
2017-04-19 19:00:12 +01:00
|
|
|
self.addAllArgs(root_src, false);
|
|
|
|
}
|
|
|
|
|
2021-08-02 09:04:54 +01:00
|
|
|
pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8, features: struct {
|
|
|
|
build_modes: bool = false,
|
|
|
|
cross_targets: bool = false,
|
|
|
|
requires_macos_sdk: bool = false,
|
2022-07-12 13:36:33 +01:00
|
|
|
requires_stage2: bool = false,
|
2022-07-20 20:51:18 +01:00
|
|
|
use_emulation: bool = false,
|
2021-08-02 09:04:54 +01:00
|
|
|
}) void {
|
2017-04-21 06:56:12 +01:00
|
|
|
const b = self.b;
|
|
|
|
|
2021-08-02 09:04:54 +01:00
|
|
|
if (features.requires_macos_sdk and !self.enable_macos_sdk) return;
|
2022-08-18 06:17:19 +01:00
|
|
|
if (features.requires_stage2 and self.omit_stage2) return;
|
2021-08-02 09:04:54 +01:00
|
|
|
|
2021-05-03 07:48:14 +01:00
|
|
|
const annotated_case_name = b.fmt("build {s}", .{build_file});
|
2017-05-03 22:23:11 +01:00
|
|
|
if (self.test_filter) |filter| {
|
2018-05-18 04:21:44 +01:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
2017-04-21 06:56:12 +01:00
|
|
|
}
|
|
|
|
|
2017-05-04 19:05:06 +01:00
|
|
|
var zig_args = ArrayList([]const u8).init(b.allocator);
|
2019-05-26 18:17:34 +01:00
|
|
|
const rel_zig_exe = fs.path.relative(b.allocator, b.build_root, b.zig_exe) catch unreachable;
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append(rel_zig_exe) catch unreachable;
|
|
|
|
zig_args.append("build") catch unreachable;
|
2017-04-21 06:56:12 +01:00
|
|
|
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append("--build-file") catch unreachable;
|
|
|
|
zig_args.append(b.pathFromRoot(build_file)) catch unreachable;
|
2017-04-21 06:56:12 +01:00
|
|
|
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append("test") catch unreachable;
|
2017-04-21 06:56:12 +01:00
|
|
|
|
|
|
|
if (b.verbose) {
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append("--verbose") catch unreachable;
|
2017-04-21 06:56:12 +01:00
|
|
|
}
|
|
|
|
|
2021-05-03 07:48:14 +01:00
|
|
|
if (features.cross_targets and !self.target.isNative()) {
|
2022-06-20 16:29:00 +01:00
|
|
|
const target_triple = self.target.zigTriple(b.allocator) catch unreachable;
|
|
|
|
const target_arg = fmt.allocPrint(b.allocator, "-Dtarget={s}", .{target_triple}) catch unreachable;
|
2021-05-03 07:48:14 +01:00
|
|
|
zig_args.append(target_arg) catch unreachable;
|
|
|
|
}
|
2017-04-21 06:56:12 +01:00
|
|
|
|
2022-07-20 20:51:18 +01:00
|
|
|
if (features.use_emulation) {
|
|
|
|
if (self.enable_darling) {
|
|
|
|
zig_args.append("-fdarling") catch unreachable;
|
|
|
|
}
|
|
|
|
if (self.enable_qemu) {
|
|
|
|
zig_args.append("-fqemu") catch unreachable;
|
|
|
|
}
|
|
|
|
if (self.enable_rosetta) {
|
|
|
|
zig_args.append("-frosetta") catch unreachable;
|
|
|
|
}
|
|
|
|
if (self.enable_wasmtime) {
|
|
|
|
zig_args.append("-fwasmtime") catch unreachable;
|
|
|
|
}
|
|
|
|
if (self.enable_wine) {
|
|
|
|
zig_args.append("-fwine") catch unreachable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-03 07:48:14 +01:00
|
|
|
const modes = if (features.build_modes) self.modes else &[1]Mode{.Debug};
|
|
|
|
for (modes) |mode| {
|
|
|
|
const arg = switch (mode) {
|
|
|
|
.Debug => "",
|
|
|
|
.ReleaseFast => "-Drelease-fast",
|
|
|
|
.ReleaseSafe => "-Drelease-safe",
|
|
|
|
.ReleaseSmall => "-Drelease-small",
|
|
|
|
};
|
|
|
|
const zig_args_base_len = zig_args.items.len;
|
|
|
|
if (arg.len > 0)
|
|
|
|
zig_args.append(arg) catch unreachable;
|
|
|
|
defer zig_args.resize(zig_args_base_len) catch unreachable;
|
|
|
|
|
|
|
|
const run_cmd = b.addSystemCommand(zig_args.items);
|
2022-07-22 06:44:11 +01:00
|
|
|
const log_step = b.addLog("PASS {s} ({s})", .{ annotated_case_name, @tagName(mode) });
|
2021-05-03 07:48:14 +01:00
|
|
|
log_step.step.dependOn(&run_cmd.step);
|
2017-04-21 06:56:12 +01:00
|
|
|
|
2021-05-03 07:48:14 +01:00
|
|
|
self.step.dependOn(&log_step.step);
|
|
|
|
}
|
2017-04-21 06:56:12 +01:00
|
|
|
}
|
|
|
|
|
2019-07-16 17:15:46 +01:00
|
|
|
pub fn addAllArgs(self: *StandaloneContext, root_src: []const u8, link_libc: bool) void {
|
2017-04-19 19:00:12 +01:00
|
|
|
const b = self.b;
|
|
|
|
|
2018-07-18 09:28:14 +01:00
|
|
|
for (self.modes) |mode| {
|
2020-11-26 12:28:38 +00:00
|
|
|
const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {s} ({s})", .{
|
2019-12-09 03:53:51 +00:00
|
|
|
root_src,
|
|
|
|
@tagName(mode),
|
|
|
|
}) catch unreachable;
|
2017-05-03 22:23:11 +01:00
|
|
|
if (self.test_filter) |filter| {
|
2018-05-18 04:21:44 +01:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
|
2017-04-19 19:00:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const exe = b.addExecutable("test", root_src);
|
2017-05-02 22:34:21 +01:00
|
|
|
exe.setBuildMode(mode);
|
2017-04-19 19:00:12 +01:00
|
|
|
if (link_libc) {
|
2017-04-21 06:56:12 +01:00
|
|
|
exe.linkSystemLibrary("c");
|
2017-04-19 19:00:12 +01:00
|
|
|
}
|
|
|
|
|
2022-07-22 06:44:11 +01:00
|
|
|
const log_step = b.addLog("PASS {s}", .{annotated_case_name});
|
2017-04-19 19:00:12 +01:00
|
|
|
log_step.step.dependOn(&exe.step);
|
|
|
|
|
|
|
|
self.step.dependOn(&log_step.step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-04-19 21:59:20 +01:00
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
pub const GenHContext = struct {
|
2018-05-31 15:56:59 +01:00
|
|
|
b: *build.Builder,
|
|
|
|
step: *build.Step,
|
2018-01-23 03:24:07 +00:00
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const TestCase = struct {
|
2018-01-23 03:24:07 +00:00
|
|
|
name: []const u8,
|
|
|
|
sources: ArrayList(SourceFile),
|
|
|
|
expected_lines: ArrayList([]const u8),
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const SourceFile = struct {
|
2018-01-23 03:24:07 +00:00
|
|
|
filename: []const u8,
|
|
|
|
source: []const u8,
|
|
|
|
};
|
|
|
|
|
2018-05-31 15:56:59 +01:00
|
|
|
pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
|
2018-11-13 13:08:37 +00:00
|
|
|
self.sources.append(SourceFile{
|
2018-01-23 03:24:07 +00:00
|
|
|
.filename = filename,
|
|
|
|
.source = source,
|
|
|
|
}) catch unreachable;
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:56:59 +01:00
|
|
|
pub fn addExpectedLine(self: *TestCase, text: []const u8) void {
|
2018-01-23 03:24:07 +00:00
|
|
|
self.expected_lines.append(text) catch unreachable;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const GenHCmpOutputStep = struct {
|
2018-01-23 03:24:07 +00:00
|
|
|
step: build.Step,
|
2018-05-31 15:56:59 +01:00
|
|
|
context: *GenHContext,
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
obj: *LibExeObjStep,
|
2018-01-23 03:24:07 +00:00
|
|
|
name: []const u8,
|
|
|
|
test_index: usize,
|
2018-05-31 15:56:59 +01:00
|
|
|
case: *const TestCase,
|
2018-01-23 03:24:07 +00:00
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
pub fn create(
|
|
|
|
context: *GenHContext,
|
|
|
|
obj: *LibExeObjStep,
|
|
|
|
name: []const u8,
|
|
|
|
case: *const TestCase,
|
|
|
|
) *GenHCmpOutputStep {
|
2018-01-23 03:24:07 +00:00
|
|
|
const allocator = context.b.allocator;
|
2019-02-03 21:13:28 +00:00
|
|
|
const ptr = allocator.create(GenHCmpOutputStep) catch unreachable;
|
|
|
|
ptr.* = GenHCmpOutputStep{
|
2020-05-25 09:36:12 +01:00
|
|
|
.step = build.Step.init(.Custom, "ParseCCmpOutput", allocator, make),
|
2018-01-23 03:24:07 +00:00
|
|
|
.context = context,
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
.obj = obj,
|
2018-01-23 03:24:07 +00:00
|
|
|
.name = name,
|
|
|
|
.test_index = context.test_index,
|
|
|
|
.case = case,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
ptr.step.dependOn(&obj.step);
|
2018-01-23 03:24:07 +00:00
|
|
|
context.test_index += 1;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:56:59 +01:00
|
|
|
fn make(step: *build.Step) !void {
|
2018-01-23 03:24:07 +00:00
|
|
|
const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);
|
|
|
|
const b = self.context.b;
|
|
|
|
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Test {d}/{d} {s}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
2018-01-23 03:24:07 +00:00
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const full_h_path = self.obj.getOutputHPath();
|
2018-02-09 23:27:50 +00:00
|
|
|
const actual_h = try io.readFileAlloc(b.allocator, full_h_path);
|
2018-01-23 03:24:07 +00:00
|
|
|
|
2020-09-27 05:03:38 +01:00
|
|
|
for (self.case.expected_lines.items) |expected_line| {
|
2018-01-23 03:24:07 +00:00
|
|
|
if (mem.indexOf(u8, actual_h, expected_line) == null) {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print(
|
2018-01-23 03:24:07 +00:00
|
|
|
\\
|
|
|
|
\\========= Expected this output: ================
|
2020-11-26 12:28:38 +00:00
|
|
|
\\{s}
|
2019-05-25 12:43:52 +01:00
|
|
|
\\========= But found: ===========================
|
2020-11-26 12:28:38 +00:00
|
|
|
\\{s}
|
2018-01-23 03:24:07 +00:00
|
|
|
\\
|
2019-12-09 03:53:51 +00:00
|
|
|
, .{ expected_line, actual_h });
|
2018-01-23 03:24:07 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
}
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("OK\n", .{});
|
2018-01-23 03:24:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-09 19:55:51 +00:00
|
|
|
pub fn create(
|
|
|
|
self: *GenHContext,
|
|
|
|
filename: []const u8,
|
|
|
|
name: []const u8,
|
|
|
|
source: []const u8,
|
|
|
|
expected_lines: []const []const u8,
|
|
|
|
) *TestCase {
|
2019-02-03 21:13:28 +00:00
|
|
|
const tc = self.b.allocator.create(TestCase) catch unreachable;
|
|
|
|
tc.* = TestCase{
|
2018-01-23 03:24:07 +00:00
|
|
|
.name = name,
|
|
|
|
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
|
|
|
.expected_lines = ArrayList([]const u8).init(self.b.allocator),
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2018-06-20 16:40:21 +01:00
|
|
|
|
2018-01-23 03:24:07 +00:00
|
|
|
tc.addSourceFile(filename, source);
|
2019-12-09 19:55:51 +00:00
|
|
|
var arg_i: usize = 0;
|
|
|
|
while (arg_i < expected_lines.len) : (arg_i += 1) {
|
2018-01-23 03:24:07 +00:00
|
|
|
tc.addExpectedLine(expected_lines[arg_i]);
|
|
|
|
}
|
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
2019-12-09 19:55:51 +00:00
|
|
|
pub fn add(self: *GenHContext, name: []const u8, source: []const u8, expected_lines: []const []const u8) void {
|
2019-03-11 14:29:57 +00:00
|
|
|
const tc = self.create("test.zig", name, source, expected_lines);
|
2018-01-23 03:24:07 +00:00
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:56:59 +01:00
|
|
|
pub fn addCase(self: *GenHContext, case: *const TestCase) void {
|
2018-01-23 03:24:07 +00:00
|
|
|
const b = self.b;
|
|
|
|
|
2021-10-05 07:47:27 +01:00
|
|
|
const mode = std.builtin.Mode.Debug;
|
2020-11-26 12:28:38 +00:00
|
|
|
const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {s} ({s})", .{ case.name, @tagName(mode) }) catch unreachable;
|
2018-01-23 03:24:07 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2018-05-18 04:21:44 +01:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
2018-01-23 03:24:07 +00:00
|
|
|
}
|
|
|
|
|
2020-01-05 18:08:18 +00:00
|
|
|
const write_src = b.addWriteFiles();
|
2020-09-27 05:03:38 +01:00
|
|
|
for (case.sources.items) |src_file| {
|
2020-01-05 18:08:18 +00:00
|
|
|
write_src.add(src_file.filename, src_file.source);
|
2018-01-23 03:24:07 +00:00
|
|
|
}
|
|
|
|
|
2020-01-05 18:08:18 +00:00
|
|
|
const obj = b.addObjectFromWriteFileStep("test", write_src, case.sources.items[0].filename);
|
|
|
|
obj.setBuildMode(mode);
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const cmp_h = GenHCmpOutputStep.create(self, obj, annotated_case_name, case);
|
2018-01-23 03:24:07 +00:00
|
|
|
|
|
|
|
self.step.dependOn(&cmp_h.step);
|
|
|
|
}
|
|
|
|
};
|
2019-03-15 21:47:47 +00:00
|
|
|
|
|
|
|
fn printInvocation(args: []const []const u8) void {
|
|
|
|
for (args) |arg| {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("{s} ", .{arg});
|
2019-03-15 21:47:47 +00:00
|
|
|
}
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("\n", .{});
|
2021-03-12 03:53:39 +00:00
|
|
|
}
|
2022-10-21 21:01:49 +01:00
|
|
|
|
|
|
|
const c_abi_targets = [_]CrossTarget{
|
|
|
|
.{},
|
|
|
|
.{
|
|
|
|
.cpu_arch = .x86_64,
|
|
|
|
.os_tag = .linux,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
.{
|
2022-10-07 18:54:44 +01:00
|
|
|
.cpu_arch = .x86,
|
2022-10-21 21:01:49 +01:00
|
|
|
.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,
|
2022-10-22 20:00:59 +01:00
|
|
|
.abi = .musl,
|
2022-10-21 21:01:49 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn addCAbiTests(b: *build.Builder, skip_non_native: bool) *build.Step {
|
|
|
|
const step = b.step("test-c-abi", "Run the C ABI tests");
|
|
|
|
|
|
|
|
for (c_abi_targets) |c_abi_target| {
|
|
|
|
if (skip_non_native and !c_abi_target.isNative())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const test_step = b.addTest("test/c_abi/main.zig");
|
|
|
|
test_step.setTarget(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"});
|
|
|
|
|
|
|
|
const triple_prefix = c_abi_target.zigTriple(b.allocator) catch unreachable;
|
|
|
|
test_step.setNamePrefix(b.fmt("{s}-{s} ", .{
|
|
|
|
"test-c-abi",
|
|
|
|
triple_prefix,
|
|
|
|
}));
|
|
|
|
|
|
|
|
test_step.use_stage1 = false;
|
|
|
|
|
|
|
|
step.dependOn(&test_step.step);
|
|
|
|
}
|
|
|
|
return step;
|
|
|
|
}
|