zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit e3b275fa47e44d0a77e513d03a3b37b0f9ea0c0d (tree)
parent d0d615d8197eeb196ac500009637296bd00c6583
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun,  3 Mar 2019 12:35:09 -0500

fix build.zig not respecting --static

closes #2027

Diffstat:
Mstd/build.zig | 2+-
Mtest/build_examples.zig | 1+
Atest/standalone/static_c_lib/build.zig | 18++++++++++++++++++
Atest/standalone/static_c_lib/foo.c | 4++++
Atest/standalone/static_c_lib/foo.h | 2++
Atest/standalone/static_c_lib/foo.zig | 8++++++++
6 files changed, 34 insertions(+), 1 deletion(-)

diff --git 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 @@ -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 @@ -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 @@ -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 @@ -0,0 +1,2 @@ +#include <stdint.h> +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 @@ -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); +}