Metadata-Version: 2.5
Name: zig-recipe
Version: 0.2.0
Summary: Generate package manager recipes from Zig projects
Keywords: zig,packaging,gentoo,ebuild,recipe
Author-email: Eric Joldasov <bratishkaerik@landless-city.net>
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-Expression: Apache-2.0
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: System :: Software Distribution
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Zig
Classifier: Typing :: Typed
License-File: LICENSE
Requires-Dist: jinja2>=3.1.6
Requires-Dist: natizon>=0.4.7
Requires-Dist: platformdirs>=4.3.0
Requires-Dist: rich>=14.0.0
Requires-Dist: semver>=3.0.4
Requires-Dist: typer>=0.15.0
Requires-Dist: yarl>=1.18.0
Project-URL: Homepage, https://github.com/BratishkaErik/zig-recipe
Project-URL: Issues, https://github.com/BratishkaErik/zig-recipe/issues
Project-URL: Repository, https://github.com/BratishkaErik/zig-recipe
Import-Name: zig_recipe

# zig-recipe

`zig-recipe` helps package maintainers turn Zig projects into distribution packages.

When you package a Zig project for an offline build environment, you usually need
the same set of facts regardless of the distribution:

- every transitive dependency URL and package hash,
- which dependencies are actually used in your build configuration,
- which system libraries and build-time tools are needed,
- which build options (`-D`) and system integrations (`-fsys`) are available.

`zig-recipe` collects all of this automatically. You can look at the result right
in your terminal as a summary table, or export it as JSON if you want to feed it
into your own scripts.

It can also generate a ready-to-edit package recipe. Gentoo ebuilds are
supported out of the box, and if you package for another distribution or prefer
a different layout, you can render the same data through your own Jinja2
template.

## Requirements

- **Zig 0.17+**
- **Python 3.12+**

