authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-04 12:38:18+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 19:33:04+02:00
log976d4f51ccae088044ac90a89c3840db94f4ceb2
tree4253fb1ecdbb7ce573c2cad5054b02930575a1e0
parent621ddc003ae9cde64d11e259f98f8e079634b94d

elf: add hello-world c++ link test


1 files changed, 38 insertions(+), 1 deletions(-)

test/link/elf.zig+38-1
......@@ -18,6 +18,7 @@ pub fn build(b: *Build) void {
1818 // Exercise linker with LLVM backend
1919 elf_step.dependOn(testEmptyObject(b, .{ .target = musl_target }));
2020 elf_step.dependOn(testLinkingC(b, .{ .target = musl_target }));
21 elf_step.dependOn(testLinkingCpp(b, .{ .target = musl_target }));
2122 elf_step.dependOn(testLinkingZig(b, .{ .target = musl_target }));
2223 elf_step.dependOn(testTlsStatic(b, .{ .target = musl_target }));
2324}
......@@ -38,7 +39,7 @@ fn testEmptyObject(b: *Build, opts: Options) *Step {
3839}
3940
4041fn testLinkingC(b: *Build, opts: Options) *Step {
41 const test_step = addTestStep(b, "linking-c-static", opts);
42 const test_step = addTestStep(b, "linking-c", opts);
4243
4344 const exe = addExecutable(b, opts);
4445 addCSourceBytes(exe,
......@@ -66,6 +67,36 @@ fn testLinkingC(b: *Build, opts: Options) *Step {
6667 return test_step;
6768}
6869
70fn testLinkingCpp(b: *Build, opts: Options) *Step {
71 const test_step = addTestStep(b, "linking-cpp", opts);
72
73 const exe = addExecutable(b, opts);
74 addCppSourceBytes(exe,
75 \\#include <iostream>
76 \\int main() {
77 \\ std::cout << "Hello World!" << std::endl;
78 \\ return 0;
79 \\}
80 );
81 exe.is_linking_libc = true;
82 exe.is_linking_libcpp = true;
83
84 const run = addRunArtifact(exe);
85 run.expectStdOutEqual("Hello World!\n");
86 test_step.dependOn(&run.step);
87
88 const check = exe.checkObject();
89 check.checkStart();
90 check.checkExact("header");
91 check.checkExact("type EXEC");
92 check.checkStart();
93 check.checkExact("section headers");
94 check.checkNotPresent("name .dynamic");
95 test_step.dependOn(&check.step);
96
97 return test_step;
98}
99
69100fn testLinkingZig(b: *Build, opts: Options) *Step {
70101 const test_step = addTestStep(b, "linking-zig-static", opts);
71102
......@@ -171,6 +202,12 @@ fn addCSourceBytes(comp: *Compile, comptime bytes: []const u8) void {
171202 comp.addCSourceFile(.{ .file = file, .flags = &.{} });
172203}
173204
205fn addCppSourceBytes(comp: *Compile, comptime bytes: []const u8) void {
206 const b = comp.step.owner;
207 const file = WriteFile.create(b).add("a.cpp", bytes);
208 comp.addCSourceFile(.{ .file = file, .flags = &.{} });
209}
210
174211fn addAsmSourceBytes(comp: *Compile, comptime bytes: []const u8) void {
175212 const b = comp.step.owner;
176213 const file = WriteFile.create(b).add("a.s", bytes ++ "\n");