aduros / wasm4

Build retro games using WebAssembly for a fantasy console.
https://wasm4.org
ISC License
1.16k stars 171 forks source link

Zig template doesn't build #685

Open squeaktoy opened 9 months ago

squeaktoy commented 9 months ago

after doing w4 new --zig test and trying zig build -Doptimize=ReleaseSmall I get this:

/home/user/my_software/test4/build.zig:8:14: error: no field named 'cpu_arch' in struct 'Build.ResolvedTarget'
            .cpu_arch = .wasm32,
             ^~~~~~~~
/usr/lib64/zig/9999/lib/std/Build.zig:2242:28: note: struct declared here
pub const ResolvedTarget = struct {
                           ^~~~~~
referenced by:
    runBuild__anon_8077: /usr/lib64/zig/9999/lib/std/Build.zig:1851:37
    steps__anon_7900: /usr/lib64/zig/9999/lib/build_runner.zig:1033:29
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

And even with Zig 0.11.0 it fails:

/home/user/my_software/test4/build.zig:14:9: error: no field named 'entry' in struct 'Build.Step.Compile'
    exe.entry = .disabled;
        ^~~~~
/usr/lib64/zig/0.11.0/lib/std/Build/Step/Compile.zig:1:1: note: struct declared here
const builtin = @import("builtin");
^~~~~
referenced by:
    runBuild__anon_7138: /usr/lib64/zig/0.11.0/lib/std/Build.zig:1639:37
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Removing the exe.entry = .disabled; line makes matters even worse:

zig build-exe cart ReleaseSmall wasm32-freestanding: error: the following command failed with 1 compilation errors:
/usr/lib64/zig/0.11.0/bin/zig build-exe --stack 14752 /home/user/my_software/test4/src/main.zig -OReleaseSmall --cache-dir /home/user/my_software/test4/zig-cache --global-cache-dir /home/user/.cache/zig --name cart --import-memory --initial-memory=65536 --max-memory=65536 --export=start --export=update -target wasm32-freestanding -mcpu generic --listen=-
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install cart transitive failure
   └─ zig build-exe cart ReleaseSmall wasm32-freestanding 1 errors
/usr/lib64/zig/0.11.0/lib/std/start.zig:559:45: error: root struct of file 'main' has no member named 'main'
    switch (@typeInfo(@typeInfo(@TypeOf(root.main)).Fn.return_type.?)) {
                                        ~~~~^~~~~
/usr/lib64/zig/0.11.0/lib/std/start.zig:201:9: note: called from here
    _ = @call(.always_inline, callMain, .{});
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bhansconnect commented 9 months ago

If you use 0.11.0, this version of the template should work: https://github.com/aduros/wasm4/tree/4f840a0cb73b16a57ca348569e48ca2bc91b439f/cli/assets/templates/zig

Not sure why someone upgrade to 0.12.0 which is a moving target with no stability guarantees.

mrBen commented 9 months ago

Not sure why someone upgrade to 0.12.0 which is a moving target with no stability guarantees.

Because that's what Zig recommends? From the Getting Started:

Zig releases tend to be far apart and eventually become stale given the current speed of development, […] we encourage you to upgrade to a nightly build.

bhansconnect commented 9 months ago

Fair enough, just means regular PRs. But I also get the staleness problem. Just a harder problem for libraries.

This is a good read on a middle ground: https://devlog.hexops.com/2024/announcing-nominated-zig/

phcarvalho commented 1 month ago

I was having some problems to build on version 0.13.0 and was able to execute it by changing .root_source_file value from .{ .path = "src/main.zig" } to .{ .cwd_relative = "src/main.zig" } on the build.zig file:

peterhellberg commented 2 weeks ago

@phcarvalho Note that you should do .root_source_file = b.path("src/main.zig"), with current versions of Zig.

So something along these lines:

    const exe = b.addExecutable(.{
        .name = "cart",
        .root_source_file = b.path("src/main.zig"),
        .target = b.resolveTargetQuery(.{
            .cpu_arch = .wasm32,
            .os_tag = .freestanding,
        }),
        .optimize = .ReleaseSmall,
    });