-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
81 lines (69 loc) · 2.68 KB
/
build.zig
File metadata and controls
81 lines (69 loc) · 2.68 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
const std = @import("std");
pub const RuntimeBackend = enum {
none,
gtk,
swift,
};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const default_runtime: RuntimeBackend = if (target.result.os.tag == .macos) .swift else .none;
const runtime = b.option(RuntimeBackend, "runtime", "App runtime backend") orelse default_runtime;
const build_config = b.addOptions();
build_config.addOption(RuntimeBackend, "runtime", runtime);
const lib = b.addLibrary(.{
.name = "colony_core",
.root_module = b.createModule(.{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "build_config", .module = build_config.createModule() },
},
}),
.linkage = .static,
});
lib.bundle_compiler_rt = true;
lib.linkSystemLibrary("sqlite3");
b.installArtifact(lib);
const lib_header = b.addInstallHeaderFile(
b.path("src/include/colony.h"),
"colony.h",
);
b.getInstallStep().dependOn(&lib_header.step);
const unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "build_config", .module = build_config.createModule() },
},
}),
});
unit_tests.linkSystemLibrary("sqlite3");
const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
const run_step = b.step("run", "Build and run the Swift app");
if (runtime == .swift) {
const swift_build = b.addSystemCommand(&.{
"swift", "build", "--package-path", "macos",
});
swift_build.step.dependOn(b.getInstallStep());
// Run the binary directly (not as .app bundle) so stdout/stderr are visible
const swift_exec = b.addSystemCommand(&.{
b.path("macos/.build/debug/Colony").getPath(b),
});
swift_exec.step.dependOn(&swift_build.step);
// Inherit stdio so logs appear in terminal, don't check exit code
swift_exec.stdio = .inherit;
swift_exec.setEnvironmentVariable("COLONY_LOG_LEVEL", "debug");
run_step.dependOn(&swift_exec.step);
} else {
const run_msg = b.addSystemCommand(&.{ "echo", "Swift runtime only available on macOS" });
run_step.dependOn(&run_msg.step);
}
}