| ... | ... | @@ -11,12 +11,14 @@ pub fn build(b: *Build) void { |
| 11 | 11 | .os_tag = .linux, |
| 12 | 12 | }; |
| 13 | 13 | |
| 14 | | elf_step.dependOn(testHelloStatic(b, .{ .target = target, .use_llvm = true })); |
| 15 | | elf_step.dependOn(testHelloStatic(b, .{ .target = target, .use_llvm = false })); |
| 14 | elf_step.dependOn(testLinkingZigStatic(b, .{ .target = target, .use_llvm = true })); |
| 15 | elf_step.dependOn(testLinkingZigStatic(b, .{ .target = target, .use_llvm = false })); |
| 16 | elf_step.dependOn(testLinkingCStatic(b, .{ .target = target, .use_llvm = true })); |
| 17 | // elf_step.dependOn(testLinkingCStatic(b, .{ .target = target, .use_llvm = false })); // TODO arocc |
| 16 | 18 | } |
| 17 | 19 | |
| 18 | | fn testHelloStatic(b: *Build, opts: Options) *Step { |
| 19 | | const test_step = addTestStep(b, "hello-static", opts); |
| 20 | fn testLinkingZigStatic(b: *Build, opts: Options) *Step { |
| 21 | const test_step = addTestStep(b, "linking-zig-static", opts); |
| 20 | 22 | |
| 21 | 23 | const exe = addExecutable(b, opts); |
| 22 | 24 | addZigSourceBytes(exe, |
| ... | ... | @@ -42,6 +44,36 @@ fn testHelloStatic(b: *Build, opts: Options) *Step { |
| 42 | 44 | return test_step; |
| 43 | 45 | } |
| 44 | 46 | |
| 47 | fn testLinkingCStatic(b: *Build, opts: Options) *Step { |
| 48 | const test_step = addTestStep(b, "linking-c-static", opts); |
| 49 | |
| 50 | const exe = addExecutable(b, opts); |
| 51 | addCSourceBytes(exe, |
| 52 | \\#include <stdio.h> |
| 53 | \\int main() { |
| 54 | \\ printf("Hello World!\n"); |
| 55 | \\ return 0; |
| 56 | \\} |
| 57 | ); |
| 58 | exe.is_linking_libc = true; |
| 59 | exe.linkage = .static; |
| 60 | |
| 61 | const run = b.addRunArtifact(exe); |
| 62 | run.expectStdOutEqual("Hello World!\n"); |
| 63 | test_step.dependOn(&run.step); |
| 64 | |
| 65 | const check = exe.checkObject(); |
| 66 | check.checkStart(); |
| 67 | check.checkExact("header"); |
| 68 | check.checkExact("type EXEC"); |
| 69 | check.checkStart(); |
| 70 | check.checkExact("section headers"); |
| 71 | check.checkNotPresent("name .dynamic"); |
| 72 | test_step.dependOn(&check.step); |
| 73 | |
| 74 | return test_step; |
| 75 | } |
| 76 | |
| 45 | 77 | const Options = struct { |
| 46 | 78 | target: CrossTarget = .{ .os_tag = .linux }, |
| 47 | 79 | optimize: std.builtin.OptimizeMode = .Debug, |
| ... | ... | @@ -78,6 +110,12 @@ fn addZigSourceBytes(comp: *Compile, bytes: []const u8) void { |
| 78 | 110 | comp.root_src = file; |
| 79 | 111 | } |
| 80 | 112 | |
| 113 | fn addCSourceBytes(comp: *Compile, bytes: []const u8) void { |
| 114 | const b = comp.step.owner; |
| 115 | const file = WriteFile.create(b).add("a.c", bytes); |
| 116 | comp.addCSourceFile(.{ .file = file, .flags = &.{} }); |
| 117 | } |
| 118 | |
| 81 | 119 | const std = @import("std"); |
| 82 | 120 | |
| 83 | 121 | const Build = std.Build; |