-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
79 lines (67 loc) · 2.3 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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const core = b.dependency("tree-sitter", .{
.target = target,
.optimize = optimize,
});
const lib = b.addStaticLibrary(.{
.name = "zig-tree-sitter",
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
lib.linkLibrary(core.artifact("tree-sitter"));
b.installArtifact(lib);
const module = b.addModule("tree_sitter", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
module.linkLibrary(lib);
const docs = b.addObject(.{
.name = "tree_sitter",
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = .Debug,
});
const install_docs = b.addInstallDirectory(.{
.source_dir = docs.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs",
});
const docs_step = b.step("docs", "Install generated docs");
docs_step.dependOn(&install_docs.step);
const tests = b.addTest(.{
.root_source_file = b.path("src/test.zig"),
.target = target,
.optimize = optimize,
});
tests.linkLibrary(lib);
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);
// HACK: fetch tree-sitter-c only for tests (ziglang/zig#19914)
var args = try std.process.argsWithAllocator(b.allocator);
defer args.deinit();
while (args.next()) |a| {
if (std.mem.eql(u8, a, "test")) {
if (b.lazyDependency("tree-sitter-c", .{})) |dep| {
const dep_lib = dep.builder.addStaticLibrary(.{
.name = "tree-sitter-c",
.target = target,
.optimize = optimize,
.link_libc = true,
});
dep_lib.addIncludePath(dep.path("src"));
dep_lib.addCSourceFile(.{
.file = dep.path("src/parser.c"),
});
tests.linkLibrary(dep_lib);
}
break;
}
}
}