67.13. zls-0.16.0
The Zig language server
| Version | 0.16.0, release 1 |
| Shelf | devtools — Debuggers, tracers, profilers, analysers, linters, language servers and developer utilities |
| Phase | 40_lang (Languages), 21 of 186 in build order |
| Licence | MIT |
| Homepage | https://github.com/zigtools/zls |
| Build time | 5.1 SBU |
| Installed size | 3.9 MiB in 2 files |
| Recipe | ports/core/devtools/zls/kpkgbuild |
About
ZLS is the Zig language server. It parses Zig with the parser in Zig’s standard library (std.zig.Ast), and a tagged ZLS release names the Zig release of the same number as both its minimum build and its minimum run-time version (minimum_zig_version in build.zig.zon, minimum_runtime_zig_version in build.zig). It is built with the installed zig, so the recipe’s version and the zig port’s move together: a ZLS parsing with another release’s syntax tree reports syntax errors in correct code.
Why it is in KDOS
The comment above it in script/phases/40_lang/packages.d/devtools.txt:
zls and zig are pinned to each other on purpose — zls parses Zig with the compiler's own AST, so a mismatch reports syntax errors on correct code.
Sources
zls-0.16.0.tar.gz(453.1 KiB)
sha256e7c5936f5b3a057ce851be0876e4e259b5c4d02f9aae038cd24a5d6b586b029f
upstream: https://github.com/zigtools/zls/archive/refs/tags/0.16.0.tar.gz
archive copy: sources-1/devtools--zls-0.16.0.tar.gzzlsdep-known_folders.tar.gz(11.6 KiB)
sha256969a38a43bfde75ad4a72b0ed639953788d4383f20a235fd7a7ec3a11f664896
upstream: https://github.com/ziglibs/known-folders/archive/d6d03830968cca6b7b9f24fd97ee348346a6905d.tar.gz
archive copy: sources-1/devtools--zlsdep-known_folders.tar.gzzlsdep-diffz.tar.gz(20.7 KiB)
sha256df7454517b746d3782ec662da5c32d44578b02479b23ce59f066259591f2f343
upstream: https://github.com/ziglibs/diffz/archive/b39fe07e7fdbcf56e43ba2890b9f484f16969f90.tar.gz
archive copy: sources-1/devtools--zlsdep-diffz.tar.gzzlsdep-lsp_kit.tar.gz(116.8 KiB)
sha25611e34ecf050fc888dff416d6bbe4664183b85770bd86eb6ed0d3c632c1bb193b
upstream: https://github.com/zigtools/lsp-kit/archive/b886a2b0d5cee85ecbcc3089b863f7517cc9ff7f.tar.gz
archive copy: sources-1/devtools--zlsdep-lsp_kit.tar.gzzlsdep-tracy.tar.gz(4.4 MiB)
sha256d4efc50ebcb0bfcfdbba148995aeb75044c0d80f5d91223aebfaa8fa9e563d2b
upstream: https://github.com/wolfpld/tracy/archive/refs/tags/v0.13.1.tar.gz
archive copy: sources-1/devtools--zlsdep-tracy.tar.gz
Dependencies
Depends on: zig.
Required by: no port names it.
Patches
build.sh applies these; kpkg applies nothing by itself.
pie.patch— Addsexe.pie = pie;to thezlsexecutable inbuild.zig, so-Dpie=trueproduces a position-independent executable rather than only position-independent code. The builtzlsis a static PIE.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/40_lang/phase.env && kpkg install zls'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/devtools/zls.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/devtools/zls
echo 'e7c5936f5b3a057ce851be0876e4e259b5c4d02f9aae038cd24a5d6b586b029f zls-0.16.0.tar.gz' | sha256sum -c -
echo '969a38a43bfde75ad4a72b0ed639953788d4383f20a235fd7a7ec3a11f664896 zlsdep-known_folders.tar.gz' | sha256sum -c -
echo 'df7454517b746d3782ec662da5c32d44578b02479b23ce59f066259591f2f343 zlsdep-diffz.tar.gz' | sha256sum -c -
echo '11e34ecf050fc888dff416d6bbe4664183b85770bd86eb6ed0d3c632c1bb193b zlsdep-lsp_kit.tar.gz' | sha256sum -c -
echo 'd4efc50ebcb0bfcfdbba148995aeb75044c0d80f5d91223aebfaa8fa9e563d2b zlsdep-tracy.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/zls
SRC=$SRC_ROOT/zls-0.16.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf zls-0.16.0.tar.gz -C "$SRC" --strip-components=1
tar --no-same-permissions --warning=no-unknown-keyword -xf zlsdep-known_folders.tar.gz -C "$SRC_ROOT"
tar --no-same-permissions --warning=no-unknown-keyword -xf zlsdep-diffz.tar.gz -C "$SRC_ROOT"
tar --no-same-permissions --warning=no-unknown-keyword -xf zlsdep-lsp_kit.tar.gz -C "$SRC_ROOT"
tar --no-same-permissions --warning=no-unknown-keyword -xf zlsdep-tracy.tar.gz -C "$SRC_ROOT"
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
export ZIG_GLOBAL_CACHE_DIR="$SRC_ROOT/zig-cache"
mkdir -p "$ZIG_GLOBAL_CACHE_DIR/p"
unpack_zig_dep() {
mkdir -p "$ZIG_GLOBAL_CACHE_DIR/p/$2"
tar xf "$PORT_SRC/zlsdep-$1.tar.gz" --strip-components=1 \
-C "$ZIG_GLOBAL_CACHE_DIR/p/$2"
}
unpack_zig_dep known_folders known_folders-0.0.0-Fy-PJk3KAACzUg2us_0JvQQmod1ZA8jBt7MuoKCihq88
unpack_zig_dep diffz diffz-0.0.1-G2tlISzNAQCldmOcINavGmF1zdt20NFPXeM8d07jp_68
unpack_zig_dep lsp_kit lsp_kit-0.1.0-bi_PL3IyDACfp1xdTnkiOHEok2YpPCCCJHuuOcNzjl1D
unpack_zig_dep tracy N-V-__8AAOncKwEm1F9c5LrT7HMNmRMYX8-fAoqpc6YyTu9X
patch -p1 -i "$PORT_SRC/pie.patch"
zig build --system "$ZIG_GLOBAL_CACHE_DIR/p" -Doptimize=ReleaseSafe -Dcpu=baseline -Dpie=true --prefix "$PKG/usr"
strip --strip-debug "$PKG/usr/bin/zls"
The switches, and why each is set:
ZIG_GLOBAL_CACHE_DIR— Zig’s global cache, which holds compiled artifacts and, underp/, unpacked packages named by their hash. It is set to a directory under$SRC_ROOT, inside the build.--system "$ZIG_GLOBAL_CACHE_DIR/p"— Take every package from that directory and fetch none.build.zig.zonnames four dependencies by URL and hash (known-folders, diffz, lsp-kit and tracy), and in system mode zig reports “remote package fetching disabled” instead of reaching for the network.-Doptimize=ReleaseSafe,-Dcpu=baseline— An optimised build with the safety checks kept, and code for the baseline x86-64 rather than the build machine’s processor, which every zig port names; see zig.-Dpie=true— ZLS’s own option for a position-independent build. Upstream applies it only to the modules’picsetting; withpie.patchit makes the executable a PIE as well, like every other program in the tree (see The release flags).--strip-debug— On the installedzls: remove the DWARF zig writes into the executable and keep its symbol table.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/zls, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf zls-0.16.0-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/zls, and runs the triggers its paths call for.
Contents
Installed programs: zls.
Installed directories: /usr/share/licenses/zls.
Notes
The four dependencies are extra source = lines in the recipe, zlsdep-<name>.tar.gz, and unpack_zig_dep unpacks each into $ZIG_GLOBAL_CACHE_DIR/p/<hash>. The hashes in build.sh are copied from build.zig.zon; a version bump that changes a dependency changes both the recipe’s URL and its hash in build.sh, or zig does not find the package.