karlseguin / http.zig

An HTTP/1.1 server for zig
MIT License
454 stars 31 forks source link

using zig --fetch #48

Closed steve-ketcham closed 1 month ago

steve-ketcham commented 1 month ago

How would I use zig --fetch to incorporate this library? I am new and find the the build.zig portion confusing.

Thanks!

karlseguin commented 1 month ago

Ya, I also struggled with it when I started (and sometimes still do!)

You start with your build.zig.zon:

.{
  .name = "my-app",
  .paths = .{""},
  .version = "0.0.0",
  .dependencies = .{
    .httpz = .{
      .url = "https://github.com/karlseguin/http.zig/archive/406fb00f8c43fe9b2da0f32f428675755c67d054.tar.gz",
      .hash = "12209e87663712928c6ae1c690e65df15a796e970e5d18f5e4e05f0eb10404883d23"
    },
  },
}

That's the latest commit for the library. And the hash you can get from

zig fetch https://github.com/karlseguin/http.zig/archive/406fb00f8c43fe9b2da0f32f428675755c67d054.tar.gz

Then in your build.zig, at some point you should be creating an executable, something like:

const exe = b.addExecutable(.{
    .name = "my-app",
    .root_source_file = b.path("src/main.zig"),
    .target = target,
    .optimize = optimize,
});

You would add:

exe.root_module.addImport("httpz", b.dependency("httpz", .{}).module("httpz"));

I think this is still up to date (if it isn't, let me know what doesn't work): https://www.openmymind.net/learning_zig/coding_in_zig/#build

steve-ketcham commented 1 month ago

Perfect. It worked the first time through. Thanks!