-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
92 lines (81 loc) · 2.94 KB
/
build.zig
File metadata and controls
92 lines (81 loc) · 2.94 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
const std = @import("std");
pub const Phpz = @import("./build/Phpz.zig");
const BuildOptions = struct {
php_include_root: []const u8,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
};
pub fn build(b: *std.Build) void {
const options = BuildOptions{
.php_include_root = b.option([]const u8, "php-include-root", "PHP root include directory path") orelse "/usr/include/php",
.target = b.standardTargetOptions(.{}),
.optimize = b.standardOptimizeOption(.{}),
};
const mod = createPhpzModule(b, options);
addCheckStep(b, mod);
addGenerateDocsStep(b, mod);
addTestStep(b, options);
}
fn createPhpzModule(b: *std.Build, options: BuildOptions) *std.Build.Module {
return Phpz.initInner(b, .{
.php_include_root = .{ .cwd_relative = options.php_include_root },
.c_source_file = b.path("build/phpz.h"),
.target = options.target,
.optimize = options.optimize,
}).mod;
}
fn addCheckStep(b: *std.Build, mod: *std.Build.Module) void {
const lib_check = b.addLibrary(.{
.name = "phpz",
.root_module = mod,
});
const check = b.step("check", "Check that phpz builds correctly");
check.dependOn(&lib_check.step);
}
fn addGenerateDocsStep(b: *std.Build, mod: *std.Build.Module) void {
const doc_step = b.step("docs", "Generate documentation for phpz");
// Generate docs for main library (src/root.zig)
const doc_obj = b.addObject(.{
.name = "phpz",
.root_module = mod,
});
const install_docs = b.addInstallDirectory(.{
.source_dir = doc_obj.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs/lib",
});
doc_step.dependOn(&install_docs.step);
// Generate docs for build system (build/Phpz.zig)
const build_doc_obj = b.addObject(.{
.name = "phpz-build",
.root_module = b.createModule(.{
.root_source_file = b.path("build/Phpz.zig"),
.target = mod.resolved_target,
.optimize = mod.optimize,
}),
});
const install_build_docs = b.addInstallDirectory(.{
.source_dir = build_doc_obj.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "docs/build",
});
doc_step.dependOn(&install_build_docs.step);
}
fn addTestStep(b: *std.Build, options: BuildOptions) void {
const step = b.step("test", "Run tests for phpz");
const examples = [_][]const u8{
"my_php_extension",
"pjs",
};
inline for (examples) |test_example| {
const test_cmd = b.addSystemCommand(&[_][]const u8{
b.graph.zig_exe,
"build",
"test",
b.fmt("-Dphp-include-root={s}", .{options.php_include_root}),
b.fmt("-Doptimize={s}", .{@tagName(options.optimize)}),
});
test_cmd.setCwd(b.path("examples").join(b.allocator, test_example) catch unreachable);
step.dependOn(&test_cmd.step);
}
}