authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-03 12:35:09-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-03 12:35:09-05:00
loge3b275fa47e44d0a77e513d03a3b37b0f9ea0c0d
treeab1a176abc3455865d62fa7c2e4683a53c2fb31e
parentd0d615d8197eeb196ac500009637296bd00c6583
signaturelock-open Commit is signed but in an unrecognized format.

fix build.zig not respecting --static

closes #2027

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

std/build.zig+1-1
......@@ -1326,7 +1326,7 @@ pub const LibExeObjStep = struct {
13261326 zig_args.append("--ver-patch") catch unreachable;
13271327 zig_args.append(builder.fmt("{}", self.version.patch)) catch unreachable;
13281328 }
1329 if ((self.kind == Kind.Exe or self.kind == Kind.Test) and self.static) {
1329 if (self.static) {
13301330 zig_args.append("--static") catch unreachable;
13311331 }
13321332
test/build_examples.zig+1
......@@ -10,6 +10,7 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void {
1010 cases.addBuildFile("test/standalone/main_pkg_path/build.zig");
1111 cases.addBuildFile("example/shared_library/build.zig");
1212 cases.addBuildFile("example/mix_o_files/build.zig");
13 cases.addBuildFile("test/standalone/static_c_lib/build.zig");
1314 if (builtin.os != builtin.Os.macosx) {
1415 // TODO https://github.com/ziglang/zig/issues/1126
1516 cases.addBuildFile("test/standalone/issue_339/build.zig");
test/standalone/static_c_lib/build.zig created+18
......@@ -0,0 +1,18 @@
1const Builder = @import("std").build.Builder;
2
3pub 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"
2uint32_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>
2uint32_t add(uint32_t a, uint32_t b);
test/standalone/static_c_lib/foo.zig created+8
......@@ -0,0 +1,8 @@
1const std = @import("std");
2const expect = std.testing.expect;
3const c = @cImport(@cInclude("foo.h"));
4
5test "C add" {
6 const result = c.add(1, 2);
7 expect(result == 3);
8}