# introduce package id and redo hash format again · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/d6a88ed74db270c14c669ab334f3ab715cfd2b76)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: d6a88ed74db270c14c669ab334f3ab715cfd2b76

Requested commit: d6a88ed74db270c14c669ab334f3ab715cfd2b76

Commit: d6a88ed74db270c14c669ab334f3ab715cfd2b76

Tree: 6a82af3d767e00c4682f45ba49e8c8ef48be6a32

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
introduce package id and redo hash format again

Introduces the `id` field to `build.zig.zon`.

Together with name, this represents a globally unique package
identifier. This field should be initialized with a 16-bit random number
when the package is first created, and then *never change*. This allows
Zig to unambiguously detect when one package is an updated version of
another.

When forking a Zig project, this id should be regenerated with a new
random number if the upstream project is still maintained. Otherwise,
the fork is *hostile*, attempting to take control over the original
project's identity.

`0x0000` is invalid because it obviously means a random number wasn't
used.

`0xffff` is reserved to represent "naked" packages.

Tracking issue #14288

Additionally:

* Fix bad path in error messages regarding build.zig.zon file.
* Manifest validates that `name` and `version` field of build.zig.zon
  are maximum 32 bytes.
* Introduce error for root package to not switch to enum literal for
  name.
* Introduce error for root package to omit `id`.
* Update init template to generate `id`
* Update init template to populate `minimum_zig_version`.
* New package hash format changes:
  - name and version limited to 32 bytes via error rather than truncation
  - truncate sha256 to 192 bits rather than 40 bits
  - include the package id

This means that, given only the package hashes for a complete dependency
tree, it is possible to perform version selection and know the final
size on disk, without doing any fetching whatsoever. This prevents
wasted bandwidth since package versions not selected do not need to be
fetched.

```

## Parents

- [9763dd2901069f80dbdaae7c6b8004fbe1cf1b26](https://git.cafe/gitcafe/zig/commit/9763dd2901069f80dbdaae7c6b8004fbe1cf1b26?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/d6a88ed74db270c14c669ab334f3ab715cfd2b76?format=markdown)
