Merge pull request #261113 from lilyinstarlight/fix/mupdf-hell

authored by

Ryan Lahfa and committed by
GitHub
ed2b1fe0 6cc772a6

+190 -66
+3 -4
pkgs/applications/misc/llpp/default.nix
··· 16 16 17 17 patches = [ 18 18 (fetchpatch { 19 - name = "system-makedeps.patch"; 20 - url = "https://aur.archlinux.org/cgit/aur.git/plain/system-makedeps.patch?h=llpp&id=0d2913056aaf3dbf7431e57b7b08b55568ba076c"; 21 - hash = "sha256-t9PLXsM8+exCeYqJBe0LSDK0D2rpktmozS8qNcEAcHo="; 19 + name = "system-makedeps-and-ocaml5.patch"; 20 + url = "https://aur.archlinux.org/cgit/aur.git/plain/system-makedeps-and-ocaml5.patch?h=llpp&id=32955e115f914bb96348d288f9af9c6e3e80a02b"; 21 + hash = "sha256-3rcPsR+M8Jx7M8GHUIsw0WNBvp6aE7BcPr4yk2vT9Ik="; 22 22 }) 23 - ./fix-mupdf.patch 24 23 ]; 25 24 26 25 postPatch = ''
-13
pkgs/applications/misc/llpp/fix-mupdf.patch
··· 1 - --- a/link.c 2 - +++ b/link.c 3 - @@ -1522,8 +1522,9 @@ static void *mainloop (void UNUSED_ATTR *unused) 4 - if (pdf && nameddest && *nameddest) { 5 - fz_point xy; 6 - struct pagedim *pdim; 7 - - int pageno = pdf_lookup_anchor (state.ctx, pdf, nameddest, 8 - + fz_location location = fz_resolve_link (state.ctx, state.doc, nameddest, 9 - &xy.x, &xy.y); 10 - + int pageno = location.page; 11 - pdim = pdimofpageno (pageno); 12 - xy = fz_transform_point (xy, pdim->ctm); 13 - printd ("a %d %d %d", pageno, (int) xy.x, (int) xy.y);
+13
pkgs/applications/misc/mupdf/0003-Fix-cpp-build.patch
··· 1 + diff --git a/scripts/wrap/cpp.py b/scripts/wrap/cpp.py 2 + index 51ac5f1..b5c0b5a 100644 3 + --- a/scripts/wrap/cpp.py 4 + +++ b/scripts/wrap/cpp.py 5 + @@ -4595,7 +4595,7 @@ def cpp_source( 6 + */ 7 + typedef unsigned long size_t; 8 + ''')) 9 + - if state.state_.macos: 10 + + if state.state_.linux or state.state_.macos: 11 + f.write( textwrap.dedent(''' 12 + /* 13 + Workaround on MacOS: we need to define fixed-size int types
+55 -21
pkgs/applications/misc/mupdf/default.nix
··· 1 1 { stdenv 2 2 , lib 3 3 , fetchurl 4 - , fetchpatch 5 4 , fetchFromGitHub 6 5 , copyDesktopItems 7 6 , makeDesktopItem ··· 26 25 , enableGL ? true 27 26 , freeglut 28 27 , libGLU 28 + , enableOcr ? false 29 + , leptonica 30 + , tesseract 31 + , enableCxx ? false 32 + , python3 33 + , enablePython ? false 34 + , which 35 + , swig 29 36 , xcbuild 30 37 , gitUpdater 31 38 32 39 # for passthru.tests 33 40 , cups-filters 34 - , python3 35 41 , zathura 42 + , mupdf 36 43 }: 37 - let 38 44 39 - # OpenJPEG version is hardcoded in package source 40 - openJpegVersion = with stdenv; 41 - lib.versions.majorMinor (lib.getVersion openjpeg); 45 + assert enablePython -> enableCxx; 46 + 47 + let 42 48 43 49 freeglut-mupdf = freeglut.overrideAttrs (old: rec { 44 50 pname = "freeglut-mupdf"; ··· 53 59 54 60 in 55 61 stdenv.mkDerivation rec { 56 - version = "1.23.0"; 62 + version = "1.23.5"; 57 63 pname = "mupdf"; 58 64 59 65 src = fetchurl { 60 66 url = "https://mupdf.com/downloads/archive/${pname}-${version}-source.tar.gz"; 61 - sha256 = "sha256-3kFAaS5pMULDEeAwrBVuOO4XXXq2wb4QxcmuljhGFk4="; 67 + sha256 = "sha256-blZ5zfqu+cfoniljlSIM4sEz7T3K1RpHhmczbG6uxwY="; 62 68 }; 63 69 64 70 patches = [ ./0001-Use-command-v-in-favor-of-which.patch 65 71 ./0002-Add-Darwin-deps.patch 72 + ./0003-Fix-cpp-build.patch 66 73 ]; 67 74 68 75 postPatch = '' 69 - sed -i "s/__OPENJPEG__VERSION__/${openJpegVersion}/" source/fitz/load-jpx.c 70 76 substituteInPlace Makerules --replace "(shell pkg-config" "(shell $PKG_CONFIG" 77 + 78 + patchShebangs scripts/mupdfwrap.py 79 + 80 + # slip in makeFlags when building bindings 81 + sed -i -e 's/^\( *make_args *=\)/\1 """ $(echo ''${makeFlagsArray[@]@Q})"""/' scripts/wrap/__main__.py 82 + 83 + # fix libclang unnamed struct format 84 + for wrapper in ./scripts/wrap/{cpp,state}.py; do 85 + substituteInPlace "$wrapper" --replace 'struct (unnamed' '(unnamed struct' 86 + done 71 87 ''; 72 88 73 - # Use shared libraries to decrease size 74 - buildFlags = [ "shared" ]; 75 - 76 89 makeFlags = [ 77 90 "prefix=$(out)" 91 + "shared=yes" 78 92 "USE_SYSTEM_LIBS=yes" 79 93 "PKG_CONFIG=${buildPackages.pkg-config}/bin/${buildPackages.pkg-config.targetPrefix}pkg-config" 80 94 ] ++ lib.optionals (!enableX11) [ "HAVE_X11=no" ] 81 - ++ lib.optionals (!enableGL) [ "HAVE_GLUT=no" ]; 95 + ++ lib.optionals (!enableGL) [ "HAVE_GLUT=no" ] 96 + ++ lib.optionals (enableOcr) [ "USE_TESSERACT=yes" ]; 82 97 83 98 nativeBuildInputs = [ pkg-config ] 84 99 ++ lib.optional (enableGL || enableX11) copyDesktopItems 100 + ++ lib.optionals (enableCxx || enablePython) [ python3 python3.pkgs.setuptools python3.pkgs.libclang ] 101 + ++ lib.optionals (enablePython) [ which swig ] 85 102 ++ lib.optional stdenv.isDarwin desktopToDarwinBundle; 86 103 87 104 buildInputs = [ freetype harfbuzz openjpeg jbig2dec libjpeg gumbo ] ··· 89 106 ++ lib.optionals enableX11 [ libX11 libXext libXi libXrandr ] 90 107 ++ lib.optionals enableCurl [ curl openssl ] 91 108 ++ lib.optionals enableGL ( 92 - if stdenv.isDarwin then 93 - with darwin.apple_sdk.frameworks; [ GLUT OpenGL ] 94 - else 95 - [ freeglut-mupdf libGLU ] 96 - ) 109 + if stdenv.isDarwin then 110 + with darwin.apple_sdk.frameworks; [ GLUT OpenGL ] 111 + else 112 + [ freeglut-mupdf libGLU ] 113 + ) 114 + ++ lib.optionals enableOcr [ leptonica tesseract ] 97 115 ; 98 116 outputs = [ "bin" "dev" "out" "man" "doc" ]; 99 117 ··· 102 120 rm -rf thirdparty/{curl,freetype,glfw,harfbuzz,jbig2dec,libjpeg,openjpeg,zlib} 103 121 ''; 104 122 123 + postBuild = lib.optionalString (enableCxx || enablePython) '' 124 + for dir in build/*; do 125 + ./scripts/mupdfwrap.py -d "$dir" -b ${lib.optionalString (enableCxx) "01"}${lib.optionalString (enablePython) "23"} 126 + done 127 + ''; 128 + 105 129 desktopItems = [ 106 130 (makeDesktopItem { 107 131 name = pname; ··· 136 160 Name: mupdf 137 161 Description: Library for rendering PDF documents 138 162 Version: ${version} 139 - Libs: -L$out/lib -lmupdf -lmupdf-third 163 + Libs: -L$out/lib -lmupdf 140 164 Cflags: -I$dev/include 141 165 EOF 142 166 ··· 148 172 ln -s "$bin/bin/mupdf-gl" "$bin/bin/mupdf" 149 173 '' else lib.optionalString (enableX11) '' 150 174 ln -s "$bin/bin/mupdf-x11" "$bin/bin/mupdf" 151 - ''); 175 + '') + (lib.optionalString (enableCxx) '' 176 + cp platform/c++/include/mupdf/*.h $out/include/mupdf 177 + cp build/*/libmupdfcpp.so $out/lib 178 + '') + (lib.optionalString (enablePython) ('' 179 + mkdir -p $out/${python3.sitePackages}/mupdf 180 + cp build/*/_mupdf.so $out/${python3.sitePackages} 181 + cp build/*/mupdf.py $out/${python3.sitePackages}/mupdf/__init__.py 182 + '' + lib.optionalString (stdenv.isDarwin) '' 183 + install_name_tool -add_rpath $out/lib $out/${python3.sitePackages}/_mupdf.so 184 + '')); 152 185 153 186 enableParallelBuilding = true; 154 187 ··· 156 189 tests = { 157 190 inherit cups-filters zathura; 158 191 inherit (python3.pkgs) pikepdf pymupdf; 192 + mupdf-all = mupdf.override { enableCurl = true; enableGL = true; enableOcr = true; enableCxx = true; enablePython = true; }; 159 193 }; 160 194 161 195 updateScript = gitUpdater { ··· 169 203 description = "Lightweight PDF, XPS, and E-book viewer and toolkit written in portable C"; 170 204 changelog = "https://git.ghostscript.com/?p=mupdf.git;a=blob_plain;f=CHANGES;hb=${version}"; 171 205 license = licenses.agpl3Plus; 172 - maintainers = with maintainers; [ vrthra fpletz ]; 206 + maintainers = with maintainers; [ vrthra fpletz lilyinstarlight ]; 173 207 platforms = platforms.unix; 174 208 mainProgram = "mupdf"; 175 209 };
+2 -1
pkgs/applications/misc/sioyek/default.nix
··· 58 58 59 59 postPatch = '' 60 60 substituteInPlace pdf_viewer_build_config.pro \ 61 - --replace "-lmupdf-threads" "-lgumbo -lharfbuzz -lfreetype -ljbig2dec -ljpeg -lopenjp2" 61 + --replace "-lmupdf-threads" "-lgumbo -lharfbuzz -lfreetype -ljbig2dec -ljpeg -lopenjp2" \ 62 + --replace "-lmupdf-third" "" 62 63 substituteInPlace pdf_viewer/main.cpp \ 63 64 --replace "/usr/share/sioyek" "$out/share" \ 64 65 --replace "/etc/sioyek" "$out/etc"
+4
pkgs/applications/misc/zathura/pdf-mupdf/default.nix
··· 41 41 42 42 PKG_CONFIG_ZATHURA_PLUGINDIR= "lib/zathura"; 43 43 44 + postPatch = '' 45 + sed -i -e '/^mupdfthird =/d' -e 's/, mupdfthird//g' meson.build 46 + ''; 47 + 44 48 passthru.updateScript = gitUpdater { 45 49 url = "https://git.pwmt.org/pwmt/zathura-pdf-mupdf.git"; 46 50 };
+1 -1
pkgs/applications/office/beamerpresenter/default.nix
··· 72 72 "-DUSE_POPPLER=${if usePoppler then "ON" else "OFF"}" 73 73 "-DUSE_MUPDF=${if useMupdf then "ON" else "OFF"}" 74 74 "-DUSE_QTPDF=OFF" 75 - "-DLINK_MUPDF_THIRD=ON" 75 + "-DLINK_MUPDF_THIRD=OFF" 76 76 "-DUSE_EXTERNAL_RENDERER=${if useExternalRenderer then "ON" else "OFF"}" 77 77 "-DLINK_MUJS=OFF" 78 78 "-DLINK_GUMBO=ON"
+4 -6
pkgs/desktops/arcan/arcan/default.nix
··· 1 1 { lib 2 2 , stdenv 3 3 , fetchFromGitHub 4 - , fetchgit 5 4 , SDL2 6 5 , cmake 7 6 , espeak ··· 21 20 , libXfixes 22 21 , libdrm 23 22 , libffi 23 + , libjpeg 24 24 , libusb1 25 25 , libuvc 26 26 , libvlc 27 27 , libvncserver 28 28 , libxcb 29 29 , libxkbcommon 30 - , lua5_1 31 - , luajit 32 30 , makeWrapper 33 31 , mesa 34 32 , mupdf 35 - , ninja 36 33 , openal 37 34 , openjpeg 38 35 , pcre2 ··· 121 118 libXfixes 122 119 libdrm 123 120 libffi 121 + libjpeg 124 122 libusb1 125 123 libuvc 126 124 libvlc ··· 128 126 libxcb 129 127 libxkbcommon 130 128 mesa 131 - mupdf.dev 129 + mupdf 132 130 openal 133 - openjpeg.dev 131 + openjpeg 134 132 pcre2 135 133 sqlite 136 134 tesseract
+56
pkgs/development/python-modules/libclang/default.nix
··· 1 + { lib 2 + , buildPythonPackage 3 + , llvmPackages 4 + , setuptools 5 + , writeText 6 + }: 7 + 8 + let 9 + libclang = llvmPackages.libclang; 10 + 11 + pyproject_toml = writeText "pyproject.toml" '' 12 + [build-system] 13 + requires = ["setuptools>=42", "wheel"] 14 + build-backend = "setuptools.build_meta" 15 + ''; 16 + 17 + setup_cfg = writeText "setup.cfg" '' 18 + [metadata] 19 + name = clang 20 + version = ${libclang.version} 21 + 22 + [options] 23 + packages = clang 24 + ''; 25 + in buildPythonPackage { 26 + pname = "libclang"; 27 + format = "pyproject"; 28 + 29 + inherit (libclang) version src; 30 + 31 + buildInputs = [ setuptools ]; 32 + 33 + postUnpack = '' 34 + # set source root to python bindings 35 + if [ -e "$sourceRoot/clang/bindings/python" ]; then 36 + # LLVM 13+ puts clang sources in subdirectory instead of plain tarball 37 + sourceRoot="$sourceRoot/clang/bindings/python" 38 + else 39 + sourceRoot="$sourceRoot/bindings/python" 40 + fi 41 + ''; 42 + 43 + postPatch = '' 44 + # link in our own build info to build as a python package 45 + ln -s ${pyproject_toml} ./pyproject.toml 46 + ln -s ${setup_cfg} ./setup.cfg 47 + 48 + # set passed libclang for runtime 49 + echo 'Config.set_library_path("${lib.getLib libclang}/lib")' >>./clang/cindex.py 50 + ''; 51 + 52 + meta = libclang.meta // { 53 + description = "Python bindings for the C language family frontend for LLVM"; 54 + maintainers = with lib.maintainers; [ lilyinstarlight ]; 55 + }; 56 + }
+46 -16
pkgs/development/python-modules/pymupdf/default.nix
··· 2 2 , stdenv 3 3 , buildPythonPackage 4 4 , pythonOlder 5 - , fetchPypi 5 + , fetchFromGitHub 6 + , pytestCheckHook 7 + , python 6 8 , swig 7 - , xcbuild 8 9 , mupdf 9 10 , freetype 10 11 , harfbuzz ··· 13 14 , libjpeg_turbo 14 15 , gumbo 15 16 , memstreamHook 17 + , fonttools 16 18 }: 17 19 18 - buildPythonPackage rec { 20 + let 21 + # PyMuPDF needs the C++ bindings generated 22 + mupdf-cxx = mupdf.override { enableOcr = true; enableCxx = true; enablePython = true; }; 23 + in buildPythonPackage rec { 19 24 pname = "pymupdf"; 20 - version = "1.23.3"; 25 + version = "1.23.6"; 21 26 format = "setuptools"; 22 27 23 28 disabled = pythonOlder "3.7"; 24 29 25 - src = fetchPypi { 26 - pname = "PyMuPDF"; 27 - inherit version; 28 - hash = "sha256-AhR4rmx26IWSQdu5cGEskIColX2L1pe7oLRTHcHPT4c="; 30 + src = fetchFromGitHub { 31 + owner = "pymupdf"; 32 + repo = "PyMuPDF"; 33 + rev = version; 34 + hash = "sha256-60KT5+EGP+s7HD4UIeaf9x2QVNU9IUbC5WKEJbrIBCI="; 29 35 }; 30 36 31 - postPatch = '' 32 - substituteInPlace setup.py \ 33 - --replace '/usr/include/mupdf' ${mupdf.dev}/include/mupdf 34 - ''; 35 37 nativeBuildInputs = [ 38 + pytestCheckHook 36 39 swig 37 - ] ++ lib.optionals stdenv.isDarwin [ 38 - xcbuild 39 40 ]; 40 41 41 42 buildInputs = [ 42 - mupdf 43 43 freetype 44 44 harfbuzz 45 45 openjpeg ··· 50 50 memstreamHook 51 51 ]; 52 52 53 - doCheck = false; 53 + propagatedBuildInputs = [ 54 + mupdf-cxx 55 + ]; 56 + 57 + env = { 58 + # force using system MuPDF (must be defined in environment and empty) 59 + PYMUPDF_SETUP_MUPDF_BUILD = ""; 60 + # provide MuPDF paths 61 + PYMUPDF_MUPDF_LIB = "${lib.getLib mupdf-cxx}/lib"; 62 + PYMUPDF_MUPDF_INCLUDE = "${lib.getDev mupdf-cxx}/include"; 63 + }; 64 + 65 + # TODO: manually add mupdf rpath until upstream fixes it 66 + postInstall = lib.optionalString stdenv.isDarwin '' 67 + for lib in */*.so $out/${python.sitePackages}/*/*.so; do 68 + install_name_tool -add_rpath ${lib.getLib mupdf-cxx}/lib "$lib" 69 + done 70 + ''; 71 + 72 + checkInputs = [ 73 + fonttools 74 + ]; 75 + 76 + disabledTests = [ 77 + # fails for indeterminate reasons 78 + "test_color_count" 79 + ] ++ lib.optionals stdenv.isDarwin [ 80 + # darwin does not support OCR right now 81 + "test_tesseract" 82 + ]; 54 83 55 84 pythonImportsCheck = [ 56 85 "fitz" 86 + "fitz_new" 57 87 ]; 58 88 59 89 meta = with lib; {
+4 -4
pkgs/development/tools/hotdoc/default.nix
··· 22 22 , setuptools 23 23 , toposort 24 24 , wheezy-template 25 - , libclang 25 + , llvmPackages 26 26 , gst_all_1 27 27 }: 28 28 ··· 100 100 postPatch = '' 101 101 substituteInPlace hotdoc/extensions/c/c_extension.py \ 102 102 --replace "shutil.which('llvm-config')" 'True' \ 103 - --replace "subprocess.check_output(['llvm-config', '--version']).strip().decode()" '"${libclang.version}"' \ 104 - --replace "subprocess.check_output(['llvm-config', '--prefix']).strip().decode()" '"${libclang.lib}"' \ 105 - --replace "subprocess.check_output(['llvm-config', '--libdir']).strip().decode()" '"${libclang.lib}/lib"' 103 + --replace "subprocess.check_output(['llvm-config', '--version']).strip().decode()" '"${llvmPackages.libclang.version}"' \ 104 + --replace "subprocess.check_output(['llvm-config', '--prefix']).strip().decode()" '"${llvmPackages.libclang.lib}"' \ 105 + --replace "subprocess.check_output(['llvm-config', '--libdir']).strip().decode()" '"${llvmPackages.libclang.lib}/lib"' 106 106 ''; 107 107 108 108 # Make pytest run from a temp dir to have it pick up installed package for cmark
+2
pkgs/top-level/python-packages.nix
··· 6145 6145 inherit (pkgs) libasyncns; 6146 6146 }; 6147 6147 6148 + libclang = callPackage ../development/python-modules/libclang { }; 6149 + 6148 6150 libcloud = callPackage ../development/python-modules/libcloud { }; 6149 6151 6150 6152 libcst = callPackage ../development/python-modules/libcst { };