AtlatestRepositorycore-channel

core-channel / tree / src / core / packagesdatastructures.sgl

1;;; Generic data-structure libraries.
2;;;
3;;; tllist is a header-only typed linked list. It is in this channel because
4;;; fcft and foot both `dependency('tllist')`, and foot's fallback for it is a
5;;; `[wrap-git]` subproject pointing at a live git URL -- which cannot resolve
6;;; inside a build sandbox, so a real package is not optional.
7(define-library (core packages datastructures)
8 (import (sigil core)
9 (core build-environments)
10 (sigil env package)
11 (sigil build external))
12 (export tllist)
13 (begin
14 ;; TLLIST IS HEADER-ONLY AND IS STILL DECLARED AS A `dependencies:` ENTRY
15 ;; BY ITS CONSUMERS, WHICH PUTS A BUILD-TIME-ONLY LIBRARY IN THEIR RUNTIME
16 ;; CLOSURE. That is not sloppiness; the channel has no other category for
17 ;; it, and the reason is worth knowing before someone "fixes" it.
18 ;;
19 ;; `build-inputs:` contributes the input's `bin/` to PATH and nothing else
20 ;; -- no `-I`, no `-L`, no `PKG_CONFIG_PATH`. It can additionally carry a
21 ;; package's own `search-paths:` exports, so a header-only library CAN
22 ;; reach a build as a build input by exporting `CPATH`.
23 ;;
24 ;; What it cannot do is be found by PKG-CONFIG. `PKG_CONFIG_PATH` is
25 ;; composed by the builder from DEPENDENCIES only, and it is builder-owned,
26 ;; so a package may not export it -- that is refused by name. fcft and
27 ;; foot both locate this library with `dependency('tllist')`, which is a
28 ;; pkg-config lookup, so it has to be a dependency.
29 ;;
30 ;; So: THERE IS NO "BUILD-TIME LIBRARY" CATEGORY HERE. A package that is
31 ;; discovered through pkg-config is a runtime dependency by construction,
32 ;; whether or not anything of it survives into the binary. For a
33 ;; header-only library nothing does.
35 ;; INSTALLED BY HAND RATHER THAN BY MESON, DELIBERATELY.
36 ;;
37 ;; tllist is one header and a `.pc` file. Its meson.build does exactly
38 ;; two things when it is not a subproject: `install_headers('tllist.h')`
39 ;; and `pkg.generate(...)`. Running a full meson configure to copy one
40 ;; header would put meson, samurai and python on the critical path of a
41 ;; package that needs none of them -- and this package was written before
42 ;; meson had been proven in this channel at all, which is the actual
43 ;; reason: it removes a dependency from the ordering, not just from the
44 ;; build.
45 ;;
46 ;; The `.pc` is hand-written to match what meson's pkgconfig module would
47 ;; have emitted. NOTE THE ABSENCE OF `${prefix}`-STYLE VARIABLES: a
48 ;; pkg-config file would normally define `prefix=` and refer to it, but
49 ;; `${...}` inside a run-phase argument is intercepted by SIGIL's
50 ;; interpolation, not by the shell or by pkg-config, and any name that is
51 ;; not `out` or a declared input is an error at evaluation time. Absolute
52 ;; paths are what the rest of this channel bakes anyway.
53 (define tllist
54 (package
55 name: "tllist"
56 version: "1.1.0"
57 source: (external-source
58 location: "https://codeberg.org/dnkl/tllist/releases/download/1.1.0/tllist-1.1.0.tar.gz"
59 sha256: "a1f0ce0dc4fcb4ce59c37202a1d914c853a8bd2d7c5d57d623b15a8dd9778767")
60 buildenv: core-buildenv
61 phases: (list
62 (external-phase
63 kind: 'run
64 args: (list "sh" "-c"
65 (string-append
66 "set -eu\n"
67 "d=\"$(dirname \"$PWD\")/install-root\"\n"
68 "mkdir -p \"$d${out}/include\" \"$d${out}/lib/pkgconfig\"\n"
69 ;; `install -m` rather than `cp`, so the installed mode is a
70 ;; function of the derivation and not of the
71 ;; ambient umask.
72 "install -m 644 tllist.h \"$d${out}/include/tllist.h\"\n"
73 "cat > \"$d${out}/lib/pkgconfig/tllist.pc\" <<'PC'\n"
74 "Name: tllist\n"
75 "Description: A C header file only implementation of a typed linked list\n"
76 "Version: 1.1.0\n"
77 "Cflags: -I${out}/include\n"
78 "PC\n"
79 ;; Prove the artifact rather than trust the copy:
80 ;; the header must be there AND pkg-config must
81 ;; be able to answer a query about it, which is
82 ;; what every consumer will actually do.
83 "test -f \"$d${out}/include/tllist.h\"\n"
84 "PKG_CONFIG_PATH=\"$d${out}/lib/pkgconfig\" pkg-config --exists tllist\n"
85 "PKG_CONFIG_PATH=\"$d${out}/lib/pkgconfig\" pkg-config --modversion tllist\n"
86 "echo TLLIST-INSTALLED\n"))))))))