-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
68 lines (59 loc) · 2.14 KB
/
build.zig
File metadata and controls
68 lines (59 loc) · 2.14 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
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("pjs.h"),
.target = target,
.optimize = optimize,
.php_include_root = .{
.cwd_relative = php_include_root,
},
});
const quickjs_dep = b.dependency("quickjs", .{ .target = target, .optimize = optimize });
const ext_lib = b.addLibrary(.{
.name = "pjs",
.root_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "phpz", .module = phpz.mod },
.{ .name = "quickjs", .module = quickjs_dep.module("quickjs") },
},
}),
.use_llvm = true,
.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" },
"pjs.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/pjs.so",
"test.php",
});
const test_info_cmd = b.addSystemCommand(&[_][]const u8{
"php",
"-dextension=./modules/pjs.so",
"--ri",
"pjs",
});
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);
}