authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-06-02 09:41:22+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-06-04 09:57:29+01:00
log82e8ed66ecaa3fc88267bfcb2850c50fe9a4b955
treee8a560adea0f664ab79162de5b1e4a0ab6ef18d4
parent4a2a9e9d24b71bd0bea80aaf88205039ae77c8df
signaturelock-open Commit is signed but in an unrecognized format.

Elf2: add basic standalone test coverage

This is just a temporary measure before we have better test coverage set up for this. I figure that in the name of incremental improvements, it makes sense to get at least a little bit of coverage in now to prevent basic use cases from regressing---because right now the old coverage of Elf2 in CI is the incremental tests, which only cover compiling for x86_64-linux without libc. In the future, this standalone test should be replaced with both of: * entries in the main test target matrix * linker tests (related: https://codeberg.org/ziglang/zig/pulls/32065)

3 files changed, 60 insertions(+), 0 deletions(-)

test/standalone/build.zig.zon+3
......@@ -193,6 +193,9 @@
193193 .debug_io_color = .{
194194 .path = "debug_io_color",
195195 },
196 .elf2 = .{
197 .path = "elf2",
198 },
196199 },
197200 .paths = .{
198201 "build.zig",
test/standalone/elf2/build.zig created+51
......@@ -0,0 +1,51 @@
1pub fn build(b: *Build) void {
2 const test_step = b.step("test", "Test the new ELF linker");
3 b.default_step = test_step;
4
5 if (b.graph.host.result.cpu.arch == .x86_64 and b.graph.host.result.os.tag == .linux) {
6 addOne(b, test_step, b.graph.host, false, .static, "elf2-hello-native-selfhosted-static");
7 addOne(b, test_step, b.graph.host, false, .dynamic, "elf2-hello-native-selfhosted-dynamic");
8 addOne(b, test_step, b.graph.host, true, .static, "elf2-hello-native-llvm-static");
9 addOne(b, test_step, b.graph.host, true, .dynamic, "elf2-hello-native-llvm-dynamic");
10 }
11
12 const x86_64_linux_target: Build.ResolvedTarget = b.resolveTargetQuery(.{
13 .cpu_arch = .x86_64,
14 .os_tag = .linux,
15 });
16 addOne(b, test_step, x86_64_linux_target, false, .static, "elf2-hello-selfhosted-static");
17 addOne(b, test_step, x86_64_linux_target, true, .static, "elf2-hello-llvm-static");
18}
19
20fn addOne(
21 b: *Build,
22 test_step: *Build.Step,
23 target: Build.ResolvedTarget,
24 use_llvm: bool,
25 link_mode: std.lang.LinkMode,
26 name: []const u8,
27) void {
28 const mod = b.createModule(.{
29 .root_source_file = b.path("hello.zig"),
30 .target = target,
31 .optimize = .Debug,
32 .link_libc = link_mode == .dynamic,
33 });
34 const exe = b.addExecutable(.{
35 .name = name,
36 .root_module = mod,
37 .linkage = link_mode,
38 });
39 exe.use_new_linker = true;
40 exe.use_llvm = use_llvm;
41
42 const run = b.addRunArtifact(exe);
43 run.expectExitCode(0);
44 run.expectStdOutEqual("Hello, World!\n");
45 run.skip_foreign_checks = true;
46
47 test_step.dependOn(&run.step);
48}
49
50const std = @import("std");
51const Build = std.Build;
test/standalone/elf2/hello.zig created+6
......@@ -0,0 +1,6 @@
1pub fn main(init: std.process.Init) !void {
2 const stdout: std.Io.File = .stdout();
3 try stdout.writeStreamingAll(init.io, "Hello, World!\n");
4}
5
6const std = @import("std");