authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-25 19:50:12+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-26 21:07:47+02:00
logb01b972999f024a694734fa9861827e5dc15a88b
tree89de11bf66d5d2b73d7392667595513e300ba00a
parenteb497c50e331550a2d28d45a77a7558a49a83e7c

elf: test linking against empty C object


1 files changed, 36 insertions(+), 18 deletions(-)

test/link/elf.zig+36-18
...@@ -12,24 +12,45 @@ pub fn build(b: *Build) void {...@@ -12,24 +12,45 @@ pub fn build(b: *Build) void {
12 .abi = .musl,12 .abi = .musl,
13 };13 };
1414
15 elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = true }));15 // Exercise linker with self-hosted backend (no LLVM)
16 elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false }));16 elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false }));
17 elf_step.dependOn(testLinkingC(b, .{ .target = musl_target, .use_llvm = true }));17
18 // elf_step.dependOn(testLinkingC(b, .{ .target = musl_target, .use_llvm = false })); // TODO arocc18 // Exercise linker with LLVM backend
19 elf_step.dependOn(testEmptyObject(b, .{ .target = musl_target }));
20 elf_step.dependOn(testLinkingC(b, .{ .target = musl_target }));
21 elf_step.dependOn(testLinkingZig(b, .{}));
19}22}
2023
21fn testLinkingZig(b: *Build, opts: Options) *Step {24fn testEmptyObject(b: *Build, opts: Options) *Step {
22 const test_step = addTestStep(b, "linking-zig-static", opts);25 const test_step = addTestStep(b, "empty-object", opts);
2326
24 const exe = addExecutable(b, opts);27 const exe = addExecutable(b, opts);
25 addZigSourceBytes(exe,28 addCSourceBytes(exe, "int main() { return 0; }");
26 \\pub fn main() void {29 addCSourceBytes(exe, "");
27 \\ @import("std").debug.print("Hello World!\n", .{});30 exe.is_linking_libc = true;
31
32 const run = b.addRunArtifact(exe);
33 run.expectExitCode(0);
34 test_step.dependOn(&run.step);
35
36 return test_step;
37}
38
39fn testLinkingC(b: *Build, opts: Options) *Step {
40 const test_step = addTestStep(b, "linking-c-static", opts);
41
42 const exe = addExecutable(b, opts);
43 addCSourceBytes(exe,
44 \\#include <stdio.h>
45 \\int main() {
46 \\ printf("Hello World!\n");
47 \\ return 0;
28 \\}48 \\}
29 );49 );
50 exe.is_linking_libc = true;
3051
31 const run = b.addRunArtifact(exe);52 const run = b.addRunArtifact(exe);
32 run.expectStdErrEqual("Hello World!\n");53 run.expectStdOutEqual("Hello World!\n");
33 test_step.dependOn(&run.step);54 test_step.dependOn(&run.step);
3455
35 const check = exe.checkObject();56 const check = exe.checkObject();
...@@ -44,21 +65,18 @@ fn testLinkingZig(b: *Build, opts: Options) *Step {...@@ -44,21 +65,18 @@ fn testLinkingZig(b: *Build, opts: Options) *Step {
44 return test_step;65 return test_step;
45}66}
4667
47fn testLinkingC(b: *Build, opts: Options) *Step {68fn testLinkingZig(b: *Build, opts: Options) *Step {
48 const test_step = addTestStep(b, "linking-c-static", opts);69 const test_step = addTestStep(b, "linking-zig-static", opts);
4970
50 const exe = addExecutable(b, opts);71 const exe = addExecutable(b, opts);
51 addCSourceBytes(exe,72 addZigSourceBytes(exe,
52 \\#include <stdio.h>73 \\pub fn main() void {
53 \\int main() {74 \\ @import("std").debug.print("Hello World!\n", .{});
54 \\ printf("Hello World!\n");
55 \\ return 0;
56 \\}75 \\}
57 );76 );
58 exe.is_linking_libc = true;
5977
60 const run = b.addRunArtifact(exe);78 const run = b.addRunArtifact(exe);
61 run.expectStdOutEqual("Hello World!\n");79 run.expectStdErrEqual("Hello World!\n");
62 test_step.dependOn(&run.step);80 test_step.dependOn(&run.step);
6381
64 const check = exe.checkObject();82 const check = exe.checkObject();