-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
174 lines (171 loc) · 5.54 KB
/
build.zig
File metadata and controls
174 lines (171 loc) · 5.54 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const mod = b.addModule("flow", .{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
const notcurses_lib_path = "external/notcurses";
try addCLibrary(
b,
b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.sanitize_c = .off, // Causes memory issues
}),
mod,
"notcurses",
&[_][]const u8{notcurses_lib_path ++ "/include"},
&[_][]const u8{"deflate", "ncurses", "unistring", "readline", "z"},
&[_][]const u8{
notcurses_lib_path ++ "/include",
notcurses_lib_path ++ "/build/include",
notcurses_lib_path ++ "/src"
},
&[_][]const u8{
notcurses_lib_path ++ "/src/lib/",
notcurses_lib_path ++ "/src/compat/"
},
&[_][]const u8{
"-std=gnu11",
"-D_GNU_SOURCE",
// NOTE: This means only notcurses_core_init can be used.
// Change this to Non-none for the notcurses_init
// symbol to be defined
"-DUSE_MULTIMEDIA=none",
}
);
const piecechain_lib_path = "external/PieceChain";
try addCLibrary(
b,
b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.sanitize_c = .off, // Causes memory issues
}),
mod,
"piecechain",
&[_][]const u8{piecechain_lib_path ++ "/include"},
null,
&[_][]const u8{
piecechain_lib_path ++ "/include",
piecechain_lib_path ++ "/src"
},
&[_][]const u8{piecechain_lib_path ++ "/src/"},
&[_][]const u8{
"-std=gnu11"
},
);
const tree_sitter = b.dependency("tree_sitter", .{
.target = target,
.optimize = optimize,
});
mod.addImport("tree-sitter", tree_sitter.module("tree_sitter"));
const ts_lang_zig = b.dependency("ts_lang_zig", .{
.target = target,
.optimize = optimize,
});
mod.addImport("ts-lang-zig", ts_lang_zig.module("tree-sitter-zig"));
const known_folders = b.dependency("known_folders", .{
.target = target,
.optimize = optimize,
});
mod.addImport("known-folders", known_folders.module("known-folders"));
const datetime = b.dependency("datetime", .{
.target = target,
.optimize = optimize,
});
mod.addImport("datetime", datetime.module("datetime"));
const exe = b.addExecutable(.{
.name = "flow",
.root_module = mod,
});
b.installArtifact(exe);
const run_step = b.step("run", "Run the app");
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
// const mod_tests = b.addTest(.{
// .root_module = mod,
// });
// const run_mod_tests = b.addRunArtifact(mod_tests);
// const exe_tests = b.addTest(.{
// .root_module = exe.root_module,
// });
// const run_exe_tests = b.addRunArtifact(exe_tests);
// const test_step = b.step("test", "Run tests");
// test_step.dependOn(&run_mod_tests.step);
// test_step.dependOn(&run_exe_tests.step);
}
fn addCLibrary(
b: *std.Build,
mod: *std.Build.Module,
root_module: *std.Build.Module,
comptime name: []const u8,
comptime root_module_include_paths: []const []const u8,
comptime system_libraries: ?[]const []const u8,
comptime include_paths: []const []const u8,
comptime source_paths: []const []const u8,
comptime compile_flags: ?[]const []const u8,
) !void {
for (root_module_include_paths) |p| {
root_module.addIncludePath(b.path(p));
}
if (system_libraries) |sys_libs| {
for (sys_libs) |sys_lib| {
mod.linkSystemLibrary(sys_lib, .{ .preferred_link_mode = .static });
}
}
for (include_paths) |inc_path| {
mod.addIncludePath(b.path(inc_path));
}
var files: std.ArrayList([]const u8) = try .initCapacity(b.allocator, 0);
defer {
for (files.items) |file| {
b.allocator.free(file);
}
files.deinit(b.allocator);
}
for (source_paths) |src_path| {
try collectCSources(b, src_path, &files);
}
mod.addCSourceFiles(.{
.files = files.items,
.flags = compile_flags orelse &[_][]const u8{},
});
const library: *std.Build.Step.Compile = b.addLibrary(.{
.name = name,
.linkage = .static,
.root_module = mod,
});
b.installArtifact(library);
root_module.linkLibrary(library);
}
fn collectCSources(b: *std.Build, path: []const u8, files: *std.ArrayList([]const u8)) !void {
var dir: std.fs.Dir = try std.fs.cwd().openDir(
path,
.{ .iterate = true }
);
var walker: std.fs.Dir.Walker = try dir.walk(b.allocator);
defer walker.deinit();
while (try walker.next()) |entry| {
const ext: []const u8 = std.fs.path.extension(entry.basename);
if (std.mem.eql(u8, ext, ".c")) {
try files.append(
b.allocator,
try std.mem.concat(b.allocator, u8, &[_][]const u8{
path,
entry.path
}),
);
}
}
}