diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-09-25 19:50:12 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-09-26 21:07:47 +0200 |
| commit | b01b972999f024a694734fa9861827e5dc15a88b (patch) | |
| tree | 89de11bf66d5d2b73d7392667595513e300ba00a | |
| parent | eb497c50e331550a2d28d45a77a7558a49a83e7c (diff) | |
| download | zig-b01b972999f024a694734fa9861827e5dc15a88b.tar.gz zig-b01b972999f024a694734fa9861827e5dc15a88b.zip | |
elf: test linking against empty C object
| -rw-r--r-- | test/link/elf.zig | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/test/link/elf.zig b/test/link/elf.zig index b20498e7df..5c910df1ab 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -12,24 +12,45 @@ pub fn build(b: *Build) void { .abi = .musl, }; - elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = true })); + // Exercise linker with self-hosted backend (no LLVM) elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false })); - elf_step.dependOn(testLinkingC(b, .{ .target = musl_target, .use_llvm = true })); - // elf_step.dependOn(testLinkingC(b, .{ .target = musl_target, .use_llvm = false })); // TODO arocc + + // Exercise linker with LLVM backend + elf_step.dependOn(testEmptyObject(b, .{ .target = musl_target })); + elf_step.dependOn(testLinkingC(b, .{ .target = musl_target })); + elf_step.dependOn(testLinkingZig(b, .{})); } -fn testLinkingZig(b: *Build, opts: Options) *Step { - const test_step = addTestStep(b, "linking-zig-static", opts); +fn testEmptyObject(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "empty-object", opts); const exe = addExecutable(b, opts); - addZigSourceBytes(exe, - \\pub fn main() void { - \\ @import("std").debug.print("Hello World!\n", .{}); + addCSourceBytes(exe, "int main() { return 0; }"); + addCSourceBytes(exe, ""); + exe.is_linking_libc = true; + + const run = b.addRunArtifact(exe); + run.expectExitCode(0); + test_step.dependOn(&run.step); + + return test_step; +} + +fn testLinkingC(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "linking-c-static", opts); + + const exe = addExecutable(b, opts); + addCSourceBytes(exe, + \\#include <stdio.h> + \\int main() { + \\ printf("Hello World!\n"); + \\ return 0; \\} ); + exe.is_linking_libc = true; const run = b.addRunArtifact(exe); - run.expectStdErrEqual("Hello World!\n"); + run.expectStdOutEqual("Hello World!\n"); test_step.dependOn(&run.step); const check = exe.checkObject(); @@ -44,21 +65,18 @@ fn testLinkingZig(b: *Build, opts: Options) *Step { return test_step; } -fn testLinkingC(b: *Build, opts: Options) *Step { - const test_step = addTestStep(b, "linking-c-static", opts); +fn testLinkingZig(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "linking-zig-static", opts); const exe = addExecutable(b, opts); - addCSourceBytes(exe, - \\#include <stdio.h> - \\int main() { - \\ printf("Hello World!\n"); - \\ return 0; + addZigSourceBytes(exe, + \\pub fn main() void { + \\ @import("std").debug.print("Hello World!\n", .{}); \\} ); - exe.is_linking_libc = true; const run = b.addRunArtifact(exe); - run.expectStdOutEqual("Hello World!\n"); + run.expectStdErrEqual("Hello World!\n"); test_step.dependOn(&run.step); const check = exe.checkObject(); |
