-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
82 lines (63 loc) · 2.63 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
const std = @import("std"); // Standard library - For the builder
const rlz = @import("raylib-zig"); // Raylib Zig - Zig bindings for Raylib
// Settings
const PROJECT_NAME = "Zong";
// Builder
pub fn build(b: *std.Build) !void {
// Allow the person running 'zig build' to choose target system and optimization mode
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Dependencies
const raylibDep = b.dependency("raylib-zig", .{
.target = target,
.optimize = optimize,
.linux_display_backend = rlz.LinuxDisplayBackend.Wayland,
});
// Modules
const raylib = raylibDep.module("raylib");
const raygui = raylibDep.module("raygui");
// Artifacts
const raylibArtifact = raylibDep.artifact("raylib");
// Web exports
if(target.query.os_tag == .emscripten) {
// Compile program for Emscripten
const exeLib = try rlz.emcc.compileForEmscripten(b, PROJECT_NAME, "src/main.zig", target, optimize);
// Link libraries
exeLib.linkLibrary(raylibArtifact);
// Add modules that can be imported in our program
exeLib.root_module.addImport("raylib", raylib);
exeLib.root_module.addImport("raygui", raygui);
// Raylib itself isn't actually added to the "exeLib" output file so it also needs to be linked with Emscripten
const linkStep = try rlz.emcc.linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exeLib, raylibArtifact });
// Allows your program to access files like "resources/my-image.png"
linkStep.addArg("--embed-file");
linkStep.addArg("resources/");
b.getInstallStep().dependOn(&linkStep.step);
// Run step
const runStep = try rlz.emcc.emscriptenRunStep(b);
runStep.step.dependOn(&linkStep.step);
const runOption = b.step("run", "Run " ++ PROJECT_NAME);
runOption.dependOn(&runStep.step);
return;
}
// Native application/executable
const exe = b.addExecutable(.{
.name = PROJECT_NAME,
.root_source_file = b.path("src/main.zig"),
.optimize = optimize,
.target = target
});
// Set include directory
exe.addIncludePath(b.path("./include/"));
// Link libraries
exe.linkLibrary(raylibArtifact);
// Add modules that can be imported in our program
exe.root_module.addImport("raylib", raylib);
exe.root_module.addImport("raygui", raygui);
// Run step
const runCmd = b.addRunArtifact(exe);
const runStep = b.step("run", "Run learningRaylib");
runStep.dependOn(&runCmd.step);
// Install program
b.installArtifact(exe);
}