-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
55 lines (47 loc) · 1.95 KB
/
build.zig
File metadata and controls
55 lines (47 loc) · 1.95 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
const std = @import("std");
const Phpz = @import("phpz").Phpz;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const php_include_root = b.option([]const u8, "php-include-root", "PHP root include directory path") orelse "/usr/include/php";
const phpz_dep = b.dependency("phpz", .{});
const phpz: Phpz = .init(phpz_dep, .{
.c_source_file = b.path("my_php_extension.h"),
.target = target,
.optimize = optimize,
.php_include_root = .{
.cwd_relative = php_include_root,
},
});
const ext_lib = b.addLibrary(.{
.name = "my_php_extension",
.root_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "phpz", .module = phpz.mod },
},
}),
.linkage = .dynamic,
});
// On macos, allow undefined symbols to be resolved at runtime by PHP
if (target.result.os.tag == .macos) {
ext_lib.linker_allow_shlib_undefined = true;
}
// for zig build system
const install_file = b.addInstallFileWithDir(
ext_lib.getEmittedBin(),
.{ .custom = "../modules" },
"my_php_extension.so",
);
install_file.step.dependOn(&ext_lib.step);
b.getInstallStep().dependOn(&install_file.step);
const test_step = b.step("test", "Test the PHP extension");
const test_cmd = b.addSystemCommand(&[_][]const u8{ "php", "-dextension=./modules/my_php_extension.so", "test.php" });
const test_info_cmd = b.addSystemCommand(&[_][]const u8{ "php", "-dextension=./modules/my_php_extension.so", "--ri", "my_php_extension" });
test_cmd.step.dependOn(b.getInstallStep());
test_info_cmd.step.dependOn(b.getInstallStep());
test_step.dependOn(&test_cmd.step);
test_step.dependOn(&test_info_cmd.step);
}