diff --git a/std/build.zig b/std/build.zig index f2e53cce104f536a00a60139980623c082c301f6..2316a87b31e41b04d80f011ca685673deb63f87f 100644 --- a/std/build.zig +++ b/std/build.zig @@ -1326,7 +1326,7 @@ pub const LibExeObjStep = struct { zig_args.append("--ver-patch") catch unreachable; zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable; } - if ((self.kind == Kind.Exe or self.kind == Kind.Test) and self.static) { + if (self.static) { zig_args.append("--static") catch unreachable; } diff --git a/test/build_examples.zig b/test/build_examples.zig index 3931648f190228d1881b76c83b89fb1733b69b01..c51fdfdf894dfecd1e5fdd7e4f6caaaff0baed65 100644 --- a/test/build_examples.zig +++ b/test/build_examples.zig @@ -10,6 +10,7 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void { cases.addBuildFile("test/standalone/main_pkg_path/build.zig"); cases.addBuildFile("example/shared_library/build.zig"); cases.addBuildFile("example/mix_o_files/build.zig"); + cases.addBuildFile("test/standalone/static_c_lib/build.zig"); if (builtin.os != builtin.Os.macosx) { // TODO https://github.com/ziglang/zig/issues/1126 cases.addBuildFile("test/standalone/issue_339/build.zig"); diff --git a/test/standalone/static_c_lib/build.zig b/test/standalone/static_c_lib/build.zig new file mode 100644 index 0000000000000000000000000000000000000000..afbb63c6bf722371f5add5761889ed6645230164 --- /dev/null +++ b/test/standalone/static_c_lib/build.zig @@ -0,0 +1,18 @@ +const Builder = @import("std").build.Builder; + +pub fn build(b: *Builder) void { + const mode = b.standardReleaseOptions(); + + const foo = b.addStaticLibrary("foo", null); + foo.addCSourceFile("foo.c", [][]const u8{}); + foo.setBuildMode(mode); + foo.addIncludeDir("."); + + const test_exe = b.addTest("foo.zig"); + test_exe.setBuildMode(mode); + test_exe.linkLibrary(foo); + test_exe.addIncludeDir("."); + + const test_step = b.step("test", "Test it"); + test_step.dependOn(&test_exe.step); +} diff --git a/test/standalone/static_c_lib/foo.c b/test/standalone/static_c_lib/foo.c new file mode 100644 index 0000000000000000000000000000000000000000..2366282d47e315c971de79608ec86645a19da170 --- /dev/null +++ b/test/standalone/static_c_lib/foo.c @@ -0,0 +1,4 @@ +#include "foo.h" +uint32_t add(uint32_t a, uint32_t b) { + return a + b; +} diff --git a/test/standalone/static_c_lib/foo.h b/test/standalone/static_c_lib/foo.h new file mode 100644 index 0000000000000000000000000000000000000000..e8ebb9842e6f165bffb4e78fd189be8dbea5feda --- /dev/null +++ b/test/standalone/static_c_lib/foo.h @@ -0,0 +1,2 @@ +#include +uint32_t add(uint32_t a, uint32_t b); diff --git a/test/standalone/static_c_lib/foo.zig b/test/standalone/static_c_lib/foo.zig new file mode 100644 index 0000000000000000000000000000000000000000..edf94539c82a102f57656f817929ca6d841ae969 --- /dev/null +++ b/test/standalone/static_c_lib/foo.zig @@ -0,0 +1,8 @@ +const std = @import("std"); +const expect = std.testing.expect; +const c = @cImport(@cInclude("foo.h")); + +test "C add" { + const result = c.add(1, 2); + expect(result == 3); +}