#zig build, where is my .wasm file?

1 messages · Page 1 of 1 (latest)

short ore
#

fn create_wasm(b: *Build, mode: std.builtin.OptimizeMode, name: []const u8, source: []const u8) !void {
    const target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
    const exe = b.addExecutable(.{
        .name = name,
        .optimize = mode,
        .target = target,
        .root_source_file = b.path(source),
    });

    exe.rdynamic = true;

    b.dest_dir = "bin/";

    // modules
    {
        const moduleDawn = b.addModule("dawn",  .{ .root_source_file = b.path("src/dawn/dawn.zig") });
        const moduleRT = b.addModule("rt",      .{ .root_source_file = b.path("src/rt/rt.zig"),  });

        moduleDawn.addImport("rt", moduleRT);

        exe.root_module.addImport("rt", moduleRT);
        exe.root_module.addImport("dawn", moduleDawn);

        moduleDawn.addIncludePath( .{ .cwd_relative = "/usr/include" });
        moduleDawn.addLibraryPath( .{ .cwd_relative = "/usr/lib" });
    }

    // c depndencies
    exe.addIncludePath(b.path("src/c/nuklear/"));
    exe.addIncludePath(b.path("src/c/stb/"));
    exe.addCSourceFile(.{ .file = b.path("src/c/nuklear/nuklear.c"), .flags = &.{ "-std=c11", "-Wl,--allow-multiple-definition" } });

    const compile_step = b.step(name, b.fmt("Build {s}", .{name}));
    compile_step.dependOn(&exe.step);

    b.installArtifact(exe);
    b.getInstallStep().dependOn(&exe.step);
}

it should go to bin/, why it doesn't work?

$ find . | grep ".wasm"
./.zig-cache/o/bcde2c35f5e134430c659b912db9936e/game-wasm.wasm.o
./.zig-cache/o/bcde2c35f5e134430c659b912db9936e/game-wasm.wasm
./.zig-cache/o/1c86ded577468bd945cdd2a8681075a0/game-wasm.wasm.o
./.zig-cache/o/1c86ded577468bd945cdd2a8681075a0/game-wasm.wasm
./src/dawn/gfx/wasm.zig
./src/main_wasm.zig
#

zig build, where is my .wasm file?

short ore
#

oh i am stupid it is zig build install

deft scaffold
#

seems like zig build should install it. if not, did you try swapping the args to dependOn() ?

short ore
#

i gave it a name, so i kept doing zig build game-wasm

#

do you by chance know how to make it so it always call the install? and how to give the wasm a specific name?

deft scaffold
#

run_cmd.step.dependOn(b.getInstallStep()); is how it looks when you run zig init. i think you should make your game-wasm step depend on the install step like this.

#

i think you have it the other way around above

#

the wasm name should follow whatever name you pass

#

and end up in zig-out/bin/

short ore
#

i don't want the wasm to be the step name tho, ideally i want game.exe and game.wasm