This repository has been archived by the owner on Sep 16, 2023. It is now read-only.
forked from tonis2/zig-postgres
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.zig
68 lines (55 loc) · 2.13 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
const std = @import("std");
const builtin = @import("builtin");
const Builder = std.build.Builder;
const OptionsStep = std.build.OptionsStep;
const examples = [2][]const u8{ "main", "custom_types" };
const include_dir = switch (builtin.target.os.tag) {
.linux => "/usr/include",
.windows => "C:\\Program Files\\PostgreSQL\\14\\include",
else => "/usr/include"
};
pub fn build(b: *Builder) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const db_uri = b.option(
[]const u8,
"db",
"Specify the database url",
) orelse "postgresql://postgres:postgres@localhost:5432";
inline for (examples) |example| {
const exe = b.addExecutable(example, "examples/" ++ example ++ ".zig");
exe.setTarget(target);
exe.setBuildMode(mode);
const db_options = b.addOptions();
exe.addOptions("db_options", db_options);
db_options.addOption([]const u8, "db_uri", db_uri);
exe.addIncludeDir(include_dir);
exe.addPackagePath("postgres", "src/postgres.zig");
exe.linkSystemLibrary("c");
exe.linkSystemLibrary("libpq");
exe.install();
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
const run_step = b.step(example, "Run the app");
run_step.dependOn(&run_cmd.step);
}
const lib = b.addStaticLibrary("zig-postgres", "src/postgres.zig");
lib.setTarget(target);
lib.setBuildMode(mode);
const db_options = b.addOptions();
lib.addOptions("db_options", db_options);
db_options.addOption([]const u8, "db_uri", db_uri);
lib.addIncludeDir(include_dir);
lib.linkSystemLibrary("c");
lib.linkSystemLibrary("libpq");
const tests = b.addTest("tests.zig");
tests.setBuildMode(mode);
tests.setTarget(target);
tests.addIncludeDir(include_dir);
tests.linkSystemLibrary("c");
tests.linkSystemLibrary("libpq");
tests.addPackagePath("postgres", "src/postgres.zig");
tests.addOptions("db_options", db_options);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&tests.step);
}