-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.zig
77 lines (62 loc) · 2.6 KB
/
build.zig
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
const std = @import("std");
// Load pgzx build support. The build utilities use pg_config to find all dependencies
// and provide functions go create and test extensions.
const PGBuild = @import("pgzx").Build;
pub fn build(b: *std.Build) void {
const NAME = "char_count_zig";
const VERSION = .{ .major = 0, .minor = 1 };
const DB_TEST_USER = "postgres";
const DB_TEST_PORT = 5432;
const build_options = b.addOptions();
build_options.addOption(bool, "testfn", b.option(bool, "testfn", "Register test function") orelse false);
var proj = PGBuild.Project.init(b, .{
.name = NAME,
.version = VERSION,
.root_dir = "src/",
.root_source_file = "src/main.zig",
});
proj.addOptions("build_options", build_options);
const steps = .{
.check = b.step("check", "Check if project compiles"),
.install = b.getInstallStep(),
.pg_regress = b.step("pg_regress", "Run regression tests"),
.unit = b.step("unit", "Run unit tests"),
};
{ // build and install extension
steps.install.dependOn(&proj.installExtensionLib().step);
steps.install.dependOn(&proj.installExtensionDir().step);
}
{ // check extension Zig source code only. No linkage or installation for faster development.
const lib = proj.extensionLib();
lib.linkage = null;
steps.check.dependOn(&lib.step);
}
{ // pg_regress tests (regression tests use the default build)
var regress = proj.pgbuild.addRegress(.{
.db_user = DB_TEST_USER,
.db_port = DB_TEST_PORT,
.root_dir = ".",
.scripts = &[_][]const u8{
"char_count_test",
},
});
regress.step.dependOn(steps.install);
steps.pg_regress.dependOn(®ress.step);
}
{ // unit testing. We install an alternative version of the lib build with test_fn = true
const test_options = b.addOptions();
test_options.addOption(bool, "testfn", true);
const lib = proj.extensionLib();
lib.root_module.addOptions("build_options", test_options);
// Step for running the unit tests.
const psql_run_tests = proj.pgbuild.addRunTests(.{
.name = NAME,
.db_user = DB_TEST_USER,
.db_port = DB_TEST_PORT,
});
// Build and install extension before running the tests.
psql_run_tests.step.dependOn(&proj.pgbuild.addInstallExtensionLibArtifact(lib, NAME).step);
psql_run_tests.step.dependOn(&proj.installExtensionLib().step);
steps.unit.dependOn(&psql_run_tests.step);
}
}