@@ -15,6 +15,10 @@ pub fn build(b: *std.Build) void {
15
15
// set a preferred release mode, allowing the user to decide how to optimize.
16
16
const optimize = b .standardOptimizeOption (.{});
17
17
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
+
18
22
// This creates a "module", which represents a collection of source files alongside
19
23
// some compilation options, such as optimization mode and linked system libraries.
20
24
// 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 {
48
52
// This creates a `std.Build.Step.Compile`, which is the build step responsible
49
53
// for actually invoking the compiler.
50
54
const lib = b .addLibrary (.{
51
- .linkage = .static ,
55
+ .linkage = linkage ,
52
56
.name = ".NAME" ,
53
57
.root_module = lib_mod ,
54
58
});
@@ -63,6 +67,7 @@ pub fn build(b: *std.Build) void {
63
67
const exe = b .addExecutable (.{
64
68
.name = ".NAME" ,
65
69
.root_module = exe_mod ,
70
+ .linkage = linkage ,
66
71
});
67
72
68
73
// This declares intent for the executable to be installed into the
@@ -99,12 +104,16 @@ pub fn build(b: *std.Build) void {
99
104
.root_module = lib_mod ,
100
105
});
101
106
107
+ lib_unit_tests .linkage = linkage ;
108
+
102
109
const run_lib_unit_tests = b .addRunArtifact (lib_unit_tests );
103
110
104
111
const exe_unit_tests = b .addTest (.{
105
112
.root_module = exe_mod ,
106
113
});
107
114
115
+ exe_unit_tests .linkage = linkage ;
116
+
108
117
const run_exe_unit_tests = b .addRunArtifact (exe_unit_tests );
109
118
110
119
// Similar to creating the run step earlier, this exposes a `test` step to
0 commit comments