diff options
| author | Luuk de Gram <luuk@degram.dev> | 2022-07-08 22:57:17 +0200 |
|---|---|---|
| committer | Luuk de Gram <luuk@degram.dev> | 2022-07-23 10:03:46 +0200 |
| commit | fd26c12469a3eda2c99cf58bf951b2223099b9ef (patch) | |
| tree | 3f0ce9d851c61395056e43564e75d59dfa3d4e9e /lib/std/build/CheckObjectStep.zig | |
| parent | a8bfddfaeae4f48c044fd134aac1e977e6a161f8 (diff) | |
| download | zig-fd26c12469a3eda2c99cf58bf951b2223099b9ef.tar.gz zig-fd26c12469a3eda2c99cf58bf951b2223099b9ef.zip | |
RunCompareStep: implement new step
This creates a new step that can run foreign binaries when
emulation is enabled using options such as `enable_qemu`.
When an incompatible binary is found, the binary will not be executed.
This differs from `RunStep` which will always execute a binary,
regardless of the compatibility.
This is useful for usecases where the user wishes to allow for running the
binary on any supported platform either natively or through emulation,
but not generate an error when met with an incompatibility.
The above is useful when creating test cases that rely on running the binary
and optionally verifying its output.
The addition of this Step was generated by the need for our linker tests.
For that reason, a handy function was created on `CheckObjectStep` to ease
the setup for that.
Diffstat (limited to 'lib/std/build/CheckObjectStep.zig')
| -rw-r--r-- | lib/std/build/CheckObjectStep.zig | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/std/build/CheckObjectStep.zig b/lib/std/build/CheckObjectStep.zig index b807e1de45..be1e741ce6 100644 --- a/lib/std/build/CheckObjectStep.zig +++ b/lib/std/build/CheckObjectStep.zig @@ -12,6 +12,7 @@ const CheckObjectStep = @This(); const Allocator = mem.Allocator; const Builder = build.Builder; const Step = build.Step; +const RunCompareStep = build.RunCompareStep; pub const base_id = .check_obj; @@ -37,6 +38,16 @@ pub fn create(builder: *Builder, source: build.FileSource, obj_format: std.Targe return self; } +/// Runs and (optionally) compares the output of a binary. +/// Asserts `self` was generated from an executable step. +pub fn runAndCompare(self: *CheckObjectStep) *RunCompareStep { + const dependencies_len = self.step.dependencies.items.len; + assert(dependencies_len > 0); + const exe_step = self.step.dependencies.items[dependencies_len - 1]; + const exe = exe_step.cast(std.build.LibExeObjStep).?; + return RunCompareStep.create(self.builder, "RunCompare", exe); +} + /// There two types of actions currently suported: /// * `.match` - is the main building block of standard matchers with optional eat-all token `{*}` /// and extractors by name such as `{n_value}`. Please note this action is very simplistic in nature |
