Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f032509b12 | ||
|
2a10ffc55c | ||
|
de7b29c458 |
38
build.zig
38
build.zig
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user