https://github.com/42lm/zig-package-manager-example
Zig ⚡️ - Package Manager Example
https://github.com/42lm/zig-package-manager-example
build-zig dependecy package-manager zig zig-fetch zig-zon ziglang zon
Last synced: 7 months ago
JSON representation
Zig ⚡️ - Package Manager Example
- Host: GitHub
- URL: https://github.com/42lm/zig-package-manager-example
- Owner: 42LM
- License: mit
- Created: 2025-01-18T15:16:07.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-03T23:47:49.000Z (over 1 year ago)
- Last Synced: 2025-02-04T00:18:54.753Z (over 1 year ago)
- Topics: build-zig, dependecy, package-manager, zig, zig-fetch, zig-zon, ziglang, zon
- Language: Zig
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://github.com/42LM/zig-package-manager-example/actions/workflows/ubuntu-latest.yml) [](https://github.com/42LM/zig-package-manager-example/actions/workflows/macos-latest.yml) [](https://github.com/42LM/zig-package-manager-example/actions/workflows/windows-latest.yml)
[](https://github.com/42LM/zig-package-manager-example/actions/workflows/v0.14.0.yml) [](https://github.com/42LM/zig-package-manager-example/actions/workflows/v0.15.0.yml)
# zig-package-manager-example
This is a small and simple example/demonstration of the zig package manager aka `zig.zon`.
It provides an example on how to provide a zig ligrary and how to use it in a different project.
> [!IMPORTANT]
> 🛟 Does **not work** on **zig versions below `< v0.14.0`**!
> [!TIP]
> If you are looking for minimal setup of a zig library please check out the [minimal](https://github.com/42LM/zig-package-manager-example/tree/minimal) branch.
## Using it
Create a new zig project:
```sh
mkdir zig-package-manager-example
cd zig-package-manager-example
zig init
```
In your zig project folder (where `build.zig` is located), run:
```sh
zig fetch --save "git+https://github.com/42LM/zig-package-manager-example"
```
> [!TIP]
> You can also fetch the lib/repo via tag/release. Check out the [v0.0.0 release](https://github.com/42LM/zig-package-manager-example/releases/tag/v0.0.0).
Then, in your `build.zig`'s `build` function, add the following before
`b.installArtifact(exe)`:
```zig
const hello = b.dependency("hello", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("hello", hello.module("hello"));
```
In your projects `main.zig` file import the hello module:
```zig
const std = @import("std");
const hello = @import("hello");
pub fn main() !void {
std.debug.print("{s}\n", .{hello.world()});
}
```
Run the project:
```sh
zig build run
```
> Does not do much, only prints out `no operations`
Run the tests:
```sh
zig build test
```
> Run the tests of the lib
## Troubleshoot
> [!WARNING]
> Handle with care: Delete the cache of zig:
> ```
> rm -rf ~/.cache/zig
> ```