From 5d8f8b571e245a9a4d72922d3939d2b1def0fb51 Mon Sep 17 00:00:00 2001 From: kcbanner Date: Fri, 5 Jun 2026 01:55:36 -0400 Subject: [PATCH] tests: update standalone/static_c_lib to test permutations of use_libc and use_llvm --- test/standalone/static_c_lib/build.zig | 87 ++++++++++++++++++++------ 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/test/standalone/static_c_lib/build.zig b/test/standalone/static_c_lib/build.zig index 4bed5cdefa5f496c702b60a051646d9e8979b177..a1e5c034fe10e4ebdd918264185e410964db9e73 100644 --- a/test/standalone/static_c_lib/build.zig +++ b/test/standalone/static_c_lib/build.zig @@ -5,26 +5,75 @@ pub fn build(b: *std.Build) void { b.default_step = test_step; const optimize: std.builtin.OptimizeMode = .Debug; + const target = b.standardTargetOptions(.{}); - const foo = b.addLibrary(.{ - .linkage = .static, - .name = "foo", - .root_module = b.createModule(.{ - .root_source_file = null, - .optimize = optimize, - .target = b.graph.host, - }), - }); - foo.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} }); - foo.root_module.addIncludePath(b.path(".")); + const exe_names: []const []const u8 = &.{ + "test", + "test-dync", + "test-no-llvm", + "test-no-llvm-dync", + "test-exe-no-llvm", + "test-dync-exe-no-llvm", + "test-no-llvm-exe-no-llvm", + "test-no-llvm-dync-exe-no-llvm", + }; + const lib_names: []const []const u8 = &.{ + "foo", + "foo-dync", + "foo-no-llvm", + "foo-no-llvm-dync", + "foo-exe-no-llvm", + "foo-dync-exe-no-llvm", + "foo-no-llvm-exe-no-llvm", + "foo-no-llvm-dync-exe-no-llvm", + }; + const lib_link_libc: []const bool = &.{ false, true, false, true, false, true, false, true }; + const lib_use_llvm: []const bool = &.{ true, true, false, false, true, true, false, false }; + const exe_use_llvm: []const bool = &.{ true, true, true, true, false, false, false, false }; - const test_exe = b.addTest(.{ .root_module = b.createModule(.{ - .root_source_file = b.path("foo.zig"), - .target = b.graph.host, - .optimize = optimize, - }) }); - test_exe.root_module.linkLibrary(foo); - test_exe.root_module.addIncludePath(b.path(".")); + for ( + exe_names, + lib_names, + lib_link_libc, + lib_use_llvm, + exe_use_llvm, + ) |exe_name, lib_name, dyn_libc, lib_llvm, exe_llvm| { + const use_llvm = lib_llvm or exe_llvm; + if (!use_llvm and target.result.os.tag == .macos) continue; // TODO + if (!use_llvm and target.result.os.tag == .freebsd) continue; // TODO + if (!use_llvm and target.result.os.tag == .netbsd) continue; // TODO + if (!use_llvm and target.result.os.tag == .openbsd) continue; // TODO + if (!use_llvm and target.result.cpu.arch == .loongarch64) continue; // TODO + if (!use_llvm and target.result.cpu.arch == .powerpc64le) continue; // TODO + if (!use_llvm and target.result.cpu.arch == .s390x) continue; // TODO - test_step.dependOn(&b.addRunArtifact(test_exe).step); + const foo = b.addLibrary(.{ + .linkage = .static, + .name = lib_name, + .root_module = b.createModule(.{ + .root_source_file = null, + .optimize = optimize, + .target = target, + .link_libc = dyn_libc, + }), + .use_llvm = lib_llvm, + }); + foo.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} }); + foo.root_module.addIncludePath(b.path(".")); + + const test_exe = b.addTest(.{ + .name = exe_name, + .root_module = b.createModule(.{ + .root_source_file = b.path("foo.zig"), + .target = target, + .optimize = optimize, + .link_libc = dyn_libc, + }), + .use_llvm = exe_llvm, + }); + test_exe.root_module.linkLibrary(foo); + test_exe.root_module.addIncludePath(b.path(".")); + + test_step.dependOn(&b.addRunArtifact(test_exe).step); + } } -- 2.54.0