Update project setup to use raylib-zig's emcc instead of copying it

This commit is contained in:
Not-Nik 2024-05-03 22:36:54 +02:00
parent 07a11a1c28
commit a85122eabe
No known key found for this signature in database
GPG Key ID: E95F679E3CDD9784

View File

@ -10,7 +10,7 @@ mkdir "$PROJECT_NAME" && cd "$PROJECT_NAME" || exit
touch build.zig touch build.zig
echo "Generating project files..." echo "Generating project files..."
echo 'const std = @import("std"); echo 'const std = @import("std");
const emcc = @import("emcc.zig"); const rlz = @import("raylib-zig");
pub fn build(b: *std.Build) !void { pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
@ -27,17 +27,17 @@ pub fn build(b: *std.Build) !void {
//web exports are completely separate //web exports are completely separate
if (target.query.os_tag == .emscripten) { if (target.query.os_tag == .emscripten) {
const exe_lib = emcc.compileForEmscripten(b, "'$PROJECT_NAME'", "src/main.zig", target, optimize); const exe_lib = rlz.emcc.compileForEmscripten(b, "'$PROJECT_NAME'", "src/main.zig", target, optimize);
exe_lib.linkLibrary(raylib_artifact); exe_lib.linkLibrary(raylib_artifact);
exe_lib.root_module.addImport("raylib", raylib); exe_lib.root_module.addImport("raylib", raylib);
exe_lib.root_module.addImport("raylib-math", raylib_math); exe_lib.root_module.addImport("raylib-math", raylib_math);
// Note that raylib itself is not actually added to the exe_lib output file, so it also needs to be linked with emscripten. // Note that raylib itself is not actually added to the exe_lib output file, so it also needs to be linked with emscripten.
const link_step = try emcc.linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact }); const link_step = try rlz.emcc.linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact });
b.getInstallStep().dependOn(&link_step.step); b.getInstallStep().dependOn(&link_step.step);
const run_step = try emcc.emscriptenRunStep(b); const run_step = try rlz.emcc.emscriptenRunStep(b);
run_step.step.dependOn(&link_step.step); run_step.step.dependOn(&link_step.step);
const run_option = b.step("run", "Run '$PROJECT_NAME'"); const run_option = b.step("run", "Run '$PROJECT_NAME'");
run_option.dependOn(&run_step.step); run_option.dependOn(&run_step.step);
@ -73,7 +73,5 @@ echo '.{
echo "Please manually update the dependency hash!" echo "Please manually update the dependency hash!"
cp ../emcc.zig .
mkdir src mkdir src
cp ../examples/core/basic_window.zig src/main.zig cp ../examples/core/basic_window.zig src/main.zig