koreader-from-src: build even more from source

This commit is contained in:
Colin 2024-02-03 23:58:41 +00:00
parent dc74bca06a
commit 4bd73ddca3
2 changed files with 122 additions and 3 deletions

View File

@ -1,8 +1,21 @@
# koreader's native build process
# 1. git clone each dependency lib into base/thirdparty/$lib
# 2. git checkout a specific rev into base/thirdparty/$lib/build/$platform
# 3. invoke cmake in the checkout dir (including `make install` equivalent), which seems to not write outside the dir
# 4. manually copy the "installed" files in that checkout to some other place for koreader to use
# - see: koreader/base/Makefile.third
# ...
# koreader and all its deps are installed to $out/lib/koreader
# - i.e. it vendors its runtime deps
#
# there's probably a simpler implementation of this which just coverrides the rules defined in koreader/base/Makefile.third.
# - maybe, even, if we just satisfy the rules there (i.e. drop our files directly to the output which the Makefile rule would otherwise produce), then all's good?
{ lib
, autoPatchelfHook
, autoconf
, automake
, buildPackages
, callPackage
, cmake
, dpkg
, fetchFromGitHub
@ -24,7 +37,7 @@
, which
}:
let
sources = import ./sources.nix;
sources = callPackage ./sources.nix { luajit = luajit52; };
version = "2023.10";
src = fetchFromGitHub {
owner = "koreader";
@ -70,6 +83,24 @@ let
"debian"
else
crossTargets."${stdenv.hostPlatform.parsed.cpu.name}";
fakeBuildDep = buildPackages.writeShellScript "fake-build-ko-dep" ''
set -x
lib="$1"
build_dir="$2"
prebuilt="$3"
mkdir -p "$build_dir/$lib-prefix/src"
rm -rf "$build_dir/$lib-prefix/src/$lib"
rm -rf "$build_dir/$lib-prefix/src/$lib-build"
# the library build directory koreader uses isn't consistently named, but we can cover most cases ($lib or $lib-build).
# we have to copy the full tree rather than just symlink because koreader/base/Makefile.third
# is copying lib/*.so into include/.
# seriously, wtf are they doing over there.
cp -R "$prebuilt" "$build_dir/$lib-prefix/src/$lib"
cp -R "$prebuilt" "$build_dir/$lib-prefix/src/$lib-build"
# ln -s "$prebuilt" "$build_dir/$lib-prefix/src/$lib"
# ln -s "$prebuilt" "$build_dir/$lib-prefix/src/$lib-build"
'';
in
stdenv.mkDerivation rec {
pname = "koreader-from-src";
@ -163,12 +194,14 @@ stdenv.mkDerivation rec {
dontConfigure = true;
buildPhase = ''
link_lib_src() {
link_lib_into_build_dir() {
lib="$1"
rev="$2"
platform="$3"
prebuilt="$4"
lib_src="../$lib"
cmake_lists="base/thirdparty/$lib/CMakeLists.txt"
build_dir="base/thirdparty/$lib/build/$platform"
# link the nix clone into the directory koreader would use for checkout
@ -206,6 +239,14 @@ stdenv.mkDerivation rec {
cp -R "$lib_src" "$prefix/src/$lib"
# src dir needs to be writable for koreader to apply its own patches
chmod u+w -R "$prefix/src/$lib"
if [ -n "$prebuilt" ]; then
abs_build_dir="$(realpath "$build_dir")"
sed -i 's/INSTALL_COMMAND .*/INSTALL_COMMAND ""/' "$cmake_lists"
sed -i \
"s:BUILD_COMMAND .*:BUILD_COMMAND ${fakeBuildDep} $lib $abs_build_dir $prebuilt:" \
"$cmake_lists"
fi
}
${builtins.concatStringsSep "\n" (lib.mapAttrsToList
@ -214,7 +255,7 @@ stdenv.mkDerivation rec {
# for machine-agnostic libraries (e.g. pure lua), koreader doesn't build them in a flavored directory
machine = if src.machineAgnostic or false then "" else stdenv.hostPlatform.config;
in
''link_lib_src "${name}" "${src.source.rev}" "${machine}"''
''link_lib_into_build_dir "${name}" "${src.source.rev}" "${machine}" "${src.package or ""}"''
)
sources.thirdparty
)}

View File

@ -20,128 +20,193 @@
# - it may be that koreader-base is more strongly decoupled from `koreader` than first appears:
# - most `koreader` commits which update base simply bump its rev and nothing more.
# - then, `koreader-base` could be its own package, updated independently from the main koreader.
{ lib
, symlinkJoin
, curl
, czmq
, djvulibre
, freetype
, fribidi
, giflib
, glib
, harfbuzz
, k2pdfopt
, leptonica
, libjpeg_turbo
, libpng
, libunibreak
, libwebp
, luajit
, minizip
, mupdf
, nanosvg
, openssh
, openssl
, tesseract
, turbo
, utf8proc
, zeromq
, zstd
, zsync
}:
let
libAndDev = pkg: symlinkJoin {
inherit (pkg) name;
paths = [
(lib.getLib pkg)
(lib.getDev pkg)
];
};
in
{
thirdparty = {
# providing `package` is just a way to optimize builds, by getting KOReader to use the built nixpkg instead of building it itself from source.
# if it fails during an update, it should always be safe to delete the package key.
curl = {
source.url = "https://github.com/curl/curl.git";
source.rev = "tags/curl-7_80_0";
source.hash = "sha256-kzozc0Io+1f4UMivSV2IhzJDQXmad4wNhXN/Y2Lsg3Q=";
package = curl;
};
czmq = {
source.url = "https://github.com/zeromq/czmq.git";
source.rev = "2a0ddbc4b2dde623220d7f4980ddd60e910cfa78";
source.hash = "sha256-p4Cl2PLVgRQ0S4qr3VClJXjvAd2LUBU9oRUvOCfVnyw=";
# package = czmq; # koreader wants v1, nixpkgs has v4
};
djvulibre = {
source.url = "https://gitlab.com/koreader/djvulibre.git";
source.rev = "6a1e5ba1c9ef81c205a4b270c3f121a1e106f4fc";
source.hash = "sha256-OWSbxdr93FH3ed0D+NSFWIah7VDTcL3LIGOciY+f4dk=";
# package = djvulibre;
};
fbink = {
source.url = "https://github.com/NiLuJe/FBInk.git";
source.rev = "ae9dd275de369b1b34e1b566bca29573f06f38a2";
source.hash = "sha256-wkyl9xtw9ocjGGArvfGa1qjamwgywPktnZJNfdychB0=";
# package: not packaged for nix
};
freetype2 = {
source.url = "https://gitlab.com/koreader/freetype2.git";
source.rev = "VER-2-13-2";
source.hash = "sha256-yylSmVM3D5xnbFx9qEEHFIP/K0x/WDXZr0MA4C7ng7k=";
package = libAndDev freetype;
};
fribidi = {
source.url = "https://github.com/fribidi/fribidi.git";
source.rev = "tags/v1.0.12";
source.hash = "sha256-L4m/F9rs8fiv9rSf8oy7P6cthhupc6R/lCv30PLiQ4M=";
package = libAndDev fribidi;
};
giflib = {
source.url = "https://gitlab.com/koreader/giflib.git";
source.rev = "5.1.4";
source.hash = "sha256-znbY4tliXHXVLBd8sTKrbglOdCUb7xhcCQsDDWcQfhw=";
package = giflib;
};
glib = {
source.url = "https://github.com/GNOME/glib.git";
source.rev = "2.58.3";
source.hash = "sha256-KmJXCJ6h2QhPyK1axk+Y9+yJzO0wnCczcogopxGShJc=";
package = libAndDev glib;
};
harfbuzz = {
source.url = "https://github.com/harfbuzz/harfbuzz.git";
source.rev = "8.2.1";
source.hash = "sha256-1JgOXpObptt/IOkYj3Q9K170Yd5DIoBa20eoqY/iY6M=";
# package = harfbuzz;
package = libAndDev harfbuzz;
};
kobo-usbms = {
source.url = "https://github.com/koreader/KoboUSBMS.git";
source.rev = "3daab316d3aff2b43ced9c0b18e6ecdeec953e4a";
source.hash = "sha256-iBbbKCpi0/velkX91Qju0oXLZtRYGesbra1huKnGQFE=";
# package: not in nixpkgs
};
leptonica = {
source.url = "https://github.com/DanBloomberg/leptonica.git";
source.rev = "1.74.1";
source.hash = "sha256-SDXKam768xvZZvTbXe3sssvZyeLEEiY97Vrzx8hoc6g=";
# package = leptonica; # k2pdf needs leptonica src. # cp -f /build/koreader/base/thirdparty/libk2pdfopt/build/aarch64-unknown-linux-gnu/libk2pdfopt-prefix/src/libk2pdfopt/leptonica_mod/dewarp2.c
};
libjpeg-turbo = {
source.url = "https://github.com/libjpeg-turbo/libjpeg-turbo.git";
source.rev = "3.0.0";
source.hash = "sha256-mIeSBP65+rWOCRS/33MPqGUpemBee2qR45CZ6H00Hak=";
# package = libAndDev libjpeg_turbo;
};
libk2pdfopt = {
source.url = "https://github.com/koreader/libk2pdfopt.git";
source.rev = "60b82eeecf71d1776951da970fe8cd2cc5735ded";
source.hash = "sha256-9UcDr9e4GZCZ78moRs1ADAt4Xl7z3vR93KDexXEHvhw=";
# package = k2pdfopt; # nixpkgs version is NOT koreader's. koreader probably forked it; nixpkgs uses old, insecure mupdf 1.17.0
};
libpng = {
source.url = "https://github.com/glennrp/libpng.git";
source.rev = "v1.6.40";
source.hash = "sha256-Rad7Y5Z9PUCipBTQcB7LEP8fIVTG3JsnMeknUkZ/rRg=";
# package = libAndDev libpng; # "/build/koreader/base/thirdparty/libpng/build/aarch64-unknown-linux-gnu/libpng-prefix/src/libpng-build/.libs/libpng16.so.16"
};
libunibreak = {
source.url = "https://github.com/adah1972/libunibreak.git";
source.rev = "tags/libunibreak_5_1";
source.hash = "sha256-hjgT5DCQ6KFXKlxk9LLzxGHz6B71X/3Ot7ipK3KY85A=";
# package = libAndDev libunibreak; # nixpkgs version is incompatible
};
libwebp = {
source.url = "https://github.com/webmproject/libwebp.git";
source.rev = "v1.3.2";
source.hash = "sha256-gfwUlJ44biO1lB/3SKfMkM/YBiYcz6RqeMOw+0o6Z/Q=";
package = libAndDev libwebp;
};
libzmq = {
source.url = "https://github.com/zeromq/libzmq";
source.rev = "883e95b22e0bffffa72312ea1fec76199afbe458";
source.hash = "sha256-R76EREtHsqcoKxKrgT8gfEf9pIWdLTBXvF9cDvjEf3E=";
# package = zeromq; # koreader expects v4, nixpkgs is v5
};
lj-wpaclient = {
source.url = "https://github.com/koreader/lj-wpaclient.git";
source.rev = "2f93beb3071e6ebb57c783bd5b92f83aa5ebb757";
source.hash = "sha256-ilJviGZTvL2i1TN5lHQ4eA9pFiM7NlXD+v9ofv520b8=";
machineAgnostic = true;
# package: not in nixpkgs; not even a non-luajit `wpaclient`
};
lodepng = {
source.url = "https://github.com/lvandeve/lodepng.git";
source.rev = "c18b949b71f45e78b1f9a28c5d458bce0da505d6";
source.hash = "sha256-AAw6I+MxDaxmGpjC5efxuBNw7Lx8FXwg2TEfl6LfPfQ=";
# package: not in nixpkgs, except in source-only form (mujoco.pin.lodepng)
};
lua-htmlparser = {
source.url = "https://github.com/msva/lua-htmlparser";
source.rev = "5ce9a775a345cf458c0388d7288e246bb1b82bff";
source.hash = "sha256-aSTLSfqz/MIDFVRwtBlDNBUhPb7KqOl32/Y62Hdec1s=";
# package: not in nixpkgs
};
luajit = {
source.url = "https://github.com/LuaJIT/LuaJIT";
source.rev = "656ecbcf8f669feb94e0d0ec4b4f59190bcd2e48";
source.hash = "sha256-KPZ1jaU9qu7CUg2eHxBNu2mrHD54+lNOCQB4sb1DPok=";
# package = luajit; #< could be fixed; follows a different install structure
};
lua-rapidjson = {
source.url = "https://github.com/xpol/lua-rapidjson";
source.rev = "242b40c8eaceb0cc43bcab88309736461cac1234";
source.hash = "sha256-y/czEVPtCt4uN1n49Qi7BrgZmkG+SDXlM5D2GvvO2qg=";
# package: TODO: packaged in nix as a luarocks package
};
luasec = {
source.url = "https://github.com/brunoos/luasec";
source.rev = "tags/v1.3.1";
source.hash = "sha256-3iYRNQoVk5HFjDSqRRmg1taSqeT2cHFil36vxjrEofo=";
# package: TODO: packaged in nix as a luarocks package
};
luasocket = {
source.url = "https://github.com/lunarmodules/luasocket";
source.rev = "8c2ff7217e2a205eb107a6f48b04ff1b2b3090a1";
source.hash = "sha256-Y35QYNLznQmErr6rIjxLzw0/6Y7y8TbzD4yaEdgEljA=";
# package: TODO: packaged in nix as a luarocks package
};
lua-Spore = {
# Complete... ish?
@ -152,42 +217,50 @@
source.url = "https://framagit.org/fperrad/lua-Spore";
source.rev = "tags/0.3.3";
source.hash = "sha256-wb7ykJsndoq0DazHpfXieUcBBptowYqD/eTTN/EK/6g=";
# package: not in nixpkgs
};
lunasvg = {
source.url = "https://github.com/sammycage/lunasvg.git";
source.rev = "59d6f6ba835c1b7c7a0f9d4ea540ec3981777885";
source.hash = "sha256-gW2ikakS6Omz5upmy26nAo/jkGHYO2kjlB3UmKJBh1k=";
# package: not in nixpkgs
};
minizip = {
source.url = "https://github.com/nmoinvaz/minizip";
source.rev = "0b46a2b4ca317b80bc53594688883f7188ac4d08";
source.hash = "sha256-P/3MMMGYDqD9NmkYvw/thKpUNa3wNOSlBBjANHSonAg=";
# package = libAndDev minizip; # weird #include incompatibilities... maybe resolvable.
};
mupdf = {
source.url = "https://github.com/ArtifexSoftware/mupdf.git";
source.rev = "tags/1.13.0";
source.hash = "sha256-pQejRon9fO9A1mhz3oLjBr1j4HveDLcQIWjR1/Rpy5Q=";
# package = libAndDev mupdf; # nixpkgs' mupdf is incompatible with koreader's `libwrap-mupdf`
};
nanosvg = {
source.url = "https://github.com/memononen/nanosvg.git";
source.rev = "9da543e8329fdd81b64eb48742d8ccb09377aed1";
source.hash = "sha256-VOiN6583DtzGYPRkl19VG2QvSzl4T9HaynBuNcvZf94=";
machineAgnostic = true;
package = nanosvg.src; # KOReader only wants the .h files, but decides to do that without even building it.
};
openssh = {
source.url = "https://github.com/openssh/openssh-portable.git";
source.rev = "V_8_6_P1";
source.hash = "sha256-yjIpSbe5pt9sEV2MZYGztxejg/aBFfKO8ieRvoLN2KA=";
package = openssh;
};
openssl = {
source.url = "https://github.com/openssl/openssl.git";
source.rev = "OpenSSL_1_1_1u";
source.hash = "sha256-JOcUj4ovA6621+1k2HUsvhGX1B9BjvaMbCaSx680nSs=";
# package = openssl; # incompatible with nixpkgs version
};
popen-noshell = {
source.url = "https://github.com/famzah/popen-noshell.git";
source.rev = "e715396a4951ee91c40a98d2824a130f158268bb";
source.hash = "sha256-JeBZMsg6ZUGSnyZ4eds4w63gM/L73EsAnLaHOPpL6iM=";
# package: not in nixpkgs
};
# sdcv = {
# # upstream is (temporarily?) acquiring this via `download_project` machinery
@ -200,26 +273,31 @@
source.url = "https://github.com/tesseract-ocr/tesseract.git";
source.rev = "60176fc5ae5e7f6bdef60c926a4b5ea03de2bfa7";
source.hash = "sha256-FQvlrJ+Uy7+wtUxBuS5NdoToUwNRhYw2ju8Ya8MLyQw=";
# package = tesseract; # i guess koreader's k2pdf also builds tessearct??
};
turbo = {
source.url = "https://github.com/kernelsauce/turbo";
source.rev = "tags/v2.1.3";
source.hash = "sha256-vBRkFdc5a0FIt15HBz3TnqMZ+GGsqjEefnfJEpuVTBs=";
# package = turbo; # nixpkgs' turbo is a totally different thing
};
utf8proc = {
source.url = "https://github.com/JuliaStrings/utf8proc.git";
source.rev = "v2.8.0";
source.hash = "sha256-/lSD78kj133rpcSAOh8T8XFW/Z0c3JKkGQM5Z6DcMtU=";
# package = libAndDev utf8proc; # nixpkgs is v3, not v2; incompatible .so name. /build/koreader/base/thirdparty/utf8proc/build/aarch64-unknown-linux-gnu/utf8proc-prefix/src/utf8proc/libutf8proc.so.2
};
zstd = {
source.url = "https://github.com/facebook/zstd.git";
source.rev = "tags/v1.5.5";
source.hash = "sha256-tHHHIsQU7vJySrVhJuMKUSq11MzkmC+Pcsj00uFJdnQ=";
package = libAndDev zstd;
};
zsync2 = {
source.url = "https://github.com/NiLuJe/zsync2.git";
source.rev = "e618d18f6a7cbf350cededa17ddfe8f76bdf0b5c";
source.hash = "sha256-S0vxCON1l6S+NWlnRPfm7R07DVkvkG+6QW5LNvXBlA8=";
package = zsync; # possibly a different thing than koreader's
};
};