-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.zig
151 lines (127 loc) · 4.49 KB
/
build.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
147
148
149
150
151
const std = @import ("std");
const toolbox = @import ("toolbox");
fn update (builder: *std.Build, shaderc_path: [] const u8,
dependencies: *const toolbox.Dependencies) !void
{
std.fs.deleteTreeAbsolute (shaderc_path) catch |err|
{
switch (err)
{
error.FileNotFound => {},
else => return err,
}
};
try dependencies.clone (builder, "shaderc", shaderc_path);
var shaderc_dir =
try std.fs.openDirAbsolute (shaderc_path, .{ .iterate = true, });
defer shaderc_dir.close ();
var it = shaderc_dir.iterate ();
while (try it.next ()) |*entry|
{
if (!std.mem.startsWith (u8, entry.name, "libshaderc"))
try std.fs.deleteTreeAbsolute (try std.fs.path.join (builder.allocator,
&.{ shaderc_path, entry.name, }));
}
var walker = try shaderc_dir.walk (builder.allocator);
defer walker.deinit ();
while (try walker.next ()) |*entry|
{
if ((entry.kind == .file) and ((
std.mem.indexOf (u8, entry.basename, "test") != null) or
toolbox.isCppHeader (entry.basename)))
try std.fs.deleteFileAbsolute (try std.fs.path.join (
builder.allocator, &.{ shaderc_path, entry.path, }));
}
try toolbox.clean (builder, &.{ "shaderc", }, &.{ ".inc", });
}
pub fn build (builder: *std.Build) !void
{
const target = builder.standardTargetOptions (.{});
const optimize = builder.standardOptimizeOption (.{});
const shaderc_path =
try builder.build_root.join (builder.allocator, &.{ "shaderc", });
const dependencies = try toolbox.Dependencies.init (builder, "shaderc.zig",
&.{ "shaderc", },
.{
.toolbox = .{
.name = "tiawl/toolbox",
.host = toolbox.Repository.Host.github,
.ref = toolbox.Repository.Reference.tag,
},
.glslang = .{
.name = "tiawl/glslang.zig",
.host = toolbox.Repository.Host.github,
.ref = toolbox.Repository.Reference.tag,
},
.spirv = .{
.name = "tiawl/spirv.zig",
.host = toolbox.Repository.Host.github,
.ref = toolbox.Repository.Reference.tag,
},
}, .{
.shaderc = .{
.name = "google/shaderc",
.host = toolbox.Repository.Host.github,
.ref = toolbox.Repository.Reference.tag,
},
});
if (builder.option (bool, "update", "Update binding") orelse false)
try update (builder, shaderc_path, &dependencies);
const lib = builder.addStaticLibrary (.{
.name = "shaderc",
.root_source_file = builder.addWriteFiles ().add ("empty.c", ""),
.target = target,
.optimize = optimize,
});
const flags = [_][] const u8 { "-DENABLE_HLSL", "-fno-sanitize=undefined", };
const glslang_dep = builder.dependency ("glslang", .{
.target = target,
.optimize = optimize,
});
const spirv_dep = builder.dependency ("spirv", .{
.target = target,
.optimize = optimize,
});
const glslang_compile_step = glslang_dep.artifact ("glslang");
const spirv_compile_step = spirv_dep.artifact ("spirv");
lib.linkLibrary (glslang_compile_step);
lib.installLibraryHeaders (glslang_compile_step);
lib.linkLibrary (spirv_compile_step);
lib.installLibraryHeaders (spirv_compile_step);
for ([_][] const u8 {
try std.fs.path.join (builder.allocator,
&.{ "shaderc", "libshaderc", "include", }),
try std.fs.path.join (builder.allocator,
&.{ "shaderc", "libshaderc_util", "include", }),
}) |include| toolbox.addInclude (lib, include);
const libshaderc_path = try std.fs.path.join (builder.allocator,
&.{ shaderc_path, "libshaderc", });
toolbox.addHeader (lib, try std.fs.path.join (builder.allocator,
&.{ libshaderc_path, "include", "shaderc", }), "shaderc", &.{ ".h", });
const libshaderc_util_path = try std.fs.path.join (builder.allocator,
&.{ shaderc_path, "libshaderc_util", });
toolbox.addHeader (lib, try std.fs.path.join (builder.allocator,
&.{ libshaderc_util_path, "include", "libshaderc_util", }),
"libshaderc_util", &.{ ".h", });
var dir: std.fs.Dir = undefined;
var walker: std.fs.Dir.Walker = undefined;
for ([_][] const u8 { libshaderc_path, libshaderc_util_path, }) |path|
{
dir = try std.fs.openDirAbsolute (path, .{ .iterate = true, });
defer dir.close ();
walker = try dir.walk (builder.allocator);
defer walker.deinit ();
while (try walker.next ()) |*entry|
{
switch (entry.kind)
{
.file => {
if (toolbox.isCppSource (entry.basename))
try toolbox.addSource (lib, path, entry.path, &flags);
},
else => {},
}
}
}
builder.installArtifact (lib);
}