-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
158 lines (138 loc) · 4.02 KB
/
build.zig
File metadata and controls
158 lines (138 loc) · 4.02 KB
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
152
153
154
155
156
157
158
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Create executable
const exe = b.addExecutable(.{
.name = "simple-2d-platformer",
.target = target,
.optimize = optimize,
});
const defaultFlags = .{
"-std=c99",
"-Wall",
"-Wextra",
};
const debugFlags = .{
"-g",
"-O0",
"-DDEBUG",
};
const releaseFlags = .{
"-O3",
"-DNDEBUG",
"-DRELEASE",
};
const flags = if (optimize == .Debug) defaultFlags ++ debugFlags else defaultFlags ++ releaseFlags;
// Add C files
exe.addCSourceFiles(.{
.files = &.{
"src/main.c",
"src/animation.c",
"src/enemy.c",
"src/fallable.c",
"src/game.c",
"src/jumpable.c",
"src/healthbar.c",
"src/moveable.c",
"src/platform.c",
"src/player.c",
"src/sprite.c",
"src/sound.c",
"src/stunnable.c",
"src/weapons.c",
},
.flags = &flags,
});
// Include src directory
exe.addIncludePath(b.path("src"));
// Link raylib
exe.linkSystemLibrary("raylib");
exe.linkLibC();
// Platform-specific libraries
switch (target.result.os.tag) {
.linux => {
exe.linkSystemLibrary("m");
exe.linkSystemLibrary("pthread");
exe.linkSystemLibrary("dl");
exe.linkSystemLibrary("rt");
},
.macos => {
exe.linkFramework("CoreVideo");
exe.linkFramework("IOKit");
exe.linkFramework("Cocoa");
exe.linkFramework("GLUT");
exe.linkFramework("OpenGL");
},
.windows => {
exe.linkSystemLibrary("winmm");
},
else => {},
}
// Install the executable
b.installArtifact(exe);
// Create run step
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the game");
run_step.dependOn(&run_cmd.step);
// Create test executable
const test_exe = b.addExecutable(.{
.name = "test_player_jump",
.target = target,
.optimize = optimize,
});
// Add test C files
test_exe.addCSourceFiles(.{
.files = &.{
"tests/test_player_jump.c",
"src/animation.c",
"src/fallable.c",
"src/jumpable.c",
"src/healthbar.c",
"src/moveable.c",
"src/platform.c",
"src/player.c",
"src/sprite.c",
"src/sound.c",
"src/stunnable.c",
"src/weapons.c",
},
.flags = &flags,
});
// Include src directory for tests
test_exe.addIncludePath(b.path("src"));
// Link raylib for tests
test_exe.linkSystemLibrary("raylib");
test_exe.linkLibC();
// Platform-specific libraries for tests
switch (target.result.os.tag) {
.linux => {
test_exe.linkSystemLibrary("m");
test_exe.linkSystemLibrary("pthread");
test_exe.linkSystemLibrary("dl");
test_exe.linkSystemLibrary("rt");
},
.macos => {
test_exe.linkFramework("CoreVideo");
test_exe.linkFramework("IOKit");
test_exe.linkFramework("Cocoa");
test_exe.linkFramework("GLUT");
test_exe.linkFramework("OpenGL");
},
.windows => {
test_exe.linkSystemLibrary("winmm");
},
else => {},
}
// Install the test executable
b.installArtifact(test_exe);
// Create test run step
const test_run_cmd = b.addRunArtifact(test_exe);
test_run_cmd.step.dependOn(b.getInstallStep());
const test_step = b.step("test", "Run jump mechanics tests");
test_step.dependOn(&test_run_cmd.step);
}