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 {
1212 .abi = .musl,
1313 };
1414
15 elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = true }));
15 // Exercise linker with self-hosted backend (no LLVM)
1616 elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false }));
17 elf_step.dependOn(testLinkingC(b, .{ .target = musl_target, .use_llvm = true }));
18 // elf_step.dependOn(testLinkingC(b, .{ .target = musl_target, .use_llvm = false })); // TODO arocc
17
18 // 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, .{}));
1922}
2023
21fn testLinkingZig(b: *Build, opts: Options) *Step {
22 const test_step = addTestStep(b, "linking-zig-static", opts);
24fn testEmptyObject(b: *Build, opts: Options) *Step {
25 const test_step = addTestStep(b, "empty-object", opts);
2326
2427 const exe = addExecutable(b, opts);
25 addZigSourceBytes(exe,
26 \\pub fn main() void {
27 \\ @import("std").debug.print("Hello World!\n", .{});
28 addCSourceBytes(exe, "int main() { return 0; }");
29 addCSourceBytes(exe, "");
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;
2848 \\}
2949 );
50 exe.is_linking_libc = true;
3051
3152 const run = b.addRunArtifact(exe);
32 run.expectStdErrEqual("Hello World!\n");
53 run.expectStdOutEqual("Hello World!\n");
3354 test_step.dependOn(&run.step);
3455
3556 const check = exe.checkObject();
......@@ -44,21 +65,18 @@ fn testLinkingZig(b: *Build, opts: Options) *Step {
4465 return test_step;
4566}
4667
47fn testLinkingC(b: *Build, opts: Options) *Step {
48 const test_step = addTestStep(b, "linking-c-static", opts);
68fn testLinkingZig(b: *Build, opts: Options) *Step {
69 const test_step = addTestStep(b, "linking-zig-static", opts);
4970
5071 const exe = addExecutable(b, opts);
51 addCSourceBytes(exe,
52 \\#include <stdio.h>
53 \\int main() {
54 \\ printf("Hello World!\n");
55 \\ return 0;
72 addZigSourceBytes(exe,
73 \\pub fn main() void {
74 \\ @import("std").debug.print("Hello World!\n", .{});
5675 \\}
5776 );
58 exe.is_linking_libc = true;
5977
6078 const run = b.addRunArtifact(exe);
61 run.expectStdOutEqual("Hello World!\n");
79 run.expectStdErrEqual("Hello World!\n");
6280 test_step.dependOn(&run.step);
6381
6482 const check = exe.checkObject();