-
Notifications
You must be signed in to change notification settings - Fork 0
/
deps.zig
117 lines (98 loc) · 2.89 KB
/
deps.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
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
const std = @import("std");
const builtin = @import("builtin");
const Pkg = std.build.Pkg;
const string = []const u8;
pub const cache = ".zigmod/deps";
pub fn addAllTo(
exe: *std.build.LibExeObjStep,
b: *std.build.Builder,
target: std.zig.CrossTarget,
mode: std.builtin.Mode,
) *std.build.LibExeObjStep {
@setEvalBranchQuota(1_000_000);
exe.setTarget(target);
exe.setBuildMode(mode);
// lazy
if (c_libs[0] == null) resolveCLibs(b, target, mode);
for (c_libs) |c_lib| exe.linkLibrary(c_lib.?);
for (packages) |pkg| {
exe.addPackage(pkg.pkg.?);
}
inline for (std.meta.declarations(package_data)) |decl| {
const pkg = @as(Package, @field(package_data, decl.name));
inline for (pkg.system_libs) |item| {
exe.linkSystemLibrary(item);
}
inline for (pkg.c_include_dirs) |item| {
exe.addIncludeDir(@field(dirs, decl.name) ++ "/" ++ item);
}
inline for (pkg.c_source_files) |item| {
exe.addCSourceFile(@field(dirs, decl.name) ++ "/" ++ item, pkg.c_source_flags);
}
}
exe.linkLibC();
return exe;
}
pub const CLib = struct {
name: string,
idx: usize,
pub fn getStep(self: *CLib) ?*std.build.LibExeObjStep {
return c_libs[self.idx];
}
};
pub const Package = struct {
directory: string,
pkg: ?Pkg = null,
c_include_dirs: []const string = &.{},
c_libs: []const CLib = &.{},
c_source_files: []const string = &.{},
c_source_flags: []const string = &.{},
system_libs: []const string = &.{},
vcpkg: bool = false,
};
pub const dirs = struct {
pub const _root = "";
pub const _f3itt0eg63fb = ".";
};
const zero_deps_map = std.ComptimeStringMap(string, .{ .{ "", "" } });
pub const dep_dirs = struct {
pub const _root = std.ComptimeStringMap(string, .{
.{ "zpp", dirs._f3itt0eg63fb },
});
pub const _f3itt0eg63fb = zero_deps_map;
};
pub const package_data = struct {
pub const _f3itt0eg63fb = Package{
.directory = dirs._f3itt0eg63fb,
.pkg = Pkg{ .name = "zpp", .path = .{ .path = dirs._f3itt0eg63fb ++ "/src/lib.zig" }, .dependencies = null },
.c_include_dirs = &.{ "include" },
.c_libs = &.{
.{ .name = "zpp", .idx = 0 },
},
};
pub const _root = Package{
.directory = dirs._root,
};
};
pub const packages = &[_]Package{
package_data._f3itt0eg63fb,
};
pub const pkgs = struct {
pub const zpp = package_data._f3itt0eg63fb;
};
// lazy
var c_libs = std.mem.zeroes([1]?*std.build.LibExeObjStep);
fn resolveCLibs(
b: *std.build.Builder,
target: std.zig.CrossTarget,
mode: std.builtin.Mode,
) void {
c_libs[0] = @import("zpp_lib.zig").configure(
dirs._f3itt0eg63fb,
dep_dirs._f3itt0eg63fb,
dep_dirs._root,
b.allocator,
b.addStaticLibrary("zpp", null),
target, mode,
);
}