#zig build wasm target

1 messages · Page 1 of 1 (latest)

tight totem
#

Hey, I updated my Zig and this code stopped compiling:

.target = .{
    .cpu_arch = .wasm32,
    .os_tag = .freestanding,
    .abi = .none
},

What's the new way of doing this :/

pine seal
#

gotta give some more info

#

can i see your code?

#

can i see the error?

tight totem
#

sure:

const std = @import("std");

pub fn build(b: *std.Build) !void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    
    // MARK: - Client ----------------------------------------------------------
    const client = b.addSharedLibrary(.{
        .name = "client",
        .root_source_file = .{ .path = "client/main.zig" },
        .target = .{
            .cpu_arch = .wasm32,
            .os_tag = .freestanding,
            .abi = .none
        },
        .optimize = .ReleaseSafe // Change for debugging!
    });
    client.rdynamic = true;
    client.strip = true;

error:

/Users/teampuzel/Projects/WebGame/build.zig:12:14: error: no field named 'cpu_arch' in struct 'Build.ResolvedTarget'
            .cpu_arch = .wasm32,
             ^~~~~~~~
#

The target field seems to be of some ResolvedTarget type instead of Target now

#

It's code from many months ago and Zig seems to have changed quite a bit

safe sentinel
#

try

b.resolveTargetQuery(.{
    .cpu_arch = .wasm32,
    .os_tag = .freestanding,
}),
tight totem
#

thanks, now it's complaining that there's no field named strip

pine seal
#

you dont want to be using addSharedLibrary anyways

#

you want to use addExecutable and do exe.entry = .disabled

tight totem
#

huh?

#

is that how wasm works now?

pine seal
#

mhm

tight totem
#

I'm pretty sure it didn't work with executables before

pine seal
#

well if you're seeing ResolvedTarget, that means youre in a pretty modern master branch build

#

the change that made wasm work that way happened quite a while ago

tight totem
#

well, the last time I compiled this project seems to have been in September, so it was a while ago :D

safe sentinel
#

strip is now in client.root_module but you can put it right in the addExecutable struct