Hello,
I’m in the throes of learning Zig (but really loving it!) and the build system, and I’m currently struggling with getting a wasm build completed of a simple sokol-zig test project.
I’m working out of my own zig init
’d project directory, and I added sokol-zig with zig fetch
. Everything is fine if I build natively, but trying to build for wasm results in this error:
$ zig build -Dtarget=wasm32-emscripten -Doptimize=ReleaseSmall
install
└─ install sokoltest
└─ zig build-exe sokoltest ReleaseSmall wasm32-emscripten failure
error: error: unable to find or provide libc for target 'wasm32-emscripten-musl'
I know it’s calling down into the sokol-zig build.zig because if I set the target to wasm32-freestanding
instead I get the following error:
zig build -Dtarget=wasm32-freestanding
error: Please build with 'zig build -Dtarget=wasm32-emscripten
thread 1116791 panic: unhandled error
/Users/zach/.cache/zig/p/12200f54d3d37b99ecde3987c1fdc744d87b40595cc32e8943db82635498f14c0db0/build.zig:177:13: 0x10484c5af in buildLibSokol (build)
return error.Wasm32EmscriptenExpected;
^
[snip]
It also ran through the process of installing the Emscripten tools, a step which is also defined in the sokol-zig build.zig file.
If I clone sokol-zig separately and run zig build -Dtarget=wasm32-emscripten
, it builds all the sokol wasm examples just fine.
It seems to me that what I need for my project to build ('wasm32-emscripten-musl
?) is available on the system, but the build is unable to find it.
Here is the sokol-zig build.zig file: sokol-zig/build.zig at master · floooh/sokol-zig · GitHub
Here is mine:
const std = @import("std");
const Build = std.Build;
const OptimizeMode = std.builtin.OptimizeMode;
pub fn build(b: *Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const dep_sokol = b.dependency("sokol", .{
.target = target,
.optimize = optimize,
});
const sokoltest = b.addExecutable(.{
.name = "sokoltest",
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/main.zig"),
});
sokoltest.root_module.addImport("sokol", dep_sokol.module("sokol"));
b.installArtifact(sokoltest);
const run = b.addRunArtifact(sokoltest);
b.step("run", "Run sokoltest").dependOn(&run.step);
}
Could someone with experience around this type of issue kindly provide some guidance? I apologize in advance if this is an obvious question, but I can’t seem to find an answer so I figured I would ask here! I’m happy to provide any additional information if necessary.
Thanks!