-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
83 lines (70 loc) · 2.82 KB
/
build.zig
File metadata and controls
83 lines (70 loc) · 2.82 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
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const mime = b.dependency("mime", .{});
const tls = b.dependency("tls", .{});
const zemplate = b.dependency("zemplate", .{});
const mod = b.addModule("zyph", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
});
mod.addImport("mime", mime.module("mime"));
mod.addImport("tls", tls.module("tls"));
mod.addImport("zemplate", zemplate.module("zemplate"));
buildExamples(b, target, optimize, mod) catch |e| {
std.log.err("Failed to build examples: {any}", .{e});
};
const lib_unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/all.zig"),
.target = target,
.optimize = optimize,
}),
});
lib_unit_tests.root_module.addImport("zyph", mod);
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
// test_step.dependOn(&zemplate.step);
test_step.dependOn(&run_lib_unit_tests.step);
}
fn buildExamples(b: *std.Build, target: std.Build.ResolvedTarget, opt: std.builtin.OptimizeMode, core_lib: *std.Build.Module) anyerror!void {
const examples_dir = "examples";
const dir = std.fs.cwd().openDir(examples_dir, .{}) catch |e| {
std.log.err("Failed to get examples: {s}\nError: {any}", .{ examples_dir, e });
return e;
};
var buffer: [256]u8 = undefined;
@memset(&buffer, 0);
var fba = std.heap.FixedBufferAllocator.init(&buffer);
var iter = dir.iterate();
while (iter.next() catch |e| {
std.log.err("Dir iterator failure: {}\n", .{e});
return e;
}) |f| {
const name = name: {
var split = std.mem.splitBackwardsScalar(u8, f.name, '.');
_ = split.first();
break :name split.next() orelse @panic("malformed bin file name");
};
const fullpath = std.fmt.allocPrint(fba.allocator(), "{s}/{s}", .{ examples_dir, f.name }) catch |e| std.debug.panic("Failed to get full path: {}\n", .{e});
const exe = b.addExecutable(.{
.name = name,
.root_module = b.createModule(.{
.root_source_file = b.path(fullpath),
.target = target,
.optimize = opt,
}),
});
exe.root_module.addImport("core", core_lib);
// b.installArtifact(exe);
const run = b.addRunArtifact(exe);
const step = b.step(name, f.name);
step.dependOn(&run.step);
if (b.args) |args| {
run.addArgs(args);
}
}
}