Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Zig template doesn't build #685

Open
squeaktoy opened this issue Jan 7, 2024 · 5 comments
Open

Zig template doesn't build #685

squeaktoy opened this issue Jan 7, 2024 · 5 comments

Comments

@squeaktoy
Copy link

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
Copy link
Contributor

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
Copy link
Contributor

mrBen commented Jan 17, 2024

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
Copy link
Contributor

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
Copy link
Contributor

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:

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

@peterhellberg
Copy link
Contributor

@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,
    });

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants