-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
339 lines (316 loc) · 10.2 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
const std = @import("std");
const Build = std.Build;
pub fn build(b: *Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const VVVVVV_dep = b.dependency("VVVVVV", .{});
const sdl_dep = switch (target.result.os.tag) {
.linux => b.dependency("sdl", .{
.target = target,
.optimize = optimize,
// doesn't support SDL_RENDERER_TARGETTEXTURE
.render_driver_ogl_es = false,
// doesn't support SDL_RENDERER_ACCELERATED
.render_driver_software = false,
}),
else => b.dependency("sdl", .{
.target = target,
.optimize = optimize,
// TODO: disable render_driver_software here as well if/when SDL supports it
//.render_driver_software = false,
}),
};
const physfs_dep = b.dependency("physfs", .{});
const zipcmdline_dep = b.dependency("zipcmdline", .{});
const makeandplay_dep = b.dependency("makeandplay", .{});
const exe = b.addExecutable(.{
.name = "VVVVVV",
.target = target,
.optimize = optimize,
});
exe.addIncludePath(physfs_dep.path("src"));
exe.addIncludePath(physfs_dep.path("extras"));
exe.addCSourceFiles(.{
.root = VVVVVV_dep.path("."),
.files = &src,
});
exe.addCSourceFiles(.{
.root = physfs_dep.path("."),
.files = &physfs_src,
});
// TODO: if steam enabled add SteamNetwork.c
// TODO: if GOG enabled add GOGNetwork.c
exe.linkLibCpp();
exe.linkLibrary(addPhysfs(b, target, optimize));
{
const sdl = sdl_dep.artifact("SDL2");
exe.linkLibrary(sdl);
const header_tree = sdl.installed_headers_include_tree orelse @panic("?");
exe.addIncludePath(header_tree.getDirectory().path(b, "SDL2"));
exe.linkLibrary(addFAudio(b, target, optimize, sdl));
}
exe.linkLibrary(addTinyXml2(b, target, optimize));
exe.linkLibrary(addCHashmap(b, target, optimize));
exe.linkLibrary(addSheenBidi(b, target, optimize));
exe.linkLibrary(addLodepng(b, target, optimize));
b.installArtifact(exe);
{
const zip_exe = zipcmdline_dep.artifact("zip");
const run_zip = b.addRunArtifact(zip_exe);
const out_zip_file = run_zip.addOutputFileArg("data.zip");
run_zip.addDirectoryArg(makeandplay_dep.path("."));
b.getInstallStep().dependOn(
&b.addInstallBinFile(out_zip_file, "data.zip").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 app");
run_step.dependOn(&run_cmd.step);
}
fn addPhysfs(
b: *Build,
target: Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
) *Build.Step.Compile {
const dep = b.dependency("physfs", .{});
const root = dep.path(".");
const lib = b.addStaticLibrary(.{
.name = "physfs",
.target = target,
.optimize = optimize,
});
var files = std.ArrayList([]const u8).init(b.allocator);
files.appendSlice(&.{
"src/physfs.c",
"src/physfs_archiver_dir.c",
"src/physfs_archiver_unpacked.c",
"src/physfs_archiver_zip.c",
"src/physfs_byteorder.c",
"src/physfs_unicode.c",
"src/physfs_platform_posix.c",
"src/physfs_platform_unix.c",
"src/physfs_platform_windows.c",
"src/physfs_platform_haiku.cpp",
"src/physfs_platform_android.c",
}) catch @panic("OOM");
if (target.result.isDarwin()) {
files.append("src/physfs_platform_apple.m") catch @panic("OOM");
}
lib.addCSourceFiles(.{
.root = root,
.files = files.toOwnedSlice() catch @panic("OOM"),
.flags = &.{
"-DPHYSFS_SUPPORTS_DEFAULT=0",
"-DPHYSFS_SUPPORTS_ZIP=1",
},
});
lib.linkLibCpp();
return lib;
}
fn addTinyXml2(
b: *Build,
target: Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
) *Build.Step.Compile {
const dep = b.dependency("tinyxml2", .{});
const root = dep.path(".");
const lib = b.addStaticLibrary(.{
.name = "tinyxml2",
.target = target,
.optimize = optimize,
});
lib.addCSourceFiles(.{
.root = root,
.files = &.{
"tinyxml2.cpp",
},
});
lib.installHeader(
root.path(b, "tinyxml2.h"),
"tinyxml2.h",
);
lib.linkLibCpp();
return lib;
}
fn addCHashmap(
b: *Build,
target: Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
) *Build.Step.Compile {
const dep = b.dependency("c_hashmap", .{});
const root = dep.path(".");
const lib = b.addStaticLibrary(.{
.name = "c-hashmap",
.target = target,
.optimize = optimize,
});
lib.addCSourceFiles(.{
.root = root,
.files = &.{
"map.c",
},
});
lib.installHeader(
root.path(b, "map.h"),
"c-hashmap/map.h",
);
lib.linkLibCpp();
return lib;
}
fn addSheenBidi(
b: *Build,
target: Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
) *Build.Step.Compile {
const dep = b.dependency("sheen_bidi", .{});
const root = dep.path(".");
const lib = b.addStaticLibrary(.{
.name = "sheenbidi",
.target = target,
.optimize = optimize,
});
const headers_path = root.path(b, "Headers");
lib.addIncludePath(headers_path);
lib.addCSourceFiles(.{
.root = root,
.files = &.{
"Source/SheenBidi.c",
},
.flags = &.{ "-DSB_CONFIG_UNITY" },
});
lib.installHeadersDirectory(headers_path, ".", .{});
lib.linkLibCpp();
return lib;
}
fn addFAudio(
b: *Build,
target: Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
sdl: *Build.Step.Compile,
) *Build.Step.Compile {
const dep = b.dependency("faudio", .{});
const root = dep.path(".");
const lib = b.addStaticLibrary(.{
.name = "faudio",
.target = target,
.optimize = optimize,
});
const include_path = root.path(b, "include");
lib.addIncludePath(include_path);
const header_tree = sdl.installed_headers_include_tree orelse @panic("?");
lib.addIncludePath(header_tree.getDirectory().path(b, "SDL2"));
lib.addCSourceFiles(.{
.root = root,
.files = &.{
"src/FAudio.c",
"src/FAudio_internal.c",
"src/FAudio_internal_simd.c",
"src/FAudio_operationset.c",
"src/FAudio_platform_sdl2.c",
},
});
lib.installHeadersDirectory(include_path, ".", .{});
lib.installHeadersDirectory(root.path(b, "src"), ".", .{});
lib.linkLibCpp();
lib.linkLibrary(sdl);
return lib;
}
fn addLodepng(
b: *Build,
target: Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
) *Build.Step.Compile {
const dep = b.dependency("lodepng", .{});
const root = dep.path(".");
const lib = b.addStaticLibrary(.{
.name = "lodepng",
.target = target,
.optimize = optimize,
});
lib.addIncludePath(root);
// The Lore:
// we generate a ".c" file and use it to include lodepng.cpp so that
// it gets compiled as a C file and doesn't mangle the symbols. We don't
// want the symbols mangled becuase VVVVVV decided it was better to copy
// the 3 function prototypes it's using from lodepng and wrap them in
// extern "C" rather than just using their header file.
const generate_files = b.addWriteFiles();
const c_wrapper = generate_files.add(
"lodepng.c",
"#include <lodepng.cpp>",
);
// workaround bug in Zig build system (TODO: create a minimal reproduction and file a bug)
lib.step.dependOn(&generate_files.step);
lib.addCSourceFiles(.{
.root = c_wrapper.dirname(),
.files = &.{
"lodepng.c",
},
.flags = &.{
"-DLODEPNG_NO_COMPILE_ALLOCATORS",
"-DLODEPNG_NO_COMPILE_DISK",
},
});
lib.linkLibCpp();
return lib;
}
const src = [_][]const u8 {
"desktop_version/src/BinaryBlob.cpp",
"desktop_version/src/BlockV.cpp",
"desktop_version/src/ButtonGlyphs.cpp",
"desktop_version/src/CustomLevels.cpp",
"desktop_version/src/CWrappers.cpp",
"desktop_version/src/Editor.cpp",
"desktop_version/src/Ent.cpp",
"desktop_version/src/Entity.cpp",
"desktop_version/src/FileSystemUtils.cpp",
"desktop_version/src/Finalclass.cpp",
"desktop_version/src/Font.cpp",
"desktop_version/src/FontBidi.cpp",
"desktop_version/src/Game.cpp",
"desktop_version/src/Graphics.cpp",
"desktop_version/src/GraphicsResources.cpp",
"desktop_version/src/GraphicsUtil.cpp",
"desktop_version/src/Input.cpp",
"desktop_version/src/KeyPoll.cpp",
"desktop_version/src/Labclass.cpp",
"desktop_version/src/LevelDebugger.cpp",
"desktop_version/src/Localization.cpp",
"desktop_version/src/LocalizationMaint.cpp",
"desktop_version/src/LocalizationStorage.cpp",
"desktop_version/src/Logic.cpp",
"desktop_version/src/Map.cpp",
"desktop_version/src/Music.cpp",
"desktop_version/src/Otherlevel.cpp",
"desktop_version/src/preloader.cpp",
"desktop_version/src/Render.cpp",
"desktop_version/src/RenderFixed.cpp",
"desktop_version/src/RoomnameTranslator.cpp",
"desktop_version/src/Screen.cpp",
"desktop_version/src/Script.cpp",
"desktop_version/src/Scripts.cpp",
"desktop_version/src/Spacestation2.cpp",
"desktop_version/src/TerminalScripts.cpp",
"desktop_version/src/Textbox.cpp",
"desktop_version/src/Tower.cpp",
"desktop_version/src/UtilityClass.cpp",
"desktop_version/src/WarpClass.cpp",
"desktop_version/src/XMLUtils.cpp",
"desktop_version/src/main.cpp",
"desktop_version/src/DeferCallbacks.c",
"desktop_version/src/GlitchrunnerMode.c",
"desktop_version/src/Network.c",
"desktop_version/src/Textbook.c",
"desktop_version/src/ThirdPartyDeps.c",
"desktop_version/src/UTF8.c",
"desktop_version/src/VFormat.c",
"desktop_version/src/Vlogging.c",
"desktop_version/src/Xoshiro.c",
};
const physfs_src = [_][]const u8 {
"extras/physfsrwops.c",
};