| ... | @@ -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 | }; |
| 14 | | 14 | |
| 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 arocc | 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 { | 24 | fn 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); |
| 23 | | 26 | |
| 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 | |
| | 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 | 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); |
| 34 | | 55 | |
| 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 | } |
| 46 | | 67 | |
| 47 | fn testLinkingC(b: *Build, opts: Options) *Step { | 68 | fn 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); |
| 49 | | 70 | |
| 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; | | |
| 59 | | 77 | |
| 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); |
| 63 | | 81 | |
| 64 | const check = exe.checkObject(); | 82 | const check = exe.checkObject(); |