Installation
Multiple methods for adding downloader.zig to your project.
Requirements
- Zig 0.15.0 or later
- Existing Zig project with
build.zig
Method 1: zig fetch (Recommended)
bash
zig fetch --save https://github.com/muhammad-fiaz/downloader.zig/archive/refs/tags/0.0.1.tar.gzThis command:
- Downloads the package
- Calculates the hash
- Updates your
build.zig.zon
Method 2: Manual Configuration
Step 1: Update build.zig.zon
zig
.{
.name = "my-project",
.version = "0.0.1",
.dependencies = .{
.downloader = .{
.url = "https://github.com/muhammad-fiaz/downloader.zig/archive/refs/tags/0.0.1.tar.gz",
.hash = "...",
},
},
.paths = .{ "src", "build.zig", "build.zig.zon" },
}Step 2: Get the Hash
bash
zig fetch --hash https://github.com/muhammad-fiaz/downloader.zig/archive/refs/tags/0.0.1.tar.gzStep 3: Update build.zig
zig
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const downloader = b.dependency("downloader", .{
.target = target,
.optimize = optimize,
});
const exe = b.addExecutable(.{
.name = "my-app",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("downloader", downloader.module("downloader"));
b.installArtifact(exe);
}Method 3: Git Submodule
bash
git submodule add https://github.com/muhammad-fiaz/downloader.zig.git libs/downloaderThen configure in build.zig:
zig
const downloader_mod = b.createModule(.{
.root_source_file = b.path("libs/downloader/src/downloader.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("downloader", downloader_mod);Verification
Create a test file:
zig
const std = @import("std");
const downloader = @import("downloader");
pub fn main() void {
std.debug.print("downloader.zig v{s}\n", .{downloader.getVersion()});
}Build and run:
bash
zig build runExpected output:
downloader.zig v0.0.1Troubleshooting
Hash Mismatch
If you get a hash mismatch error:
- Delete
.zig-cache - Run
zig fetch --save ...again
Module Not Found
Ensure your build.zig correctly calls addImport:
zig
exe.root_module.addImport("downloader", downloader.module("downloader"));Network Issues
For environments behind a proxy:
bash
export HTTP_PROXY=http://proxy:port
export HTTPS_PROXY=http://proxy:port
zig fetch --save ...Next Steps
- Configuration - Customize behavior
- API Reference - Full documentation