| ... | ... | @@ -12,24 +12,45 @@ pub fn build(b: *Build) void { |
| 12 | 12 | .abi = .musl, |
| 13 | 13 | }; |
| 14 | 14 | |
| 15 | | elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = true })); |
| 15 | // Exercise linker with self-hosted backend (no LLVM) |
| 16 | 16 | 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, .{})); |
| 19 | 22 | } |
| 20 | 23 | |
| 21 | | fn testLinkingZig(b: *Build, opts: Options) *Step { |
| 22 | | const test_step = addTestStep(b, "linking-zig-static", opts); |
| 24 | fn testEmptyObject(b: *Build, opts: Options) *Step { |
| 25 | const test_step = addTestStep(b, "empty-object", opts); |
| 23 | 26 | |
| 24 | 27 | 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 | |
| 39 | fn 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; |
| 30 | 51 | |
| 31 | 52 | const run = b.addRunArtifact(exe); |
| 32 | | run.expectStdErrEqual("Hello World!\n"); |
| 53 | run.expectStdOutEqual("Hello World!\n"); |
| 33 | 54 | test_step.dependOn(&run.step); |
| 34 | 55 | |
| 35 | 56 | const check = exe.checkObject(); |
| ... | ... | @@ -44,21 +65,18 @@ fn testLinkingZig(b: *Build, opts: Options) *Step { |
| 44 | 65 | return test_step; |
| 45 | 66 | } |
| 46 | 67 | |
| 47 | | fn testLinkingC(b: *Build, opts: Options) *Step { |
| 48 | | const test_step = addTestStep(b, "linking-c-static", opts); |
| 68 | fn testLinkingZig(b: *Build, opts: Options) *Step { |
| 69 | const test_step = addTestStep(b, "linking-zig-static", opts); |
| 49 | 70 | |
| 50 | 71 | 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", .{}); |
| 56 | 75 | \\} |
| 57 | 76 | ); |
| 58 | | exe.is_linking_libc = true; |
| 59 | 77 | |
| 60 | 78 | const run = b.addRunArtifact(exe); |
| 61 | | run.expectStdOutEqual("Hello World!\n"); |
| 79 | run.expectStdErrEqual("Hello World!\n"); |
| 62 | 80 | test_step.dependOn(&run.step); |
| 63 | 81 | |
| 64 | 82 | const check = exe.checkObject(); |