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.6k stars 60 forks source link

Need an example on how to use Capy as a package. #50

Closed malespiaut closed 1 year ago

malespiaut commented 1 year ago

Hello,

I understood that the concept of packages isn't clearly defined in Zig, at least in the latest nigthly build.

Yet, I think it would help to have an example on how to use Capy as a package for a new Zig project.

Best regards.

Damjan94 commented 1 year ago

I was struggling with this recently too. It's quite simple once you know what to do. First, as pointed out to me, capy has a template that works with zigmod package manager.

If you want it to work with build.zig.zon, add capy as a dependency like so (try to build, it'll tell you the expected hash, add it after the .url field.

.{
    .version = "0.0.0",
    .name = "test",
    .dependencies = .{
        .capy = .{
            .url = "https://github.com/capy-ui/capy/archive/refs/heads/master.tar.gz",
        }   
    },
}

and in your build.zig do

const capy_install = @import("capy").install;
    ...
    _ = try capy_install(exe, .{});
    b.installArtifact(exe);
malespiaut commented 1 year ago

Thank you for your answer. However Zig build asks for a .hash field in the .zon file, and I don't understand yet if it's possible to skip it.

Damjan94 commented 1 year ago

it will print the hash it expects. just paste it below the .url, so it becomes

.{
    .version = "0.0.0",
    .name = "test",
    .dependencies = .{
        .capy = .{
            .url = "https://github.com/capy-ui/capy/archive/refs/heads/master.tar.gz",
            .hash = "paste the hash that zig tells you it's expecting",
        }   
    },
}

you should hang around at ziggit.dev Andrew explained it briefly here (read the paragraph starting with "Suggested workflow ...").

zenith391 commented 1 year ago

https://github.com/capy-ui/zig-template has been updated to use the Zig package manager. So this issue is now closed.