authorgravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-02-11 15:44:42+01:00
committergravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-02-11 15:48:18+01:00
loga6f64096a1487fa6787907d7f130dadff5decb5b
treef7601069e9daf8824e96ce9873aae3be21807a49
parent87fa61bdd12f0b2625013ca6eabb5fe5479a18f4
signaturebadge-check Signed by SSH key SHA256:p3IHbr0lyK2ekfDC1Zi7dOEV/9T6lGghNawhl5sBnM4

chore(test/standalone): test linking libc in a shared library


1 files changed, 34 insertions(+), 26 deletions(-)

test/standalone/shared_library/build.zig+34-26
...@@ -6,32 +6,40 @@ pub fn build(b: *std.Build) void {...@@ -6,32 +6,40 @@ pub fn build(b: *std.Build) void {
66
7 const optimize: std.builtin.OptimizeMode = .Debug;7 const optimize: std.builtin.OptimizeMode = .Debug;
8 const target = b.graph.host;8 const target = b.graph.host;
9 const lib = b.addLibrary(.{
10 .linkage = .dynamic,
11 .name = "mathtest",
12 .version = .{ .major = 1, .minor = 0, .patch = 0 },
13 .root_module = b.createModule(.{
14 .root_source_file = b.path("mathtest.zig"),
15 .target = target,
16 .optimize = optimize,
17 }),
18 });
199
20 const exe = b.addExecutable(.{10 const exe_names: []const []const u8 = &.{ "test", "test-dync" };
21 .name = "test",11 const lib_names: []const []const u8 = &.{ "mathtest", "mathtest-dync" };
22 .root_module = b.createModule(.{12 const lib_link_libc: []const bool = &.{ false, true };
23 .root_source_file = null,
24 .target = target,
25 .optimize = optimize,
26 .link_libc = true,
27 }),
28 });
29 exe.root_module.addCSourceFile(.{
30 .file = b.path("test.c"),
31 .flags = &[_][]const u8{"-std=c99"},
32 });
33 exe.root_module.linkLibrary(lib);
3413
35 const run_cmd = b.addRunArtifact(exe);14 for (exe_names, lib_names, lib_link_libc) |exe_name, lib_name, dyn_libc| {
36 test_step.dependOn(&run_cmd.step);15 const lib = b.addLibrary(.{
16 .linkage = .dynamic,
17 .name = lib_name,
18 .version = .{ .major = 1, .minor = 0, .patch = 0 },
19 .root_module = b.createModule(.{
20 .root_source_file = b.path("mathtest.zig"),
21 .target = target,
22 .optimize = optimize,
23 .link_libc = dyn_libc,
24 }),
25 });
26
27 const exe = b.addExecutable(.{
28 .name = exe_name,
29 .root_module = b.createModule(.{
30 .root_source_file = null,
31 .target = target,
32 .optimize = optimize,
33 .link_libc = true,
34 }),
35 });
36 exe.root_module.addCSourceFile(.{
37 .file = b.path("test.c"),
38 .flags = &[_][]const u8{"-std=c99"},
39 });
40 exe.root_module.linkLibrary(lib);
41
42 const run_cmd = b.addRunArtifact(exe);
43 test_step.dependOn(&run_cmd.step);
44 }
37}45}