On 16/6/25 06:18, kpcyrd wrote:
The example based on my notes is quite straight-forward:

```
depends=(
   glibc
)
makedepends=(
   zig
)

build() {
   cd "${pkgname}-${pkgver}"
   zig build --verbose -Dcpu=baseline -Doptimize=ReleaseSmall
}

package() {
   cd "${pkgname}-${pkgver}"
   install -Dm755 -t "${pkgdir}/usr/bin" zig-out/bin/example
}
```

Common gotchas were:

- The `zig build` command is essentially fully silent if no interactive terminal is attached, `--verbose` helped but it's still very little info - Without `-Dcpu=baseline` the compiler is going to probe the build server cpu, which both causes problems with Reproducible Builds, but more importantly can also make the binary crash with `Illegal instruction` errors, since the default binaries aren't really distributable

Looking at the ncdu PKGBUILD shows there's some room for improvement:

```
build() {
   cd "${pkgname}-${pkgver}"

   DESTDIR="build" zig build \
     --summary all \
     --global-cache-dir ../zig-global-cache \
     --prefix /usr \
     --search-prefix /usr \
     --release=safe \
     -Dtarget=native-linux.6.1-gnu.2.38 \
     -Dcpu=baseline \
     -Dpie=true
}

check() {
   cd "${pkgname}-${pkgver}"

   zig build test \
     --summary all \
     --global-cache-dir ../zig-global-cache \
     --prefix /usr \
     --search-prefix /usr \
     --release=safe \
     -Dtarget=native-linux.6.1-gnu.2.38 \
     -Dcpu=baseline \
     -Dpie=true
}
```

More input very welcome, but I'm also fine with adding a very basic one by myself and whoever has something to add can just edit the wiki.

I've been the defacto zig package maintainer for a bit now.
Good packages to look at are ncdu, river, waylock.

Guidelines off the top of my head:
  - Indeed make sure you don't forget `-Dcpu=baseline`
- zig targets include a kernel version and glibc version; make sure you include them! - Leave the target architecture as `native` so that archlinuxarm can pick up the package automatically - Add build.zig.zon dependencies to the `sources` array so they get archived correctly; they also need to be added to `noextract`
    We should probably write a script to automate this.
  - Use prepare() to build a build-environment-local global package cache
  - Use `--system ../zig-global-cache/p` to then use that package cache
  - Consider `--summary all` to get some build output
- `package()` should usually be `cp -a build/* "$pkgdir` rather than trying to `install` files individually

Reply via email to