diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index 072bcd0309cf4decce854badf096994606a1e550..0314bc23ef96091c368cdcb20649c5567aedd92c 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -193,6 +193,9 @@ .debug_io_color = .{ .path = "debug_io_color", }, + .elf2 = .{ + .path = "elf2", + }, }, .paths = .{ "build.zig", diff --git a/test/standalone/elf2/build.zig b/test/standalone/elf2/build.zig new file mode 100644 index 0000000000000000000000000000000000000000..d25c04eb3a446a8cb5db8d07222105775e126da5 --- /dev/null +++ b/test/standalone/elf2/build.zig @@ -0,0 +1,51 @@ +pub fn build(b: *Build) void { + const test_step = b.step("test", "Test the new ELF linker"); + b.default_step = test_step; + + if (b.graph.host.result.cpu.arch == .x86_64 and b.graph.host.result.os.tag == .linux) { + addOne(b, test_step, b.graph.host, false, .static, "elf2-hello-native-selfhosted-static"); + addOne(b, test_step, b.graph.host, false, .dynamic, "elf2-hello-native-selfhosted-dynamic"); + addOne(b, test_step, b.graph.host, true, .static, "elf2-hello-native-llvm-static"); + addOne(b, test_step, b.graph.host, true, .dynamic, "elf2-hello-native-llvm-dynamic"); + } + + const x86_64_linux_target: Build.ResolvedTarget = b.resolveTargetQuery(.{ + .cpu_arch = .x86_64, + .os_tag = .linux, + }); + addOne(b, test_step, x86_64_linux_target, false, .static, "elf2-hello-selfhosted-static"); + addOne(b, test_step, x86_64_linux_target, true, .static, "elf2-hello-llvm-static"); +} + +fn addOne( + b: *Build, + test_step: *Build.Step, + target: Build.ResolvedTarget, + use_llvm: bool, + link_mode: std.lang.LinkMode, + name: []const u8, +) void { + const mod = b.createModule(.{ + .root_source_file = b.path("hello.zig"), + .target = target, + .optimize = .Debug, + .link_libc = link_mode == .dynamic, + }); + const exe = b.addExecutable(.{ + .name = name, + .root_module = mod, + .linkage = link_mode, + }); + exe.use_new_linker = true; + exe.use_llvm = use_llvm; + + const run = b.addRunArtifact(exe); + run.expectExitCode(0); + run.expectStdOutEqual("Hello, World!\n"); + run.skip_foreign_checks = true; + + test_step.dependOn(&run.step); +} + +const std = @import("std"); +const Build = std.Build; diff --git a/test/standalone/elf2/hello.zig b/test/standalone/elf2/hello.zig new file mode 100644 index 0000000000000000000000000000000000000000..8ac9329446e86ca6711af740bd8213be0b89bb21 --- /dev/null +++ b/test/standalone/elf2/hello.zig @@ -0,0 +1,6 @@ +pub fn main(init: std.process.Init) !void { + const stdout: std.Io.File = .stdout(); + try stdout.writeStreamingAll(init.io, "Hello, World!\n"); +} + +const std = @import("std");