|
10 | 10 |
|
11 | 11 | [](https://github.com/softprops/zig-jwt/actions/workflows/ci.yml)   [](https://ziglang.org/documentation/0.13.0/) |
12 | 12 |
|
| 13 | +## 📼 installing |
| 14 | + |
| 15 | +Create a new exec project with `zig init`. Copy an example from the examples directory into your into `src/main.zig` |
| 16 | + |
| 17 | +Create a `build.zig.zon` file to declare a dependency |
| 18 | + |
| 19 | +> .zon short for "zig object notation" files are essentially zig structs. `build.zig.zon` is zigs native package manager convention for where to declare dependencies |
| 20 | +
|
| 21 | +Starting in zig 0.12.0, you can use and should prefer |
| 22 | + |
| 23 | +```sh |
| 24 | +zig fetch --save https://github.com/softprops/zig-jwt/archive/refs/tags/v0.1.0.tar.gz |
| 25 | +``` |
| 26 | + |
| 27 | +otherwise, to manually add it, do so as follows |
| 28 | + |
| 29 | +```diff |
| 30 | +.{ |
| 31 | + .name = "my-app", |
| 32 | + .version = "0.1.0", |
| 33 | + .dependencies = .{ |
| 34 | ++ // 👇 declare dep properties |
| 35 | ++ .jwt = .{ |
| 36 | ++ // 👇 uri to download |
| 37 | ++ .url = "https://github.com/softprops/zig-jwt/archive/refs/tags/v0.1.0.tar.gz", |
| 38 | ++ // 👇 hash verification |
| 39 | ++ .hash = "...", |
| 40 | ++ }, |
| 41 | + }, |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +> the hash below may vary. you can also depend any tag with `https://github.com/softprops/zig-jwt/archive/refs/tags/v{version}.tar.gz` or current main with `https://github.com/softprops/zig-jwt/archive/refs/heads/main/main.tar.gz`. to resolve a hash omit it and let zig tell you the expected value. |
| 46 | +
|
| 47 | +Add the following in your `build.zig` file |
| 48 | + |
| 49 | +```diff |
| 50 | +const std = @import("std"); |
| 51 | + |
| 52 | +pub fn build(b: *std.Build) void { |
| 53 | + const target = b.standardTargetOptions(.{}); |
| 54 | + |
| 55 | + const optimize = b.standardOptimizeOption(.{}); |
| 56 | + // 👇 de-reference dep from build.zig.zon |
| 57 | ++ const jwt = b.dependency("jwt", .{ |
| 58 | ++ .target = target, |
| 59 | ++ .optimize = optimize, |
| 60 | ++ }).module("jwt"); |
| 61 | + var exe = b.addExecutable(.{ |
| 62 | + .name = "your-exe", |
| 63 | + .root_source_file = .{ .path = "src/main.zig" }, |
| 64 | + .target = target, |
| 65 | + .optimize = optimize, |
| 66 | + }); |
| 67 | + // 👇 add the module to executable |
| 68 | ++ exe.root_mode.addImport("jwt", jwt); |
| 69 | + |
| 70 | + b.installArtifact(exe); |
| 71 | +} |
13 | 72 |
|
14 | 73 | ## examples |
15 | 74 |
|
|
0 commit comments