Skip to content

Commit 2093dc5

Browse files
lib/init/build.zig: use standard linkage option
1 parent e6adb59 commit 2093dc5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/init/build.zig

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pub fn build(b: *std.Build) void {
1515
// set a preferred release mode, allowing the user to decide how to optimize.
1616
const optimize = b.standardOptimizeOption(.{});
1717

18+
// Standard linkage option allows the person running `zig build` to select
19+
// between static or dynamic.
20+
const linkage = b.standardLinkageOption(target.result);
21+
1822
// This creates a "module", which represents a collection of source files alongside
1923
// some compilation options, such as optimization mode and linked system libraries.
2024
// Every executable or library we compile will be based on one or more modules.
@@ -48,7 +52,7 @@ pub fn build(b: *std.Build) void {
4852
// This creates a `std.Build.Step.Compile`, which is the build step responsible
4953
// for actually invoking the compiler.
5054
const lib = b.addLibrary(.{
51-
.linkage = .static,
55+
.linkage = linkage,
5256
.name = ".NAME",
5357
.root_module = lib_mod,
5458
});
@@ -63,6 +67,7 @@ pub fn build(b: *std.Build) void {
6367
const exe = b.addExecutable(.{
6468
.name = ".NAME",
6569
.root_module = exe_mod,
70+
.linkage = linkage,
6671
});
6772

6873
// This declares intent for the executable to be installed into the
@@ -99,12 +104,16 @@ pub fn build(b: *std.Build) void {
99104
.root_module = lib_mod,
100105
});
101106

107+
lib_unit_tests.linkage = linkage;
108+
102109
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
103110

104111
const exe_unit_tests = b.addTest(.{
105112
.root_module = exe_mod,
106113
});
107114

115+
exe_unit_tests.linkage = linkage;
116+
108117
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
109118

110119
// Similar to creating the run step earlier, this exposes a `test` step to

0 commit comments

Comments
 (0)