-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.zig
More file actions
108 lines (87 loc) · 3.29 KB
/
Copy pathbuild.zig
File metadata and controls
108 lines (87 loc) · 3.29 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const fluentzig = b.addModule("fluentorm", .{
.root_source_file = b.path("src/root.zig"),
});
const pg = b.dependency("pg", .{
.target = target,
.optimize = optimize,
});
const dotenv = b.dependency("dotenv", .{
.target = target,
.optimize = optimize,
});
fluentzig.addImport("pg", pg.module("pg"));
fluentzig.addImport("dotenv", dotenv.module("dotenv"));
// Generator executable - Standalone model generator
const gen_exe = b.addExecutable(.{
.name = "fluentzig-gen",
.root_module = b.createModule(.{
.root_source_file = b.path("src/generate_model.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "fluentorm", .module = fluentzig },
.{ .name = "pg", .module = pg.module("pg") },
.{ .name = "dotenv", .module = dotenv.module("dotenv") },
},
}),
});
b.installArtifact(gen_exe);
// Migration runner executable
const migrate_exe = b.addExecutable(.{
.name = "fluent-migrate",
.root_module = b.createModule(.{
.root_source_file = b.path("src/migration_runner.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "fluentorm", .module = fluentzig },
.{ .name = "pg", .module = pg.module("pg") },
.{ .name = "dotenv", .module = dotenv.module("dotenv") },
},
}),
});
b.installArtifact(migrate_exe);
// Migration directory option
const migrations_dir = b.option([]const u8, "migrations-dir", "Directory containing migration files") orelse "migrations";
// Env file option
const env_file = b.option([]const u8, "env-file", "Path to .env file") orelse ".env";
// Run step for local testing
const run_cmd = b.addRunArtifact(gen_exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the generator");
run_step.dependOn(&run_cmd.step);
// Migrate step
const migrate_cmd = b.addRunArtifact(migrate_exe);
migrate_cmd.step.dependOn(b.getInstallStep());
migrate_cmd.addArgs(&.{ "--migrations-dir", migrations_dir });
migrate_cmd.addArgs(&.{ "--env-file", env_file });
if (b.args) |args| {
migrate_cmd.addArgs(args);
}
const migrate_step = b.step("migrate", "Run database migrations");
migrate_step.dependOn(&migrate_cmd.step);
// Test step
const lib_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "pg", .module = pg.module("pg") },
},
}),
});
const run_lib_tests = b.addRunArtifact(lib_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_tests.step);
// Help step
const help_step = b.step("help", "Show help information");
_ = help_step;
}