Skip to content

Commit 063a98c

Browse files
committed
remove usage of deprecated build system API
1 parent 3914656 commit 063a98c

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

build.zig

+27-29
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,48 @@ pub fn build(b: *std.Build) void {
2626

2727
const exe = b.addExecutable(.{
2828
.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+
}),
3133
});
3234
// The metaModel.json file should be removed once https://github.com/ziglang/zig/issues/17895 has been resolved.
3335
exe.root_module.addAnonymousImport("meta-model", .{ .root_source_file = b.path("metaModel.json") });
3436

3537
const run_codegen = b.addRunArtifact(exe);
3638
const lsp_types_output_file = run_codegen.addOutputFileArg("lsp_types.zig");
3739

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+
});
4154

4255
const lsp_module = b.addModule("lsp", .{
4356
.root_source_file = b.path("src/lsp.zig"),
4457
.target = target,
4558
.optimize = optimize,
59+
.imports = &.{
60+
.{ .name = "parser", .module = lsp_parser_module },
61+
.{ .name = "types", .module = lsp_types_module },
62+
},
4663
});
47-
lsp_module.addImport("parser", lsp_parser_module);
48-
lsp_module.addImport("types", lsp_types_module);
4964

5065
// -------------------------------- Autodoc --------------------------------
5166

52-
// This can be simplified with https://github.com/ziglang/zig/pull/20388
5367
const autodoc_exe = b.addObject(.{
5468
.name = "lsp",
55-
.root_source_file = b.path("src/lsp.zig"),
56-
.target = target,
57-
.optimize = .Debug,
69+
.root_module = lsp_module,
5870
});
59-
autodoc_exe.root_module.addImport("parser", lsp_parser_module);
60-
autodoc_exe.root_module.addImport("types", lsp_types_module);
6171

6272
const install_docs = b.addInstallDirectory(.{
6373
.source_dir = autodoc_exe.getEmittedDocs(),
@@ -70,23 +80,16 @@ pub fn build(b: *std.Build) void {
7080

7181
// --------------------------------- Tests ---------------------------------
7282

73-
// This can be simplified with https://github.com/ziglang/zig/pull/20388
7483
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,
7885
.filters = test_filters,
7986
.use_lld = use_llvm,
8087
.use_llvm = use_llvm,
8188
});
82-
lsp_tests.root_module.addImport("parser", lsp_parser_module);
83-
lsp_tests.root_module.addImport("types", lsp_types_module);
8489

8590
const lsp_parser_tests = b.addTest(.{
8691
.name = "test parser",
87-
.root_source_file = b.path("src/parser.zig"),
88-
.target = target,
89-
.optimize = optimize,
92+
.root_module = lsp_parser_module,
9093
.filters = test_filters,
9194
.use_lld = use_llvm,
9295
.use_llvm = use_llvm,
@@ -100,23 +103,18 @@ pub fn build(b: *std.Build) void {
100103

101104
const kcov_bin = b.findProgram(&.{"kcov"}, &.{}) catch "kcov";
102105

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-
108106
const kcov_merge = std.Build.Step.Run.create(b, "kcov merge coverage");
109107
kcov_merge.rename_step_with_output_arg = false;
110108
kcov_merge.addArg(kcov_bin);
111109
kcov_merge.addArg("--merge");
112-
const coverage_output = addOutputDirectoryArg(kcov_merge, ".");
110+
const coverage_output = kcov_merge.addOutputDirectoryArg(".");
113111

114112
for ([_]*std.Build.Step.Compile{ lsp_tests, lsp_parser_tests }) |test_artifact| {
115113
const kcov_collect = std.Build.Step.Run.create(b, "kcov collect coverage");
116114
kcov_collect.addArg(kcov_bin);
117115
kcov_collect.addArg("--collect-only");
118116
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));
120118
kcov_collect.addArtifactArg(test_artifact);
121119
kcov_collect.enableTestRunnerMode();
122120
}

0 commit comments

Comments
 (0)