@@ -3,12 +3,11 @@ const std = @import("std");
33
44
55pub fn build (b : * std.Build ) ! void {
6- var flags = std .ArrayList ([]const u8 ).init (b .allocator );
6+ var flags = std .array_list . Managed ([]const u8 ).init (b .allocator );
77 defer flags .deinit ();
88 try flags .append ("-std=c99" );
99
1010 const c_flags = flags .items ;
11-
1211 const target = b .standardTargetOptions (.{});
1312 const optimize = b .standardOptimizeOption (.{});
1413
@@ -25,12 +24,21 @@ pub fn build(b: *std.Build) !void {
2524 });
2625 const build_dir = cmake_step .addOutputDirectoryArg ("out" );
2726
28- b .getInstallStep ().dependOn (& cmake_step .step );
29- const lib = b .addStaticLibrary (.{
30- .name = "libversion-zig" ,
27+ const mod = b .createModule (.{
28+ .root_source_file = b .path ("src/lib.zig" ),
3129 .target = target ,
30+ .link_libc = true ,
3231 .optimize = optimize ,
3332 });
33+ mod .addIncludePath (libversion_dep .path ("." ));
34+ mod .addIncludePath (build_dir );
35+
36+ b .getInstallStep ().dependOn (& cmake_step .step );
37+ const lib = b .addLibrary (.{
38+ .name = "libversion-zig" ,
39+ .linkage = .static ,
40+ .root_module = mod ,
41+ });
3442 lib .addIncludePath (libversion_dep .path ("." ));
3543 // build_dir Outputed by cmake_step. This make sure cmake_step runs first
3644 lib .addIncludePath (build_dir );
@@ -47,26 +55,21 @@ pub fn build(b: *std.Build) !void {
4755 .flags = c_flags ,
4856 });
4957 lib .linkLibC ();
50-
51- const mod = b .addModule ("libversion" , .{
52- .root_source_file = b .path ("src/lib.zig" ),
53- .link_libc = true ,
54- });
55- mod .addIncludePath (libversion_dep .path ("." ));
56- mod .addIncludePath (build_dir );
57- mod .linkLibrary (lib );
58-
5958 b .installArtifact (lib );
6059
61- const test_step = b .step ("test" , "Run library tests" );
6260 const test_exe = b .addTest (.{
63- .root_source_file = b .path ("src/lib.zig" ), // Tests are often in the same lib.zig for small libs
64- .target = target ,
65- .optimize = optimize ,
61+ .name = "libversion-zig-test" ,
62+ .root_module = b .createModule (.{
63+ .root_source_file = b .path ("src/lib.zig" ),
64+ .target = target ,
65+ .optimize = optimize ,
66+ }),
6667 });
6768 test_exe .addIncludePath (libversion_dep .path ("." ));
6869 test_exe .addIncludePath (build_dir );
6970 test_exe .linkLibrary (lib );
7071 const run_tests = b .addRunArtifact (test_exe );
72+
73+ const test_step = b .step ("test" , "Run library tests" );
7174 test_step .dependOn (& run_tests .step );
7275}
0 commit comments