Emscripten SDK integration for Zig projects.
| .gitignore | Initial import. | |
| build.zig | Fix issue. | |
| build.zig.zon | Update fingerprint. | |
| LICENSE-APACHE | Initial import. | |
| LICENSE-MIT | Initial import. | |
| README.md | Add basic README. | |
EMSDKZ
EMSDKZ is a build library for Zig to support Emscripten builds. It allows for common usage, such as building executables, linking ports, and configuring header file locations.
Getting Started
On the command line:
zig fetch --save=emsdkz git+https://codeberg.org/scriblz/emsdkz
In build.zig
constemsdkz=@import("emsdkz");constEmSdk=emsdkz.EmSdk;pubfnbuild(b:*std.Build)void{constmaybe_emsdk=switch(target.result.os.tag){.emscripten=>EmSdk.create(b,emsdkz_dep,.{}),else=>null,};constexe_mod=b.createModule(...);switch(target.result.os.tag){.emscripten=>{constexe=b.addLibrary(.{.name="example",.root_module=exe_mod,});if(maybe_emsdk)|emsdk|{constlink_step=emsdk.addLinkStep(.{.main=exe,.target=target,.optimize=optimize,.ports=&.{"emdawnwebgpu","contrib.glfw3",// other required ports},// path to the shell file used to run the project.shell_file_path=b.path("shell.html"),});construn=emsdk.addRunStep(.{.name="example",// optional browser param to override which browser to run with.browser="chrome",});run.step.dependOn(&link_step.step);if(optimize==.Debug){// install src files for debugging in browserconstinstall_src_dir=b.addInstallDirectory(.{.source_dir=b.path("src"),.install_dir=.{.custom="web"},.install_subdir="src",});run.step.dependOn(&install_src_dir.step);}b.step("example","Run example").dependOn(&run.step);}},else=>{// do normal build things},}}Building Ports
pubfnbuild(b:*std.Build)void{...if(maybe_emsdk)|emsdk|{constbuild_dawn_port_step=emsdk.addBuildPort(.{.port_name="emdawnwebgpu",});constwebgpu_include_path=emsdk.portPath("emdawnwebgpu",&.{"emdawnwebgpu_pkg","webgpu","include"});my_module.addSystemIncludePath(webgpu_include_path);}}