AtlatestRepositorycore-channel

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

1;;; Screen capture.
2;;;
3;;; grim is a Wayland screenshot client. It is in this channel for two
4;;; reasons, and the second is the one worth reading.
5;;;
6;;; 1. IT IS A SECOND WAYLAND CLIENT. Everything else in the Wayland half of
7;;; this channel exists to serve foot, which makes it hard to tell whether
8;;; `wayland`, `pixman` and `wayland-protocols` are packaged correctly or
9;;; merely packaged the way foot happens to need. A second, unrelated
10;;; consumer answers that.
11;;;
12;;; 2. IT MAKES A DIFFERENTIAL TEST POSSIBLE -- AND IT MUST NOT BE MISTAKEN
13;;; FOR AN INSTRUMENT. foot's acceptance evidence is a screenshot of a
14;;; nested compositor, and that screenshot is deliberately taken with the
15;;; HOST's grim, not this one. The observer has to be independent of the
16;;; observed: a grim built from the SAME pixman and the SAME wayland-client
17;;; as foot could be wrong in a correlated way, agree with foot, and produce
18;;; a convincing green. What this package is good for is the other
19;;; direction -- run both grims on the same frame and compare. Agreement is
20;;; then evidence that the channel's Wayland and pixman stack behaves like
21;;; the host's, which is a measurement rather than a caveat.
22;;;
23;;; grim vendors the `wlr-screencopy` protocol XML it needs under `protocol/`,
24;;; so it does not drag wlroots into this channel.
25(define-library (core packages capture)
26 (import (sigil core)
27 (core build-environments)
28 (core packages compression)
29 (core packages graphics)
30 (core packages wayland)
31 (core packages ffi)
32 (core packages build-tools)
33 (core packages python)
34 (sigil env package)
35 (sigil build external))
36 (export grim)
37 (begin
38 (define grim
39 (package
40 name: "grim"
41 version: "1.4.0"
42 source: (external-source
43 location: "https://github.com/emersion/grim/releases/download/v1.4.0/grim-1.4.0.tar.gz"
44 sha256: "b6786e889ed93568634189a59f6b6429c041bf74883c10e8b6e2ed6772ae7ffb")
45 buildenv: core-buildenv
46 ;; zlib is reached through libpng.pc's `Requires:` chain -- see the
47 ;; note on `fontconfig` in (core packages fonts) for why a
48 ;; grand-dependency has to be named here.
49 dependencies: (list libpng pixman wayland wayland-protocols libffi zlib)
50 ;; WAYLAND IS A DEPENDENCY ONLY, AND THE SCANNER IS POINTED AT
51 ;; EXPLICITLY. The obvious move -- naming `wayland` in BOTH
52 ;; `dependencies:` and `build-inputs:`, since grim needs the library
53 ;; linked and the `wayland-scanner` program run -- IS REFUSED:
54 ;;
55 ;; package: duplicate input name: wayland
56 ;;
57 ;; and there is no way round it by declaration. Only build inputs put
58 ;; a `bin/` on PATH, and a dependency cannot export one either, because
59 ;; `PATH` is builder-owned and a `search-paths:` export naming it is
60 ;; refused as well.
61 ;;
62 ;; foot does not hit this: it reads the scanner's absolute path out of
63 ;; pkg-config (`wscanner.get_variable('wayland_scanner')`). grim's
64 ;; `protocol/meson.build:3` does a plain
65 ;; `find_program('wayland-scanner')`, which searches PATH:
66 ;;
67 ;; Run-time dependency wayland-client found: YES 1.24.0
68 ;; Program wayland-scanner found: NO
69 ;;
70 ;; The library is found and the program is not, from the same package,
71 ;; one line apart.
72 ;;
73 ;; The answer is meson's own mechanism for exactly this -- a native
74 ;; file naming the binary -- fed from `${wayland}`, which interpolates
75 ;; because wayland IS a declared dependency. No patch to grim, no
76 ;; second declaration, and the path is derived from the closure rather
77 ;; than searched for.
78 build-inputs: (list meson samurai python)
79 phases: (list
80 (external-phase
81 kind: 'run
82 args: (list "sh" "-c"
83 (string-append
84 "set -eu\n"
85 "cat > native.ini <<'NF'\n"
86 "[binaries]\n"
87 "wayland-scanner = '${wayland}/bin/wayland-scanner'\n"
88 "NF\n"
89 "meson setup build --native-file native.ini"
90 " --prefix=${out}"
91 " --buildtype=plain"
92 " --default-library=static"
93 ;; `-Dprefer_static=true` MAKES MESON ASK
94 ;; PKG-CONFIG THE STATIC QUESTION, and without it
95 ;; a fully static link fails at the last step.
96 ;;
97 ;; A `.pc` file splits its link line: `Libs:` is
98 ;; what a SHARED consumer needs, `Libs.private:`
99 ;; and `Requires.private:` are the extra
100 ;; transitive libraries a STATIC consumer needs.
101 ;; fontconfig lists expat under
102 ;; `Requires.private:`, so a default
103 ;; `dependency('fontconfig')` emits no `-lexpat`
104 ;; -- correct for a shared link, fatal here:
105 ;;
106 ;; ld.lld: error: undefined symbol: XML_ErrorString
107 ;; >>> referenced by fcxml.c
108 ;; >>> fcxml.o in archive libfontconfig.a
109 ;;
110 ;; The symbol is missing from the LINK, not from
111 ;; the closure: expat is declared, built, and
112 ;; present. Only the query was the wrong one.
113 ;; This is the same `Requires.private:` line that
114 ;; had to be satisfied at CONFIGURE time; it bites
115 ;; twice, in two different ways, and fixing the
116 ;; first does not fix the second.
117 " -Dprefer_static=true"
118 ;; JPEG output would add libjpeg for a format
119 ;; nothing here reads.
120 ;; UPSTREAM'S WARNINGS-AS-ERRORS IS TURNED OFF,
121 ;; and this is a compiler-set difference rather
122 ;; than a defect in grim. grim's meson sets
123 ;; `werror=true`, and this toolchain's clang
124 ;; warns where the author's compiler did not:
125 ;;
126 ;; ../write_ppm.c:32:23: error: unused variable
127 ;; 'format' [-Werror,-Wunused-variable]
128 ;;
129 ;; The variable really is unused, in a PPM writer
130 ;; nothing in this channel calls. Distributions
131 ;; disable `werror` for exactly this reason: a
132 ;; project's warning policy is calibrated to the
133 ;; compilers its authors use, and turning a
134 ;; foreign compiler's extra warnings into build
135 ;; failures makes the package unbuildable for
136 ;; reasons unrelated to correctness.
137 ;;
138 ;; NOTE THAT FOOT DOES NOT NEED THIS. foot also
139 ;; sets `werror=true` and compiles clean under
140 ;; the same clang, so this is not a blanket
141 ;; concession -- it is one package's warning.
142 " -Dwerror=false"
143 " -Djpeg=disabled"
144 ;; man pages want scdoc.
145 " -Dman-pages=disabled\n"
146 "echo GRIM-CONFIGURED\n")))
147 (external-phase
148 kind: 'run
149 args: (list "sh" "-c"
150 (string-append
151 "set -eu\n"
152 "meson compile -C build\n"
153 "echo GRIM-COMPILED\n")))
154 (external-phase
155 kind: 'run
156 args: (list "sh" "-c"
157 (string-append
158 "set -eu\n"
159 "d=\"$(dirname \"$PWD\")/install-root\"\n"
160 "DESTDIR=\"$d\" meson install -C build --no-rebuild\n"
161 "test -x \"$d${out}/bin/grim\"\n"
162 "echo GRIM-INSTALLED\n"))))))))