@@ -26,38 +26,48 @@ pub fn build(b: *std.Build) void {
26
26
27
27
const exe = b .addExecutable (.{
28
28
.name = "lsp-codegen" ,
29
- .root_source_file = b .path ("src/main.zig" ),
30
- .target = b .graph .host ,
29
+ .root_module = b .addModule ("lsp-codegen" , .{
30
+ .root_source_file = b .path ("src/main.zig" ),
31
+ .target = b .graph .host ,
32
+ }),
31
33
});
32
34
// The metaModel.json file should be removed once https://github.com/ziglang/zig/issues/17895 has been resolved.
33
35
exe .root_module .addAnonymousImport ("meta-model" , .{ .root_source_file = b .path ("metaModel.json" ) });
34
36
35
37
const run_codegen = b .addRunArtifact (exe );
36
38
const lsp_types_output_file = run_codegen .addOutputFileArg ("lsp_types.zig" );
37
39
38
- const lsp_parser_module = b .addModule ("lsp-parser" , .{ .root_source_file = b .path ("src/parser.zig" ) });
39
- const lsp_types_module = b .addModule ("lsp-types" , .{ .root_source_file = lsp_types_output_file });
40
- lsp_types_module .addImport ("parser" , lsp_parser_module );
40
+ const lsp_parser_module = b .addModule ("lsp-parser" , .{
41
+ .root_source_file = b .path ("src/parser.zig" ),
42
+ .target = target ,
43
+ .optimize = optimize ,
44
+ });
45
+
46
+ const lsp_types_module = b .addModule ("lsp-types" , .{
47
+ .root_source_file = lsp_types_output_file ,
48
+ .target = target ,
49
+ .optimize = optimize ,
50
+ .imports = &.{
51
+ .{ .name = "parser" , .module = lsp_parser_module },
52
+ },
53
+ });
41
54
42
55
const lsp_module = b .addModule ("lsp" , .{
43
56
.root_source_file = b .path ("src/lsp.zig" ),
44
57
.target = target ,
45
58
.optimize = optimize ,
59
+ .imports = &.{
60
+ .{ .name = "parser" , .module = lsp_parser_module },
61
+ .{ .name = "types" , .module = lsp_types_module },
62
+ },
46
63
});
47
- lsp_module .addImport ("parser" , lsp_parser_module );
48
- lsp_module .addImport ("types" , lsp_types_module );
49
64
50
65
// -------------------------------- Autodoc --------------------------------
51
66
52
- // This can be simplified with https://github.com/ziglang/zig/pull/20388
53
67
const autodoc_exe = b .addObject (.{
54
68
.name = "lsp" ,
55
- .root_source_file = b .path ("src/lsp.zig" ),
56
- .target = target ,
57
- .optimize = .Debug ,
69
+ .root_module = lsp_module ,
58
70
});
59
- autodoc_exe .root_module .addImport ("parser" , lsp_parser_module );
60
- autodoc_exe .root_module .addImport ("types" , lsp_types_module );
61
71
62
72
const install_docs = b .addInstallDirectory (.{
63
73
.source_dir = autodoc_exe .getEmittedDocs (),
@@ -70,23 +80,16 @@ pub fn build(b: *std.Build) void {
70
80
71
81
// --------------------------------- Tests ---------------------------------
72
82
73
- // This can be simplified with https://github.com/ziglang/zig/pull/20388
74
83
const lsp_tests = b .addTest (.{
75
- .root_source_file = b .path ("src/lsp.zig" ),
76
- .target = target ,
77
- .optimize = optimize ,
84
+ .root_module = lsp_module ,
78
85
.filters = test_filters ,
79
86
.use_lld = use_llvm ,
80
87
.use_llvm = use_llvm ,
81
88
});
82
- lsp_tests .root_module .addImport ("parser" , lsp_parser_module );
83
- lsp_tests .root_module .addImport ("types" , lsp_types_module );
84
89
85
90
const lsp_parser_tests = b .addTest (.{
86
91
.name = "test parser" ,
87
- .root_source_file = b .path ("src/parser.zig" ),
88
- .target = target ,
89
- .optimize = optimize ,
92
+ .root_module = lsp_parser_module ,
90
93
.filters = test_filters ,
91
94
.use_lld = use_llvm ,
92
95
.use_llvm = use_llvm ,
@@ -100,23 +103,18 @@ pub fn build(b: *std.Build) void {
100
103
101
104
const kcov_bin = b .findProgram (&.{"kcov" }, &.{}) catch "kcov" ;
102
105
103
- const addOutputDirectoryArg = comptime if (@import ("builtin" ).zig_version .order (.{ .major = 0 , .minor = 13 , .patch = 0 }) == .lt )
104
- std .Build .Step .Run .addOutputFileArg
105
- else
106
- std .Build .Step .Run .addOutputDirectoryArg ;
107
-
108
106
const kcov_merge = std .Build .Step .Run .create (b , "kcov merge coverage" );
109
107
kcov_merge .rename_step_with_output_arg = false ;
110
108
kcov_merge .addArg (kcov_bin );
111
109
kcov_merge .addArg ("--merge" );
112
- const coverage_output = addOutputDirectoryArg (kcov_merge , "." );
110
+ const coverage_output = kcov_merge . addOutputDirectoryArg ("." );
113
111
114
112
for ([_ ]* std.Build.Step.Compile { lsp_tests , lsp_parser_tests }) | test_artifact | {
115
113
const kcov_collect = std .Build .Step .Run .create (b , "kcov collect coverage" );
116
114
kcov_collect .addArg (kcov_bin );
117
115
kcov_collect .addArg ("--collect-only" );
118
116
kcov_collect .addPrefixedDirectoryArg ("--include-pattern=" , b .path ("." ));
119
- kcov_merge .addDirectoryArg (addOutputDirectoryArg (kcov_collect , test_artifact .name ));
117
+ kcov_merge .addDirectoryArg (kcov_collect . addOutputDirectoryArg (test_artifact .name ));
120
118
kcov_collect .addArtifactArg (test_artifact );
121
119
kcov_collect .enableTestRunnerMode ();
122
120
}
0 commit comments