-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deps.zig
146 lines (128 loc) · 4.92 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// zig fmt: off
const std = @import("std");
const builtin = @import("builtin");
const Pkg = std.build.Pkg;
const string = []const u8;
pub const GitExactStep = struct {
step: std.build.Step,
builder: *std.build.Builder,
url: string,
commit: string,
pub fn create(b: *std.build.Builder, url: string, commit: string) *GitExactStep {
var result = b.allocator.create(GitExactStep) catch @panic("memory");
result.* = GitExactStep{
.step = std.build.Step.init(.custom, b.fmt("git clone {s} @ {s}", .{ url, commit }), b.allocator, make),
.builder = b,
.url = url,
.commit = commit,
};
var urlpath = url;
urlpath = trimPrefix(u8, urlpath, "https://");
urlpath = trimPrefix(u8, urlpath, "git://");
const repopath = b.fmt("{s}/zigmod/deps/git/{s}/{s}", .{ b.cache_root, urlpath, commit });
flip(std.fs.cwd().access(repopath, .{})) catch return result;
var clonestep = std.build.RunStep.create(b, "clone");
clonestep.addArgs(&.{ "git", "clone", "-q", "--progress", url, repopath });
result.step.dependOn(&clonestep.step);
var checkoutstep = std.build.RunStep.create(b, "checkout");
checkoutstep.addArgs(&.{ "git", "-C", repopath, "checkout", "-q", commit });
result.step.dependOn(&checkoutstep.step);
return result;
}
fn make(step: *std.build.Step) !void {
_ = step;
}
};
pub fn fetch(exe: *std.build.LibExeObjStep) void {
const b = exe.builder;
inline for (comptime std.meta.declarations(package_data)) |decl| {
const path = &@field(package_data, decl.name).entry;
const root = if (@field(package_data, decl.name).store) |_| b.cache_root else ".";
if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? });
}
}
fn trimPrefix(comptime T: type, haystack: []const T, needle: []const T) []const T {
if (std.mem.startsWith(T, haystack, needle)) {
return haystack[needle.len .. haystack.len];
}
return haystack;
}
fn flip(foo: anytype) !void {
_ = foo catch return;
return error.ExpectedError;
}
pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
checkMinZig(builtin.zig_version, exe);
fetch(exe);
const b = exe.builder;
@setEvalBranchQuota(1_000_000);
for (packages) |pkg| {
exe.addPackage(pkg.zp(b));
}
var llc = false;
var vcpkg = false;
inline for (comptime std.meta.declarations(package_data)) |decl| {
const pkg = @as(Package, @field(package_data, decl.name));
const root = if (pkg.store) |st| b.fmt("{s}/zigmod/deps/{s}", .{ b.cache_root, st }) else ".";
for (pkg.system_libs) |item| {
exe.linkSystemLibrary(item);
llc = true;
}
for (pkg.frameworks) |item| {
if (!builtin.target.isDarwin()) @panic(exe.builder.fmt("a dependency is attempting to link to the framework {s}, which is only possible under Darwin", .{item}));
exe.linkFramework(item);
llc = true;
}
for (pkg.c_include_dirs) |item| {
exe.addIncludeDir(b.fmt("{s}/{s}", .{ root, item }));
llc = true;
}
for (pkg.c_source_files) |item| {
exe.addCSourceFile(b.fmt("{s}/{s}", .{ root, item }), pkg.c_source_flags);
llc = true;
}
vcpkg = vcpkg or pkg.vcpkg;
}
if (llc) exe.linkLibC();
if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err));
}
pub const Package = struct {
name: string = "",
entry: ?string = null,
store: ?string = null,
deps: []const *Package = &.{},
c_include_dirs: []const string = &.{},
c_source_files: []const string = &.{},
c_source_flags: []const string = &.{},
system_libs: []const string = &.{},
frameworks: []const string = &.{},
vcpkg: bool = false,
pub fn zp(self: *const Package, b: *std.build.Builder) Pkg {
var temp: [100]Pkg = undefined;
for (self.deps) |item, i| {
temp[i] = item.zp(b);
}
return .{
.name = self.name,
.source = .{ .path = self.entry.? },
.dependencies = b.allocator.dupe(Pkg, temp[0..self.deps.len]) catch @panic("oom"),
};
}
};
fn checkMinZig(current: std.SemanticVersion, exe: *std.build.LibExeObjStep) void {
const min = std.SemanticVersion.parse("null") catch return;
if (current.order(min).compare(.lt)) @panic(exe.builder.fmt("Your Zig version v{} does not meet the minimum build requirement of v{}", .{current, min}));
}
pub const package_data = struct {
pub var _root = Package{
.system_libs = &.{ "fuse3" },
};
pub var _i0xhsq87to7x = Package{
};
};
pub const packages = [_]*const Package{
};
pub const pkgs = struct {
};
pub const imports = struct {
};