| author | |
| committer | |
| log | e3b275fa47e44d0a77e513d03a3b37b0f9ea0c0d |
| tree | ab1a176abc3455865d62fa7c2e4683a53c2fb31e |
| parent | d0d615d8197eeb196ac500009637296bd00c6583 |
| signature |
closes #20276 files changed, 34 insertions(+), 1 deletions(-)
std/build.zig+1-1| ... | ... | @@ -1326,7 +1326,7 @@ pub const LibExeObjStep = struct { |
| 1326 | 1326 | zig_args.append("--ver-patch") catch unreachable; |
| 1327 | 1327 | zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable; |
| 1328 | 1328 | } |
| 1329 | if ((self.kind == Kind.Exe or self.kind == Kind.Test) and self.static) { | |
| 1329 | if (self.static) { | |
| 1330 | 1330 | zig_args.append("--static") catch unreachable; |
| 1331 | 1331 | } |
| 1332 | 1332 |
test/build_examples.zig+1| ... | ... | @@ -10,6 +10,7 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void { |
| 10 | 10 | cases.addBuildFile("test/standalone/main_pkg_path/build.zig"); |
| 11 | 11 | cases.addBuildFile("example/shared_library/build.zig"); |
| 12 | 12 | cases.addBuildFile("example/mix_o_files/build.zig"); |
| 13 | cases.addBuildFile("test/standalone/static_c_lib/build.zig"); | |
| 13 | 14 | if (builtin.os != builtin.Os.macosx) { |
| 14 | 15 | // TODO https://github.com/ziglang/zig/issues/1126 |
| 15 | 16 | cases.addBuildFile("test/standalone/issue_339/build.zig"); |
test/standalone/static_c_lib/build.zig created+18| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | const Builder = @import("std").build.Builder; | |
| 2 | ||
| 3 | pub fn build(b: *Builder) void { | |
| 4 | const mode = b.standardReleaseOptions(); | |
| 5 | ||
| 6 | const foo = b.addStaticLibrary("foo", null); | |
| 7 | foo.addCSourceFile("foo.c", [][]const u8{}); | |
| 8 | foo.setBuildMode(mode); | |
| 9 | foo.addIncludeDir("."); | |
| 10 | ||
| 11 | const test_exe = b.addTest("foo.zig"); | |
| 12 | test_exe.setBuildMode(mode); | |
| 13 | test_exe.linkLibrary(foo); | |
| 14 | test_exe.addIncludeDir("."); | |
| 15 | ||
| 16 | const test_step = b.step("test", "Test it"); | |
| 17 | test_step.dependOn(&test_exe.step); | |
| 18 | } |
test/standalone/static_c_lib/foo.c created+4| ... | ... | @@ -0,0 +1,4 @@ |
| 1 | #include "foo.h" | |
| 2 | uint32_t add(uint32_t a, uint32_t b) { | |
| 3 | return a + b; | |
| 4 | } |
test/standalone/static_c_lib/foo.h created+2| ... | ... | @@ -0,0 +1,2 @@ |
| 1 | #include <stdint.h> | |
| 2 | uint32_t add(uint32_t a, uint32_t b); |
test/standalone/static_c_lib/foo.zig created+8| ... | ... | @@ -0,0 +1,8 @@ |
| 1 | const std = @import("std"); | |
| 2 | const expect = std.testing.expect; | |
| 3 | const c = @cImport(@cInclude("foo.h")); | |
| 4 | ||
| 5 | test "C add" { | |
| 6 | const result = c.add(1, 2); | |
| 7 | expect(result == 3); | |
| 8 | } |