212.3. pdfium-7988
Chromium's PDF renderer, as a shared library with its C headers
| Version | 7988, release 1 |
| Shelf | documents — PDF, PostScript, DjVu, EPUB, CHM and DOCX viewers, libraries and tools, and ebook managers |
| Phase | 42_graphics (Graphics Stack), 84 of 189 in build order |
| Licence | BSD-3-Clause AND Apache-2.0 |
| Homepage | https://pdfium.googlesource.com/pdfium/ |
| Build time | 4.7 SBU |
| Installed size | 5.1 MiB in 28 files |
| Recipe | ports/core/documents/pdfium/kpkgbuild |
About
PDFium is Chromium’s PDF engine. KDOS builds it as a shared library, libpdfium.so, with its C headers under /usr/include/pdfium and two pkg-config files, for the two ports that use it: python3-pypdfium2, the Python binding that OCRmyPDF renders pages with, and libvips’s PDF loader. The port’s version is the PDFium branch number, which is also the build number of the Chromium release it belongs to (_chromium in the recipe).
Why it is in KDOS
The comment above it in script/phases/42_graphics/packages.d/documents.txt:
ocrmypdf's rasteriser: Chromium's PDF engine built as a shared library.
Sources
pdfium-7988.tar.bz2(15.6 MiB)
sha2560340b2fca57cecdf6e2e0366129a3340f6764c132cb090f57db96d9f0f349855
upstream: https://dev-www.libreoffice.org/src/pdfium-7988.tar.bz2
archive copy: sources-1/documents--pdfium-7988.tar.bz2pdfium-vendor-7988.tar.xz(3.0 MiB)
sha2564268f9778821e4aa45e21ba2ca21641aacc4657bfa01692232b89ed64ad07546
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-1/documents--pdfium-vendor-7988.tar.xz
Dependencies
Depends on: gn, ninja, python3, pkgconf, freetype2, harfbuzz, icu, lcms2, libjpeg-turbo, libpng, openjpeg, zlib.
Required by (2): libvips, python3-pypdfium2.
Patches
build.sh applies these; kpkg applies nothing by itself.
pdfium-shared-library.patch— Turns thepdfiumtarget from a gncomponent, which outside a component build is a static library, into ashared_library; makesFPDF_EXPORTexport the API unconditionally instead of only underCOMPONENT_BUILD; and makes the headers inpublic/cppinclude their siblings by relative path, so the installed headers resolve under/usr/include/pdfium.
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/42_graphics/phase.env && kpkg install pdfium'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/documents/pdfium.
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/documents/pdfium
echo '0340b2fca57cecdf6e2e0366129a3340f6764c132cb090f57db96d9f0f349855 pdfium-7988.tar.bz2' | sha256sum -c -
echo '4268f9778821e4aa45e21ba2ca21641aacc4657bfa01692232b89ed64ad07546 pdfium-vendor-7988.tar.xz' | 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/pdfium
SRC=$SRC_ROOT/pdfium-7988
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf pdfium-7988.tar.bz2 -C "$SRC" --strip-components=1
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 recipe’s helpers _chromium, _build_rev, _abseil_rev and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
for pin in "build_revision=$_build_rev" "abseil_revision=$_abseil_rev"; do
if ! grep -q "'${pin%%=*}': '${pin#*=}'" DEPS; then
echo "pdfium: DEPS does not name ${pin%%=*} ${pin#*=} — rebuild the vendor bundle" >&2
exit 1
fi
done
rm -rf third_party/abseil-cpp
tar -xf "$PORT_SRC/$name-vendor-$version.tar.xz" --strip-components=1
patch -p1 -i "$PORT_SRC/pdfium-shared-library.patch"
printf 'build_with_chromium = false\n' > build/config/gclient_args.gni
install -Dm644 build/linux/unbundle/icu.gn third_party/icu/BUILD.gn
export CC=gcc CXX=g++ AR=ar NM=nm
export CPPFLAGS="$CPPFLAGS -ffp-contract=off"
gn gen out/Release --root-pattern=//:pdfium --args='
is_debug = false
is_clang = false
is_component_build = false
custom_toolchain = "//build/toolchain/linux/unbundle:default"
host_toolchain = "//build/toolchain/linux/unbundle:default"
treat_warnings_as_errors = false
clang_use_chrome_plugins = false
use_custom_libcxx = false
use_sysroot = false
use_glib = false
use_siso = false
pdf_is_standalone = true
pdf_enable_v8 = false
pdf_enable_xfa = false
pdf_use_skia = false
pdf_use_partition_alloc = false
pdf_bundle_freetype = false
use_system_freetype = true
use_system_harfbuzz = true
use_system_lcms2 = true
use_system_libjpeg = true
use_system_libopenjpeg2 = true
use_system_libpng = true
use_system_libtiff = true
use_system_zlib = true
'
ninja -C out/Release pdfium
install -Dm755 out/Release/libpdfium.so "$PKG/usr/lib/libpdfium.so"
install -d "$PKG/usr/include/pdfium/cpp"
install -m644 public/*.h "$PKG/usr/include/pdfium/"
install -m644 public/cpp/*.h "$PKG/usr/include/pdfium/cpp/"
install -Dm644 /dev/stdin "$PKG/usr/lib/pkgconfig/libpdfium.pc" <<PC
prefix=/usr
libdir=\${prefix}/lib
includedir=\${prefix}/include/pdfium
Name: libpdfium
Description: Chromium's PDF renderer
Version: $_chromium
Libs: -L\${libdir} -lpdfium
Cflags: -I\${includedir}
PC
install -Dm644 /dev/stdin "$PKG/usr/lib/pkgconfig/pdfium.pc" <<PC
prefix=/usr
libdir=\${prefix}/lib
includedir=\${prefix}/include/pdfium
Name: pdfium
Description: Chromium's PDF renderer
Version: $version
Libs: -L\${libdir} -lpdfium
Cflags: -I\${includedir}
PC
install -Dm644 LICENSE "$PKG/usr/share/licenses/$name/LICENSE"
The switches, and why each is set:
export CC=gcc CXX=g++ AR=ar NM=nm— The//build/toolchain/linux/unbundle:defaulttoolchain, named as bothcustom_toolchainandhost_toolchain, takes its compiler, archiver andnm, andCFLAGS,CPPFLAGS,CXXFLAGSandLDFLAGS, from the environment.is_clang = falseandclang_use_chrome_plugins = falsego with it: the library is built with the tree’s GCC.-ffp-contract=off— Do not fuse a multiply and an add into one floating-point operation. Chromium’s own build, which is clang, passes the same flag inbuild/config/compiler; withis_clang = falsethat branch is not taken, sobuild.shadds it throughCPPFLAGS, which the toolchain passes to both C and C++ compiles.--root-pattern=//:pdfium— Keep gn to the library’s own build graph, so the test targets, whose fonts are not in the tarball, are never loaded.is_component_build = false— A normal build, in which a gncomponentis a static library;pdfium-shared-library.patchis what makespdfiuma shared one.treat_warnings_as_errors = false— Do not compile with-Werror, which upstream’s build turns on.use_custom_libcxx = false,use_sysroot = false,use_glib = false,use_siso = false— Link the system’s libstdc++ instead of Chromium’s bundled libc++, compile against the root instead of a downloaded Debian sysroot, use no GLib, and generate plain ninja files rather than ones for Chromium’ssisobuild tool.pdf_is_standalone = true— Build PDFium on its own, outside a Chromium tree.pdf_enable_v8 = false,pdf_enable_xfa = false— Build without JavaScript in PDF forms, which needs V8, a second browser engine to build, and without XFA forms, which need V8 too.pdf_use_skia = false— Render with PDFium’s own AGG rasteriser, not Skia.pdf_use_partition_alloc = false— Allocate with the system’smallocinstead of Chromium’s PartitionAlloc.pdf_bundle_freetype = false,use_system_freetype = true,use_system_harfbuzz = true,use_system_lcms2 = true,use_system_libjpeg = true,use_system_libopenjpeg2 = true,use_system_libpng = true,use_system_libtiff = true,use_system_zlib = true— Link every codec and font library from the tree instead of the copies underthird_party/. All are ports independsexcept libtiff, which only XFA reaches.
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/pdfium, 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 pdfium-7988-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/pdfium, and runs the triggers its paths call for.
Contents
Installed libraries: libpdfium.so.
Installed directories: /usr/include/pdfium, /usr/share/licenses/pdfium.
Short descriptions
libpdfium.pc |
Chromium's PDF renderer |
pdfium.pc |
Chromium's PDF renderer |
Notes
- The source and the vendor bundle. The tarball is LibreOffice’s copy of the PDFium branch; it carries PDFium’s own tree with its
third_partycopies, and of what gclient would fetch, fast_float and part of abseil. The rest of what gn needs is the vendor bundle, made by hand: Chromium’s//buildat the revision the branch’sDEPSnames asbuild_revision,third_party/abseil-cppwith itsBUILD.gnfiles atabseil_revision, andtools/generate_shim_headers/generate_shim_headers.pyfrom the matching Chromium tag. How to rebuild it on a version bump is in A bundle no tool writes.build.shremoves the tarball’s partial abseil and unpacks the bundle over the tree. - The pins are checked first. The recipe’s
_build_revand_abseil_revmust be the revisionsDEPSnames; the loop at the top ofbuild.shstops the build otherwise, because a//buildfrom another branch fails in gn with errors that name neither. - Two pkg-config files, two versions.
libpdfium.pccarries the Chromium version (_chromium), which python3-pypdfium2’s build reads and records in its bindings; without it the binding records the build number as NaN, and everybuild >= Ncheck in its helpers is false, so the constants and error paths those checks guard are silently missing.pdfium.pccarries the branch number: libvips looks the library up aspdfiumand requires version>= 4200, a branch number, which the Chromium version would fail. A symbolic link between the two would give both consumers the sameVersionline. - Two files gclient would write.
build/config/gclient_args.gni, which//buildimports, is written bybuild.shwithbuild_with_chromium = false, since no gclient runs; and Chromium’s ICU unbundling shim,build/linux/unbundle/icu.gn, is installed asthird_party/icu/BUILD.gn, so ICU comes from the icu port.