-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.zig
115 lines (94 loc) · 4.62 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const use_llvm = b.option(bool, "use-llvm", "Use Zig's llvm code backend");
const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match filter") orelse &[0][]const u8{};
// -------------------------------------------------------------------------
const exe = b.addExecutable(.{
.name = "lsp-codegen",
.root_source_file = b.path("src/main.zig"),
.target = b.graph.host,
});
// The metaModel.json file should be removed once https://github.com/ziglang/zig/issues/17895 has been resolved.
exe.root_module.addAnonymousImport("meta-model", .{ .root_source_file = b.path("metaModel.json") });
const run_codegen = b.addRunArtifact(exe);
const lsp_types_output_file = run_codegen.addOutputFileArg("lsp_types.zig");
const lsp_parser_module = b.addModule("lsp-parser", .{ .root_source_file = b.path("src/parser.zig") });
const lsp_types_module = b.addModule("lsp-types", .{ .root_source_file = lsp_types_output_file });
lsp_types_module.addImport("parser", lsp_parser_module);
const lsp_module = b.addModule("lsp", .{
.root_source_file = b.path("src/lsp.zig"),
.target = target,
.optimize = optimize,
});
lsp_module.addImport("parser", lsp_parser_module);
lsp_module.addImport("types", lsp_types_module);
// -------------------------------- Autodoc --------------------------------
// This can be simplified with https://github.com/ziglang/zig/pull/20388
const autodoc_exe = b.addObject(.{
.name = "lsp",
.root_source_file = b.path("src/lsp.zig"),
.target = target,
.optimize = .Debug,
});
autodoc_exe.root_module.addImport("parser", lsp_parser_module);
autodoc_exe.root_module.addImport("types", lsp_types_module);
const install_docs = b.addInstallDirectory(.{
.source_dir = autodoc_exe.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "doc/lsp-codegen",
});
const docs_step = b.step("docs", "Generate and install documentation");
docs_step.dependOn(&install_docs.step);
// --------------------------------- Tests ---------------------------------
// This can be simplified with https://github.com/ziglang/zig/pull/20388
const lsp_tests = b.addTest(.{
.root_source_file = b.path("src/lsp.zig"),
.target = target,
.optimize = optimize,
.filters = test_filters,
.use_lld = use_llvm,
.use_llvm = use_llvm,
});
lsp_tests.root_module.addImport("parser", lsp_parser_module);
lsp_tests.root_module.addImport("types", lsp_types_module);
const lsp_parser_tests = b.addTest(.{
.name = "test parser",
.root_source_file = b.path("src/parser.zig"),
.target = target,
.optimize = optimize,
.filters = test_filters,
.use_lld = use_llvm,
.use_llvm = use_llvm,
});
const test_step = b.step("test", "Run all the tests");
test_step.dependOn(&b.addRunArtifact(lsp_tests).step);
test_step.dependOn(&b.addRunArtifact(lsp_parser_tests).step);
// ----------------------------- Code Coverage -----------------------------
const addOutputDirectoryArg = comptime if (@import("builtin").zig_version.order(.{ .major = 0, .minor = 13, .patch = 0 }) == .lt)
std.Build.Step.Run.addOutputFileArg
else
std.Build.Step.Run.addOutputDirectoryArg;
const kcov_merge = std.Build.Step.Run.create(b, "kcov merge coverage");
kcov_merge.rename_step_with_output_arg = false;
kcov_merge.addArg("kcov");
kcov_merge.addArg("--merge");
const coverage_output = addOutputDirectoryArg(kcov_merge, ".");
for ([_]*std.Build.Step.Compile{ lsp_tests, lsp_parser_tests }) |test_artifact| {
const kcov_collect = std.Build.Step.Run.create(b, "kcov collect coverage");
kcov_collect.addArg("kcov");
kcov_collect.addArg("--collect-only");
kcov_collect.addPrefixedDirectoryArg("--include-pattern=", b.path("."));
kcov_merge.addDirectoryArg(addOutputDirectoryArg(kcov_collect, test_artifact.name));
kcov_collect.addArtifactArg(test_artifact);
kcov_collect.enableTestRunnerMode();
}
const install_coverage = b.addInstallDirectory(.{
.source_dir = coverage_output,
.install_dir = .{ .custom = "coverage" },
.install_subdir = "",
});
const coverage_step = b.step("coverage", "Generate a coverage report with kcov");
coverage_step.dependOn(&install_coverage.step);
}