Compare commits

..

3 Commits
master ... wasm

Author SHA1 Message Date
nothke
f032509b12 Added note about running wasm but doesnt build 2024-07-04 17:08:10 +02:00
nothke
2a10ffc55c Now switches on target set to wasm 2024-07-04 16:57:48 +02:00
nothke
de7b29c458 Added a build for web option 2024-07-04 16:56:17 +02:00
2 changed files with 63 additions and 29 deletions

View File

@ -1,4 +1,7 @@
const std = @import("std"); const std = @import("std");
const sokol = @import("sokol");
const title = "sok";
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
@ -6,10 +9,11 @@ pub fn build(b: *std.Build) void {
const dep_sokol = b.dependency("sokol", .{ .target = target, .optimize = optimize }); const dep_sokol = b.dependency("sokol", .{ .target = target, .optimize = optimize });
// Exe if (!target.result.isWasm()) {
// Native exe
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "sok", .name = title,
.root_source_file = b.path("src/main.zig"), .root_source_file = b.path("src/main.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
@ -46,8 +50,36 @@ pub fn build(b: *std.Build) void {
run_cmd.addArgs(args); run_cmd.addArgs(args);
} }
const run_step = b.step("run", "Run the app"); const run_step = b.step("run", "Run" ++ title ++ " as native app");
run_step.dependOn(&run_cmd.step); run_step.dependOn(&run_cmd.step);
} else {
// Web
const wasmLib = b.addStaticLibrary(.{
.name = title,
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/pacman.zig"),
});
wasmLib.root_module.addImport("sokol", dep_sokol.module("sokol"));
// create a build step which invokes the Emscripten linker
const emsdk = dep_sokol.builder.dependency("emsdk", .{});
const link_step = try sokol.emLinkStep(b, .{
.lib_main = wasmLib,
.target = target,
.optimize = optimize,
.emsdk = emsdk,
.use_webgl2 = true,
.use_emmalloc = true,
.use_filesystem = false,
.shell_file_path = dep_sokol.path("src/sokol/web/shell.html").getPath(b),
});
// ...and a special run step to start the web build output via 'emrun'
const run = sokol.emRunStep(b, .{ .name = "sok", .emsdk = emsdk });
run.step.dependOn(&link_step.step);
b.step("run", "Run " ++ title ++ " as wasm").dependOn(&run.step);
}
// Tests // Tests

View File

@ -10,6 +10,8 @@ The goal of this project is not fixed, and is just to try out some sokol feature
To build, you need to have zig master (you can use [zvm](https://www.zvm.app/) to help you with this). Then just `zig build run` and that should be it! To build, you need to have zig master (you can use [zvm](https://www.zvm.app/) to help you with this). Then just `zig build run` and that should be it!
To build for wasm, use `zig build -Dtarget=wasm32-emscripten run`
Note that if you change shaders, you have to recompile them manually - run compile_shaders.bat. Note that if you change shaders, you have to recompile them manually - run compile_shaders.bat.
### Live error checking ### Live error checking