| 1 | # build.zig.zon Documentation |
| 2 | |
| 3 | This is the manifest file for build.zig scripts. It is named build.zig.zon in |
| 4 | order to make it clear that it is metadata specifically pertaining to |
| 5 | build.zig. |
| 6 | |
| 7 | - **build root** - the directory that contains `build.zig` |
| 8 | |
| 9 | ## Top-Level Fields |
| 10 | |
| 11 | ### `name` |
| 12 | |
| 13 | Enum literal. Required. |
| 14 | |
| 15 | This is the default name used by packages depending on this one. For example, |
| 16 | when a user runs `zig fetch --save <url>`, this field is used as the key in the |
| 17 | `dependencies` table. Although the user can choose a different name, most users |
| 18 | will stick with this provided value. |
| 19 | |
| 20 | It is redundant to include "zig" in this name because it is already within the |
| 21 | Zig package namespace. |
| 22 | |
| 23 | Must be a valid bare Zig identifier (don't `@` me), limited to 32 bytes. |
| 24 | |
| 25 | Together with `fingerprint`, this represents a globally unique package identifier. |
| 26 | |
| 27 | ### `fingerprint` |
| 28 | |
| 29 | Together with `name`, this represents a globally unique package identifier. This |
| 30 | field is auto-initialized by the toolchain when the package is first created, |
| 31 | and then *never changes*. This allows Zig to unambiguously detect when one |
| 32 | package is an updated version of another. |
| 33 | |
| 34 | When forking a Zig project, this fingerprint should be regenerated if the upstream |
| 35 | project is still maintained. Otherwise, the fork is *hostile*, attempting to |
| 36 | take control over the original project's identity. The fingerprint can be regenerated |
| 37 | by deleting the field and running `zig build`. |
| 38 | |
| 39 | This 64-bit integer is the combination of a 32-bit id component and a 32-bit |
| 40 | checksum. |
| 41 | |
| 42 | The id component within the fingerprint has these restrictions: |
| 43 | |
| 44 | `0x00000000` is reserved for legacy packages. |
| 45 | |
| 46 | `0xffffffff` is reserved to represent "naked" packages. |
| 47 | |
| 48 | The checksum is computed from `name` and serves to protect Zig users from |
| 49 | accidental id collisions. |
| 50 | |
| 51 | ### `version` |
| 52 | |
| 53 | String. Required. |
| 54 | |
| 55 | [semver](https://semver.org/) |
| 56 | |
| 57 | Limited to 32 bytes. |
| 58 | |
| 59 | ### `minimum_zig_version` |
| 60 | |
| 61 | String. Optional. |
| 62 | |
| 63 | [semver](https://semver.org/) |
| 64 | |
| 65 | This is currently advisory only; the compiler does not yet do anything |
| 66 | with this version. |
| 67 | |
| 68 | ### `dependencies` |
| 69 | |
| 70 | Struct. |
| 71 | |
| 72 | Each dependency must either provide a `url` and `hash`, or a `path`. |
| 73 | |
| 74 | #### `url` |
| 75 | |
| 76 | String. |
| 77 | |
| 78 | When updating this field to a new URL, be sure to delete the corresponding |
| 79 | `hash`, otherwise you are communicating that you expect to find the old hash at |
| 80 | the new URL. If the contents of a URL change this will result in a hash mismatch |
| 81 | which will prevent zig from using it. |
| 82 | |
| 83 | #### `hash` |
| 84 | |
| 85 | String. |
| 86 | |
| 87 | [multihash](https://multiformats.io/multihash/) |
| 88 | |
| 89 | This is computed from the file contents of the directory of files that is |
| 90 | obtained after fetching `url` and applying the inclusion rules given by |
| 91 | `paths`. |
| 92 | |
| 93 | This field is the source of truth; packages do not come from a `url`; they |
| 94 | come from a `hash`. `url` is just one of many possible mirrors for how to |
| 95 | obtain a package matching this `hash`. |
| 96 | |
| 97 | #### `path` |
| 98 | |
| 99 | String. |
| 100 | |
| 101 | When this is provided, the package is found in a directory relative to the |
| 102 | build root. In this case the package's hash is irrelevant and therefore not |
| 103 | computed. This field and `url` are mutually exclusive. |
| 104 | |
| 105 | #### `lazy` |
| 106 | |
| 107 | Boolean. |
| 108 | |
| 109 | When this is set to `true`, a package is declared to be lazily fetched. This |
| 110 | makes the dependency only get fetched if it is actually used. |
| 111 | |
| 112 | ### `paths` |
| 113 | |
| 114 | List. Required. |
| 115 | |
| 116 | Specifies the set of files and directories that are included in this package. |
| 117 | Paths are relative to the build root. Use the empty string (`""`) to refer to |
| 118 | the build root itself. |
| 119 | |
| 120 | Only files included in the package are used to compute a package's `hash`. |