diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-09-25 17:05:16 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-09-26 21:07:47 +0200 |
| commit | 8abfb3559ab6e1be7852b61455fe1197bf1cbd69 (patch) | |
| tree | b6b1f01a232864cf9fa91c53a6d9b4ab6e9ef63d /test | |
| parent | aac04b4a5a70fc45f88d7b005e20c2cde271ff89 (diff) | |
| download | zig-8abfb3559ab6e1be7852b61455fe1197bf1cbd69.tar.gz zig-8abfb3559ab6e1be7852b61455fe1197bf1cbd69.zip | |
elf: test statically linking libc
Diffstat (limited to 'test')
| -rw-r--r-- | test/link/elf.zig | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/test/link/elf.zig b/test/link/elf.zig index 6f0fa962b6..e29a5af158 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -11,12 +11,14 @@ pub fn build(b: *Build) void { .os_tag = .linux, }; - elf_step.dependOn(testHelloStatic(b, .{ .target = target, .use_llvm = true })); - elf_step.dependOn(testHelloStatic(b, .{ .target = target, .use_llvm = false })); + elf_step.dependOn(testLinkingZigStatic(b, .{ .target = target, .use_llvm = true })); + elf_step.dependOn(testLinkingZigStatic(b, .{ .target = target, .use_llvm = false })); + elf_step.dependOn(testLinkingCStatic(b, .{ .target = target, .use_llvm = true })); + // elf_step.dependOn(testLinkingCStatic(b, .{ .target = target, .use_llvm = false })); // TODO arocc } -fn testHelloStatic(b: *Build, opts: Options) *Step { - const test_step = addTestStep(b, "hello-static", opts); +fn testLinkingZigStatic(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "linking-zig-static", opts); const exe = addExecutable(b, opts); addZigSourceBytes(exe, @@ -42,6 +44,36 @@ fn testHelloStatic(b: *Build, opts: Options) *Step { return test_step; } +fn testLinkingCStatic(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "linking-c-static", opts); + + const exe = addExecutable(b, opts); + addCSourceBytes(exe, + \\#include <stdio.h> + \\int main() { + \\ printf("Hello World!\n"); + \\ return 0; + \\} + ); + exe.is_linking_libc = true; + exe.linkage = .static; + + const run = b.addRunArtifact(exe); + run.expectStdOutEqual("Hello World!\n"); + test_step.dependOn(&run.step); + + const check = exe.checkObject(); + check.checkStart(); + check.checkExact("header"); + check.checkExact("type EXEC"); + check.checkStart(); + check.checkExact("section headers"); + check.checkNotPresent("name .dynamic"); + test_step.dependOn(&check.step); + + return test_step; +} + const Options = struct { target: CrossTarget = .{ .os_tag = .linux }, optimize: std.builtin.OptimizeMode = .Debug, @@ -78,6 +110,12 @@ fn addZigSourceBytes(comp: *Compile, bytes: []const u8) void { comp.root_src = file; } +fn addCSourceBytes(comp: *Compile, bytes: []const u8) void { + const b = comp.step.owner; + const file = WriteFile.create(b).add("a.c", bytes); + comp.addCSourceFile(.{ .file = file, .flags = &.{} }); +} + const std = @import("std"); const Build = std.Build; |
