-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.zig
More file actions
130 lines (113 loc) · 4.53 KB
/
Copy pathbuild.zig
File metadata and controls
130 lines (113 loc) · 4.53 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const std = @import("std");
const builtin = @import("builtin");
const required_zig = std.SemanticVersion{ .major = 0, .minor = 15, .patch = 2 };
const macos_deployment_target = std.SemanticVersion{ .major = 14, .minor = 0, .patch = 0 };
comptime {
if (builtin.zig_version.order(required_zig) != .eq) {
const msg = std.fmt.comptimePrint(
"zmux requires Zig {}. You have {}. Run `zvm use {}`.",
.{ required_zig, builtin.zig_version, required_zig },
);
@compileError(msg);
}
}
pub fn build(b: *std.Build) void {
var target = b.standardTargetOptions(.{});
if (target.result.os.tag == .macos and target.query.os_version_min == null) {
var query = target.query;
query.os_version_min = .{ .semver = macos_deployment_target };
target = b.resolveTargetQuery(query);
}
const optimize = b.standardOptimizeOption(.{});
const root_mod = b.addModule("zmux", .{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
root_mod.link_libc = true;
const daemon_mod = createRootModule(b, target, optimize, "src/daemon.zig");
const daemon = b.addExecutable(.{
.name = "zmuxd",
.root_module = daemon_mod,
});
linkPtyArtifact(daemon, target);
const smithers_daemon_mod = createRootModule(b, target, optimize, "src/daemon.zig");
const smithers_daemon = b.addExecutable(.{
.name = "smithers-session-daemon",
.root_module = smithers_daemon_mod,
});
linkPtyArtifact(smithers_daemon, target);
const connect_mod = createConnectModule(b, target, optimize);
const connect = b.addExecutable(.{
.name = "zmux-connect",
.root_module = connect_mod,
});
linkPtyArtifact(connect, target);
const smithers_connect_mod = createConnectModule(b, target, optimize);
const smithers_connect = b.addExecutable(.{
.name = "smithers-session-connect",
.root_module = smithers_connect_mod,
});
linkPtyArtifact(smithers_connect, target);
// iOS cannot spawn local PTY child processes; package artifacts are only
// installed for desktop/server targets.
if (target.result.os.tag != .ios) {
b.installArtifact(daemon);
b.installArtifact(smithers_daemon);
b.installArtifact(connect);
b.installArtifact(smithers_connect);
}
const test_step = b.step("test", "Run zmux unit and integration tests");
const root_tests = b.addTest(.{ .root_module = createRootModule(b, target, optimize, "src/main.zig") });
linkPtyArtifact(root_tests, target);
test_step.dependOn(&b.addRunArtifact(root_tests).step);
const daemon_tests = b.addTest(.{ .root_module = createRootModule(b, target, optimize, "src/daemon.zig") });
linkPtyArtifact(daemon_tests, target);
test_step.dependOn(&b.addRunArtifact(daemon_tests).step);
const connect_tests = b.addTest(.{ .root_module = createConnectModule(b, target, optimize) });
linkPtyArtifact(connect_tests, target);
test_step.dependOn(&b.addRunArtifact(connect_tests).step);
const server_mod = createRootModule(b, target, optimize, "src/server.zig");
const integration_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("test/integration/session_daemon.zig"),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "zmux_server", .module = server_mod }},
}),
});
linkPtyArtifact(integration_tests, target);
test_step.dependOn(&b.addRunArtifact(integration_tests).step);
}
fn createRootModule(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
root: []const u8,
) *std.Build.Module {
const module = b.createModule(.{
.root_source_file = b.path(root),
.target = target,
.optimize = optimize,
});
module.link_libc = true;
return module;
}
fn createConnectModule(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
) *std.Build.Module {
const module = b.createModule(.{
.root_source_file = b.path("src/connect.zig"),
.target = target,
.optimize = optimize,
});
module.link_libc = true;
return module;
}
fn linkPtyArtifact(artifact: *std.Build.Step.Compile, target: std.Build.ResolvedTarget) void {
artifact.linkLibC();
if (target.result.os.tag == .linux) artifact.linkSystemLibrary("util");
if (target.result.os.tag == .macos) artifact.linkSystemLibrary("proc");
}