diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-04-20 17:54:11 +0100 |
|---|---|---|
| committer | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-04-22 22:50:36 +0100 |
| commit | 927f233ff82bd422b387b4eef7fcbc67823e4b85 (patch) | |
| tree | b921686a62e6e60efa6db973488d9fffb93c8ebb /lib/std/Build/Module.zig | |
| parent | 6a7ca4b8b0fcce9e5f6a4d3f799e83021929c975 (diff) | |
| download | zig-927f233ff82bd422b387b4eef7fcbc67823e4b85.tar.gz zig-927f233ff82bd422b387b4eef7fcbc67823e4b85.zip | |
compiler: allow emitting tests to an object file
This is fairly straightforward; the actual compiler changes are limited
to the CLI, since `Compilation` already supports this combination.
A new `std.Build` API is introduced to allow representing this. By
passing the `emit_object` option to `std.Build.addTest`, you get a
`Step.Compile` which emits an object file; you can then use that as you
would any other object, such as either installing it for external use,
or linking it into another step.
A standalone test is added to cover the build system API. It builds a
test into an object, and links it into a final executable, which it then
runs.
Using this build system mechanism prevents the build system from
noticing that you're running a `zig test`, so the build runner and test
runner do not communicate over stdio. However, that's okay, because the
real-world use cases for this feature don't want to do that anyway!
Resolves: #23374
Diffstat (limited to 'lib/std/Build/Module.zig')
| -rw-r--r-- | lib/std/Build/Module.zig | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig index 0bc77b0741..ff85d5a6c7 100644 --- a/lib/std/Build/Module.zig +++ b/lib/std/Build/Module.zig @@ -474,7 +474,7 @@ pub fn addObjectFile(m: *Module, object: LazyPath) void { } pub fn addObject(m: *Module, object: *Step.Compile) void { - assert(object.kind == .obj); + assert(object.kind == .obj or object.kind == .test_obj); m.linkLibraryOrObject(object); } |
