This repository was archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
168 lines (146 loc) · 5.26 KB
/
Copy pathbuild.zig
File metadata and controls
168 lines (146 loc) · 5.26 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
159
160
161
162
163
164
165
166
167
168
const std = @import("std");
const builtin = @import("builtin");
const rl = @import("src/Build_raylib.zig");
const raygui = @import("src/raygui/build.zig");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
var raylib = rl.getModule(b, "src/raylib-zig");
var raylib_math = rl.math.getModule(b, "src/raylib-zig");
//web exports are completely separate
if (target.getOsTag() == .emscripten) {
const cwd_path = b.build_root.path.?;
const emscripten_absolute_path = b.pathJoin(&[_][]const u8{
cwd_path,
".",
"src",
"emscripten",
"upstream",
"emscripten",
});
// Set the sysroot folder for emscripten
b.sysroot = emscripten_absolute_path;
setupEmscripten(b);
const exe_lib = rl.compileForEmscripten(
b,
"Scale",
"src/Scale.zig",
target,
optimize,
);
exe_lib.addModule("raylib", raylib);
exe_lib.addModule("raylib-math", raylib_math);
raygui.addTo(b, exe_lib, target, optimize);
const raylib_artifact = rl.getArtifact(b, target, optimize);
// Override raylib's default config.h with our custom one
const raylib_artifact_src_folder = raylib_artifact.step.owner.build_root.path.?;
const copy_raylib_config_header = b.addSystemCommand(&[_][]const u8{
"cp",
b.pathJoin(&[_][]const u8{
cwd_path,
"src",
"Includes",
"raylib_config.h",
}),
b.pathJoin(&[_][]const u8{
raylib_artifact_src_folder,
"src",
"config.h",
}),
});
raylib_artifact.step.dependOn(©_raylib_config_header.step);
// Note that raylib itself is not actually added to the exe_lib output file, so it also needs to be linked with emscripten.
exe_lib.linkLibrary(raylib_artifact);
const link_step = try rl.linkWithEmscripten(
b,
&[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact },
);
b.getInstallStep().dependOn(&link_step.step);
const run_step = try rl.emscriptenRunStep(b);
run_step.step.dependOn(&link_step.step);
const run_option = b.step("run", "Run Scale");
run_option.dependOn(&run_step.step);
try copyWASMRunStep(b, &link_step.step, cwd_path);
return;
}
const exe = b.addExecutable(.{ .name = "Scale", .root_source_file = .{ .path = "src/Scale.zig" }, .optimize = optimize, .target = target });
rl.link(b, exe, target, optimize);
exe.addModule("raylib", raylib);
exe.addModule("raylib-math", raylib_math);
raygui.addTo(b, exe, target, optimize);
const run_cmd = b.addRunArtifact(exe);
const run_step = b.step("run", "Run Scale");
run_step.dependOn(&run_cmd.step);
// // Add locales
// b.installDirectory(.{
// .source_dir = .{ .path = "./src/Locales" },
// .install_dir = .bin,
// .install_subdir = "Locales",
// });
b.installArtifact(exe);
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/Tests.zig" },
.target = target,
.optimize = optimize,
});
const run_unit_tests = b.addRunArtifact(unit_tests);
// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
}
pub fn setupEmscripten(b: *std.build) void {
std.debug.print("Install Emscripten\n", .{});
_ = b.exec(&[_][]const u8{
b.pathJoin(&[_][]const u8{ ".", "src", "emscripten", "emsdk" }),
"install",
"latest",
});
std.debug.print("Activate Emscripten\n", .{});
_ = b.exec(&[_][]const u8{
b.pathJoin(&[_][]const u8{ ".", "src", "emscripten", "emsdk" }),
"activate",
"latest",
});
}
pub fn copyWASMRunStep(b: *std.Build, dependsOn: *std.Build.Step, cwd_path: []const u8) !void {
const indexjs_step = b.addSystemCommand(&[_][]const u8{
"cp",
b.pathJoin(&[_][]const u8{
cwd_path,
"zig-out",
"htmlout",
"index.js",
}),
b.pathJoin(&[_][]const u8{
cwd_path,
"src",
"scale-website",
"static",
"emscripten.js",
}),
});
const indexwasm_step = b.addSystemCommand(&[_][]const u8{
"cp",
b.pathJoin(&[_][]const u8{
cwd_path,
"zig-out",
"htmlout",
"index.wasm",
}),
b.pathJoin(&[_][]const u8{
cwd_path,
"src",
"scale-website",
"static",
"scale.wasm",
}),
});
indexjs_step.step.dependOn(dependsOn);
indexwasm_step.step.dependOn(dependsOn);
b.getInstallStep().dependOn(&indexjs_step.step);
b.getInstallStep().dependOn(&indexwasm_step.step);
}