Zig packaging guidelines
hello, I've just changed minisign from C to Zig since this is now supported by upstream (it was quite the journey though). I noticed we don't have any packaging guideline for Zig yet so I would like to propose adding one. 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. Never lose the plot, kpcyrd
On Sun, 15 Jun 2025 at 22:19, kpcyrd <kpcyrd@archlinux.org> wrote:
hello,
I've just changed minisign from C to Zig since this is now supported by upstream (it was quite the journey though). I noticed we don't have any packaging guideline for Zig yet so I would like to propose adding one.
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.
Never lose the plot, kpcyrd
Shouldn't we prefer ReleaseSafe or ReleaseSpeed? We generally don't use -Os CFLAGS, either.
On 25/06/15 10:18PM, kpcyrd wrote:
hello,
Hey kpcyrd!
I've just changed minisign from C to Zig since this is now supported by upstream (it was quite the journey though). I noticed we don't have any packaging guideline for Zig yet so I would like to propose adding one.
Thanks for starting this effort, I also have a zig based package (ly) and it would be good to coordinate those packaging efforts a bit and have guidelines for zig. Especially establishing a valid set of default flags or information like the fact that the same flags need to be passed for build & install step is something that should definitely be written down! :) Is there already a draft page on the wiki somewhere? Cheers, Chris
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
Hi, On 17/06/2025 03:38, Daurnimator wrote:
On 16/6/25 06:18, kpcyrd wrote:
The example based on my notes is quite straight-forward:
snip
} ```
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!
So glibc in general should be fine, but for the kernel version we should target our LTS version or what we specify as baseline in our glibc package?
On 17/6/25 16:21, Jelle van der Waa wrote:
On 17/06/2025 03:38, Daurnimator wrote:
- zig targets include a kernel version and glibc version; make sure you include them!
So glibc in general should be fine, but for the kernel version we should target our LTS version or what we specify as baseline in our glibc package?
To be cautious for upgrades but stay recent, I've been selecting the previously packaged linux-lts version. So e.g. currently we've got linux-lts 6.12 in core; the previous major release of linux-lts was 6.6. On the glibc side, I'd also recommend selecting the previously packaged version for compatibility. At the moment we package 2.41, and the previous packaged version was 2.40. So I would recommend at the current point in time, we specify a target of: `native-linux.6.6-gnu.2.40`. A couple of years ago I brought up if we should formalise this via some sort of exposed variable in makepkg; it might be worth bringing this up again? Also FYI zig can take a kernel version range. e.g. zig build -Dtarget=native-linux.4.4...6.6-gnu.2.39 I'm not suggesting that we set a maximum target version.
participants (5)
-
Daurnimator
-
gromit
-
Jan Alexander Steffens (heftig)
-
Jelle van der Waa
-
kpcyrd