| ... | ... | @@ -18,6 +18,7 @@ pub fn build(b: *Build) void { |
| 18 | 18 | // Exercise linker with LLVM backend |
| 19 | 19 | elf_step.dependOn(testEmptyObject(b, .{ .target = musl_target })); |
| 20 | 20 | elf_step.dependOn(testLinkingC(b, .{ .target = musl_target })); |
| 21 | elf_step.dependOn(testLinkingCpp(b, .{ .target = musl_target })); |
| 21 | 22 | elf_step.dependOn(testLinkingZig(b, .{ .target = musl_target })); |
| 22 | 23 | elf_step.dependOn(testTlsStatic(b, .{ .target = musl_target })); |
| 23 | 24 | } |
| ... | ... | @@ -38,7 +39,7 @@ fn testEmptyObject(b: *Build, opts: Options) *Step { |
| 38 | 39 | } |
| 39 | 40 | |
| 40 | 41 | fn 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); |
| 42 | 43 | |
| 43 | 44 | const exe = addExecutable(b, opts); |
| 44 | 45 | addCSourceBytes(exe, |
| ... | ... | @@ -66,6 +67,36 @@ fn testLinkingC(b: *Build, opts: Options) *Step { |
| 66 | 67 | return test_step; |
| 67 | 68 | } |
| 68 | 69 | |
| 70 | fn 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 | |
| 69 | 100 | fn testLinkingZig(b: *Build, opts: Options) *Step { |
| 70 | 101 | const test_step = addTestStep(b, "linking-zig-static", opts); |
| 71 | 102 | |
| ... | ... | @@ -171,6 +202,12 @@ fn addCSourceBytes(comp: *Compile, comptime bytes: []const u8) void { |
| 171 | 202 | comp.addCSourceFile(.{ .file = file, .flags = &.{} }); |
| 172 | 203 | } |
| 173 | 204 | |
| 205 | fn 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 | |
| 174 | 211 | fn addAsmSourceBytes(comp: *Compile, comptime bytes: []const u8) void { |
| 175 | 212 | const b = comp.step.owner; |
| 176 | 213 | const file = WriteFile.create(b).add("a.s", bytes ++ "\n"); |