-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.zig
61 lines (51 loc) · 1.77 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
const std = @import ("std");
const cimgui = @import ("cimgui");
const Platform = cimgui.Platform;
const Renderer = cimgui.Renderer;
fn platform (dir_name: [] const u8) !Platform
{
return if (std.mem.indexOf (u8, dir_name, "_glfw") != null) .GLFW
else error.UnknownPlatformBackend;
}
fn renderer (dir_name: [] const u8) !Renderer
{
return if (std.mem.indexOf (u8, dir_name, "_vulkan") != null) .Vulkan
else error.UnknownRendererBackend;
}
pub fn build (builder: *std.Build) !void
{
const target = builder.standardTargetOptions (.{});
const optimize = .Debug;
const pattern = builder.option ([] const u8, "pattern",
"Simple & stupid indexOf pattern matching to select examples") orelse "";
var examples_dir =
try builder.build_root.handle.openDir (".", .{ .iterate = true, });
defer examples_dir.close ();
var exe: *std.Build.Step.Compile = undefined;
var cimgui_dep: *std.Build.Dependency = undefined;
var it = examples_dir.iterate ();
while (try it.next ()) |*entry|
{
if (entry.kind == .directory and
std.mem.startsWith (u8, entry.name, "example_") and
std.mem.indexOf (u8, entry.name, pattern) != null)
{
exe = builder.addExecutable (.{
.name = entry.name,
.root_source_file = .{ .cwd_relative = try builder.build_root.join (
builder.allocator, &.{ entry.name, "main.zig", }), },
.target = target,
.optimize = optimize,
});
cimgui_dep = builder.dependency ("cimgui", .{
.target = target,
.optimize = optimize,
.platform = try platform (entry.name),
.renderer = try renderer (entry.name),
});
exe.linkLibrary (cimgui_dep.artifact ("cimgui"));
//exe.module.addImport ("")
builder.installArtifact (exe);
}
}
}