This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.zig
80 lines (67 loc) · 2.56 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
const std = @import("std");
pub const Package = struct {
module: *std.Build.Module,
pub fn link(pkg: Package, exe: *std.Build.CompileStep) void {
exe.addModule("zig-metal", pkg.module);
}
};
pub fn package(b: *std.Build) Package {
return .{
.module = b.createModule(
.{
.source_file = .{ .path = thisDir() ++ "/src/main.zig" },
.dependencies = &[_]std.build.ModuleDependency{
.{
.name = "zigtrait",
.module = zigTraitModule(b),
},
},
},
),
};
}
pub fn zigTraitModule(b: *std.Build) *std.Build.Module {
return b.createModule(.{ .source_file = .{ .path = thisDir() ++ "/libs/zigtrait/src/zigtrait.zig" } });
}
pub fn addExample(
b: *std.Build,
target: std.zig.CrossTarget,
optimize: std.builtin.OptimizeMode,
comptime name: []const u8,
comptime path: []const u8,
) void {
const exe = b.addExecutable(.{
.name = name,
.root_source_file = .{ .path = path ++ "/main.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(exe);
var pkg = package(b);
pkg.link(exe);
// exe.addModule("zigtrait", zigTraitModule(b));
exe.linkFramework("Foundation");
exe.linkFramework("AppKit");
exe.linkFramework("Metal");
exe.linkFramework("MetalKit");
const run_cmd = b.addRunArtifact(exe);
const run_step = b.step("run-" ++ name, "Run the sample '" ++ name ++ "'");
run_step.dependOn(&run_cmd.step);
}
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
addExample(b, target, optimize, "window", "examples/01-window");
addExample(b, target, optimize, "primitive", "examples/02-primitive");
addExample(b, target, optimize, "argbuffers", "examples/03-argbuffers");
addExample(b, target, optimize, "animation", "examples/04-animation");
addExample(b, target, optimize, "instancing", "examples/05-instancing");
addExample(b, target, optimize, "perspective", "examples/06-perspective");
addExample(b, target, optimize, "lighting", "examples/07-lighting");
addExample(b, target, optimize, "texturing", "examples/08-texturing");
addExample(b, target, optimize, "compute", "examples/09-compute");
addExample(b, target, optimize, "compute-to-render", "examples/10-compute_to_render");
}
inline fn thisDir() []const u8 {
return comptime std.fs.path.dirname(@src().file) orelse ".";
}