Add to build config.
2.1 Native
const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = options.optimize,
});
const exe = b.addExecutable(.{
.name = "app",
.root_module = exe_mod,
});
exe.root_module.addImport("sokol", dep_sokol.module("sokol"));
const zflecs = b.dependency("zflecs", .{});
exe.root_module.addImport("zflecs", zflecs.module("root"));
exe.linkLibrary(zflecs.artifact("flecs"));
const lib = b.addStaticLibrary(.{
.name = "app",
.target = target,
.optimize = options.optimize,
.root_source_file = b.path("src/main.zig"),
});
lib.root_module.addImport("sokol", dep_sokol.module("sokol"));
const zflecs = b.dependency("zflecs", .{});
lib.root_module.addImport("zflecs", zflecs.module("root"));
lib.linkLibrary(zflecs.artifact("flecs"));
// 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 = lib,
.target = target,
.optimize = options.optimize,
.emsdk = emsdk,
.use_webgl2 = options.backend != .wgpu,
.use_webgpu = options.backend == .wgpu,
.use_emmalloc = true,
.use_filesystem = false,
.release_use_closure = options.backend != .wgpu,
.shell_file_path = dep_sokol.path("src/sokol/web/shell.html"),
});
// attach Emscripten linker output to default install step
b.getInstallStep().dependOn(&link_step.step);
// ...and a special run step to start the web build output via 'emrun'
const run = sokol.emRunStep(b, .{ .name = "app", .emsdk = emsdk });
run.step.dependOn(&link_step.step);
b.step("run", "Run app").dependOn(&run.step);
** Duplicate of the main repository
Hi folks,
I am trying to confirm that I will be able to use zflecs and possibly other zig-gamedev libs in my project.
It seems I am able to compile it successfully for the native platforms, but getting an error building it for the web.
My steps:
Add
zflecsto zon file:zig fetch --save=zflecs git+https://github.com/zig-gamedev/zflecs.gitAdd to build config.
2.1 Native
2.2 Web
Add basic initialization to make sure the linking is ok:
Native build works just fine, but getting an error when building for the web
zig build -Dtarget=wasm32-emscripten