88.23. rapidjson-1.1.0
Header-only JSON parser and generator for C++
| Version | 1.1.0, release 1 |
| Shelf | formats — Data-format and serialisation libraries (XML, JSON, YAML, TOML, INI, RDF, protobuf, thrift), plus data query and convert tools |
| Phase | 41_system (System), 553 of 1047 in build order |
| Licence | MIT |
| Homepage | https://rapidjson.org/ |
| Build time | 0.1 SBU |
| Installed size | 582.5 KiB in 39 files |
| Recipe | ports/core/formats/rapidjson/kpkgbuild |
About
RapidJSON is Tencent’s header-only JSON parser and generator for C++, with both a DOM and a SAX (streaming) API and in-place parsing. It installs only headers, a CMake package configuration and a pkg-config file. kodi, ppsspp, octave, opencascade, openbabel, opencpn and curaengine build against it.
Sources
rapidjson-1.1.0.tar.gz(995.5 KiB)
sha256bf7ced29704a1e696fbccf2a2b4ea068e7774fa37f6d7dd4039d0787f8bed98e
upstream: https://github.com/Tencent/rapidjson/archive/refs/tags/v1.1.0.tar.gz
archive copy: sources-2/formats--rapidjson-1.1.0.tar.gz
Dependencies
Required by (7): curaengine, kodi, octave, openbabel, opencascade, opencpn, ppsspp.
Patches
build.sh applies these; kpkg applies nothing by itself.
CVE-2024-38517.patch— Prevent int underflow when parsing exponentsWhen parsing negative exponents, the current implementation takes precautions for |exp| to not underflow int.
But that is not sufficient: later on [1], |exp + expFrac| is also stored to an int - so we must ensure that the sum stays within int representable values.
Update the exp clamping logic to take expFrac into account.
[1] https://github.com/Tencent/rapidjson/blob/master/include/rapidjson/reader.h#L1690
gcc14.patch— Removed non-compiling assignment operator. Fixed #718prettywriter-writeflags.patch— Two fixes toPrettyWriterinprettywriter.h: itsBasetypedef passes the class’swriteFlagstemplate argument on toWriter, so flags such askWriteNanAndInfFlaggiven to aPrettyWritertake effect, and its allocator constructor initialisesformatOptions_, which that constructor otherwise leaves unset.
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/41_system/phase.env && kpkg install rapidjson'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/formats/rapidjson.
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/formats/rapidjson
echo 'bf7ced29704a1e696fbccf2a2b4ea068e7774fa37f6d7dd4039d0787f8bed98e rapidjson-1.1.0.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/rapidjson
SRC=$SRC_ROOT/rapidjson-1.1.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf rapidjson-1.1.0.tar.gz -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 five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 --no-backup-if-mismatch -i "$PORT_SRC/gcc14.patch"
patch -p1 --no-backup-if-mismatch -i "$PORT_SRC/CVE-2024-38517.patch"
patch -p1 --no-backup-if-mismatch -i "$PORT_SRC/prettywriter-writeflags.patch"
mkdir build && cd build
cmake .. -G Ninja -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DRAPIDJSON_BUILD_DOC=OFF \
-DRAPIDJSON_BUILD_EXAMPLES=OFF \
-DRAPIDJSON_BUILD_TESTS=OFF
ninja
DESTDIR=$PKG ninja install
rm -rf "$PKG/usr/share/doc"
test -z "$(find "$PKG" -name '*.orig' -o -name '*.rej')"
The switches, and why each is set:
-DCMAKE_POLICY_VERSION_MINIMUM=3.5— TheCMakeLists.txtdeclaresCMAKE_MINIMUM_REQUIRED(VERSION 2.8), and the tree’s CMake 4 refuses a floor below 3.5 (see An old CMake policy floor).-DRAPIDJSON_BUILD_DOC=OFF— Do not build the Doxygen documentation. Upstream’s default is on.-DRAPIDJSON_BUILD_EXAMPLES=OFF— Do not build the example programs. Upstream’s default is on.-DRAPIDJSON_BUILD_TESTS=OFF— Do not build the unit and performance tests, which need googletest. Upstream’s default is on.
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/rapidjson, 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 rapidjson-1.1.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/rapidjson, and runs the triggers its paths call for.
Contents
Installed directories: /usr/include/rapidjson, /usr/lib/cmake/RapidJSON, /usr/share/licenses/rapidjson.
Short descriptions
RapidJSON.pc |
A fast JSON parser/generator for C++ with both SAX/DOM style API |
Notes
gcc14.patch and CVE-2024-38517.patch are upstream commits that the release does not contain. The first removes an assignment operator of GenericStringRef that assigns to its const members and so does not compile with GCC 14; the second keeps the exponent arithmetic of the number parser from underflowing int on a very large negative exponent.
The install copies include/rapidjson as a directory, whatever is in it. patch therefore runs with --no-backup-if-mismatch, so a hunk applied with fuzz leaves no .orig file to be installed as a header, and the test -z "$(find … -name '*.orig' -o -name '*.rej')" line stops the build if one is there anyway. Upstream’s readme.md and the example sources it installs under /usr/share/doc are deleted.