If you are packaging an older Zig 0.14–0.16 project, see the legacy [zig-ebuilder](https://github.com/BratishkaErik/zig-ebuilder).

### Running with `uv`

The easiest way to run `zig-recipe` without installing it globally is with
[uv](https://docs.astral.sh/uv/):

```console
$ uvx zig-recipe gentoo ./river
```

To install it as a persistent CLI tool:

```console
$ uv tool install zig-recipe
```

## Usage

All commands accept an optional path to a Zig project directory (or `build.zig`).
If you omit the path, `zig-recipe` uses the current directory.

If a project's dependencies or system libraries depend on non-default build
options, you can forward them to `zig build` after `--`:

```console
$ zig-recipe inspect ./project -- -Dbackend=wayland
```

### Inspecting a project

To see what a project needs without writing a recipe file, run `inspect`:

```console
$ zig-recipe inspect ./project
```

This prints a summary of packages, build options, system libraries, system
integrations, and top-level build steps.

> [!TIP]
> Add `--format json` if you want machine-readable output for your own scripts.

### Gentoo ebuilds

To generate a Gentoo ebuild for the project:

```console
$ zig-recipe gentoo ./project
```

By default, this writes `<name>-<version>.ebuild` in the current directory
(pass `-o -` to print to stdout).

Alongside `ZBS_DEPENDENCIES` and `src_configure()`, `zig-recipe` adds comments
listing detected system libraries, build options, and external tools to help
you finish the ebuild by hand. You can control how detailed those comments are
with `--comments`:

- `full` (default) — descriptions for every build option, system library, and build tool.
- `compact` — one-line hints for options and libraries.
- `none` — no helper comments at all.

Many Zig projects also declare lazy dependencies that your build never uses
(for example, packages for other operating systems or vendored libraries). You
can choose how those appear in `ZBS_DEPENDENCIES` with `--unused-deps`:

- `comment` (default with `full` and `compact`) — commented out so Portage does not download them.
- `drop` (default with `--comments none`) — omitted from `ZBS_DEPENDENCIES`.
- `keep` — kept uncommented in `ZBS_DEPENDENCIES`.

When updating an existing ebuild to a new release, you often only need the new
dependency list. Passing `--deps-only` prints just the `ZBS_DEPENDENCIES` array
to stdout:

```console
$ zig-recipe gentoo ./ghostty --deps-only
```

See [docs/gentoo.md](docs/gentoo.md) for multi-pass `IUSE`/`src_configure()`
mapping and a full walkthrough.

### Custom templates

If you are targeting another distribution or want your own file layout, pass a
Jinja2 template to `render`:

```console
$ zig-recipe render ./my-template.j2 ./project -o recipe.out
```

Your template can use all of the collected project, dependency, and build
information. See [docs/templates.md](docs/templates.md) for a walkthrough and
example.

### Configuration and multi-pass analysis

By default, `zig-recipe` traces both the default build step and the `test` step
(when present) to separate test-only dependencies and libraries automatically.

To analyze optional features across multiple build configurations (see
[docs/multi-pass.md](docs/multi-pass.md)) or store reusable project metadata
and renderer settings, pass a [project config](docs/project-config.md) with
`--config`:

```console
$ zig-recipe gentoo ./river --config river.toml
```

Machine paths and personal defaults (such as `--zig`, `--cache-dir`, or your
preferred Gentoo comment style) can live in a [user config](docs/user-config.md)
at `~/.config/zig-recipe/config.toml` on Linux.

## Example

Running `zig-recipe gentoo ./river --comments compact -o -` on `river 0.5.2`:

```bash
# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# Generated by zig-recipe 0.1.0

EAPI=8

declare -g -r -A ZBS_DEPENDENCIES=(
	[pixman-0.3.0-LClMnz2VAAAs7QSCGwLimV5VUYx0JFnX5xWU6HwtMuDX.tar.gz]='https://codeberg.org/ifreund/zig-pixman/archive/v0.3.0.tar.gz'
	[wayland-0.7.0-lQa1kuP8AQD5dW7_o-VKLVD_QbqXe7Zob78r2su7Pyex.tar.gz]='https://codeberg.org/ifreund/zig-wayland/archive/v0.7.0.tar.gz'
	[wlroots-0.20.3-jmOlcsh0BACce9rpfvzUI4V3AalGg9GE0QQkvRFoHo1c.tar.gz]='https://codeberg.org/ifreund/zig-wlroots/archive/v0.20.3.tar.gz'
	[xkbcommon-0.5.0-VDqIe8y3AgDU-cGL02xZplwABH3WbpTimrrgbgTgD_3g.tar.gz]='https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.5.0.tar.gz'

	# Not used in any analyzed pass:
	# [pixman-0.4.0-LClMn_eWAAAa2zACATDpPwjuI5fWlO5cBp_F_M33hnNZ.tar.gz]='https://codeberg.org/ifreund/zig-pixman/archive/v0.4.0.tar.gz'
)

# C/C++ sources detected; verify if LLVM backend is required
ZIG_NEEDS_LLVM=1
ZIG_SLOT="0.17"
inherit zig

DESCRIPTION="TODO"
HOMEPAGE="TODO"
SRC_URI="
	# TODO: add project source URL
	${ZBS_DEPENDENCIES_SRC_URI}
"

LICENSE="TODO"
SLOT="0"
KEYWORDS="~amd64"

# Detected system libraries: libevdev, libinput, pixman-1, wayland-server, wlroots-0.20, xkbcommon

src_configure() {
	local my_zbs_args=(
		# -Dstrip=[bool]
		# -Dpie=[bool]
		# -Dllvm=[bool]
		# -Dman-pages=[bool]
		# -Dxwayland=[bool]
		# -Dversion-string=[string]
	)

	zig_src_configure
}
```

> [!NOTE]
> `build.zig.zon` does not have standard fields for license, homepage, or short
> description yet (see [ziglang/zig#14342](https://github.com/ziglang/zig/issues/14342)),
> so those are left as `TODO` placeholders by default. The unofficial `summary`
> field ([ziglang/zig#23816](https://github.com/ziglang/zig/issues/23816)) is
> picked up automatically when present, and you can also supply these fields in
> a `--config` file (see [docs/project-config.md](docs/project-config.md)).

## Further reading

- [How `zig-recipe` Works](docs/how-it-works.md)
- [Multi-Pass Analysis](docs/multi-pass.md)
- [Project Configuration](docs/project-config.md)
- [User Configuration](docs/user-config.md)
- [Gentoo Ebuilds](docs/gentoo.md)
- [Custom Jinja2 Templates](docs/templates.md)

## License

`zig-recipe` is licensed under the [Apache License 2.0](LICENSE).
Generated recipe files are not covered by this license — you may license them
however you want.

