capy-ui / capy

💻Build one codebase and get native UI on Windows, Linux and Web
https://capy-ui.org
Mozilla Public License 2.0
1.69k stars 62 forks source link

build.zig.zon support #39

Closed ghost closed 1 year ago

ghost commented 1 year ago

If I'm not mistaken and my use of the undocumented zig 0.11 package manager is error free, capy needs changes for downstream build.zig.zon to work. Either that, or zig 0.11's experimental package manager isn't capable of pulling in capy yet.

build_capy.zig:18:20: error: no field named 'builder' in struct 'Build.CompileStep'
    const b = step.builder;

What's a working recipe to use capy with build.zig.zon?

No patch attached because I don't know what the fix is or if capy actually needs one.

zenith391 commented 1 year ago

Since the new package manager is still completely undocumented, I've refrained myself from using it for now until it's at least stable and/or documented. However, the const b = step.builder causes an error because of the fact that build steps now run in parallel, but I already fixed that in commit 324b483, maybe it will work if you git pull capy?

ghost commented 1 year ago

build.zig.zon was at 1d50ad47a33510c1d42ad90d3fdd20c8d53ca64c, will try 232584fe5210f41cb4d259fd2dfe3237956ff661 with 0.11.0-dev.2287+1de64dba2

ghost commented 1 year ago

Hit a different error this time. Looks like this experiment requires more digging. I'll wait for the package manager to improve before trying again.

truemedian commented 1 year ago

The only thing preventing capy from being used in the zig package manager is that the install function isn't exposed in build.zig. If install is changed to be pub in build.zig then it works fine with the package manager.

It's kinda against the new module+dependency system, but this works until the package manager gets better documentation. Just do the following:

capy build.zig

- const install = @import("build_capy.zig").install;
+ pub const install = @import("build_capy.zig").install;

build.zig.zon

.{
    ...
    .dependencies = .{
        .capy = .{
            .url = "https://github.com/capy-ui/capy/archive/232584fe5210f41cb4d259fd2dfe3237956ff661.tar.gz",
            .hash = "1220cc01af945ce8eda22be2f46a31a6b0795bd4f6041257bcecd3863267550b49d9",
        },
    },
}

build.zig

const capy = @import("root").dependencies.imports.capy;

pub fn build(b: *std.Build) void {
    ...
    capy.install(exe, .{}) catch @panic("capy install failed");
    ...
}

main.zig

const capy = @import("capy");
ghost commented 1 year ago

My failed experiment based on bits and pieces from the package manager tickets looks a lot more verbose:

    const capy_pkg = b.dependency("capy", .{
        .target = target,
        .optimize = optimize,
    });
    const capy_mod = capy_pkg.module("capy");
...
    exe.addModule("capy", capy_mod);

@truemedian thanks for the vastly shorter and most likely only correct usage example. I was actually wondering if it's supposed to be this verbose at the consumer side and questioned my hacked together script.

truemedian commented 1 year ago

b.dependency is the correct way to use the package manager, but it isn’t built to handle sdk-like packages that need to do their own configuration that depends on a CompileStep.

ghost commented 1 year ago

I see, in that case do you mind sharing a complete build.zig?

truemedian commented 1 year ago

The build.zig in https://github.com/capy-ui/capy/issues/39#issuecomment-1494786972 is what my PR enables, which is closer to how it works right now with zigmod.

ghost commented 1 year ago

Thanks. #40 with @truemedian's build.zig works