-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
79 lines (65 loc) · 2.47 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 shared = b.option(bool, "build-shared", "Build a shared library") orelse true;
const reuse_alloc = b.option(bool, "reuse-allocator", "Reuse the library allocator") orelse false;
const lib: *std.Build.Step.Compile = if (shared) b.addSharedLibrary(.{
.name = "tree_sitter_netlinx",
.pic = true,
.target = target,
.optimize = optimize,
.link_libc = true,
}) else b.addStaticLibrary(.{
.name = "tree_sitter_netlinx",
.target = target,
.optimize = optimize,
.link_libc = true,
});
lib.addCSourceFile(.{
.file = b.path("src/parser.c"),
.flags = &.{"-std=c11"},
});
if (hasScanner(b.build_root.handle)) {
lib.addCSourceFile(.{
.file = b.path("src/scanner.c"),
.flags = &.{"-std=c11"},
});
}
if (reuse_alloc) {
lib.root_module.addCMacro("TREE_SITTER_REUSE_ALLOCATOR", "");
}
if (optimize == .Debug) {
lib.root_module.addCMacro("TREE_SITTER_DEBUG", "");
}
lib.addIncludePath(b.path("src"));
b.installArtifact(lib);
b.installFile("src/node-types.json", "node-types.json");
b.installDirectory(.{ .source_dir = b.path("queries"), .install_dir = .prefix, .install_subdir = "queries", .include_extensions = &.{"scm"} });
const module = b.addModule("tree_sitter_netlinx", .{
.root_source_file = b.path("bindings/zig/root.zig"),
.target = target,
.optimize = optimize,
});
module.linkLibrary(lib);
const ts_dep = b.dependency("tree_sitter", .{});
const ts_mod = ts_dep.module("tree-sitter");
module.addImport("tree-sitter", ts_mod);
// ╭─────────────────╮
// │ Tests │
// ╰─────────────────╯
const tests = b.addTest(.{
.root_source_file = b.path("bindings/zig/root.zig"),
.target = target,
.optimize = optimize,
});
tests.linkLibrary(lib);
tests.root_module.addImport("tree_sitter", ts_mod);
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);
}
inline fn hasScanner(dir: std.fs.Dir) bool {
dir.access("src/scanner.c", .{}) catch return false;
return true;
}