From 40dc82c7cd7d1350d65a68c504ddff30a51fa690 Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Wed, 18 Sep 2024 17:58:29 -0400 Subject: [PATCH 1/6] mupdf: fix cxx build on darwin --- .../misc/mupdf/0002-Add-Darwin-deps.patch | 57 ------------------ pkgs/applications/misc/mupdf/default.nix | 8 ++- ...ix-cpp-build.patch => fix-cpp-build.patch} | 0 .../misc/mupdf/fix-darwin-system-deps.patch | 60 +++++++++++++++++++ 4 files changed, 66 insertions(+), 59 deletions(-) delete mode 100644 pkgs/applications/misc/mupdf/0002-Add-Darwin-deps.patch rename pkgs/applications/misc/mupdf/{0003-Fix-cpp-build.patch => fix-cpp-build.patch} (100%) create mode 100644 pkgs/applications/misc/mupdf/fix-darwin-system-deps.patch diff --git a/pkgs/applications/misc/mupdf/0002-Add-Darwin-deps.patch b/pkgs/applications/misc/mupdf/0002-Add-Darwin-deps.patch deleted file mode 100644 index 2fe1a4afd9fd..000000000000 --- a/pkgs/applications/misc/mupdf/0002-Add-Darwin-deps.patch +++ /dev/null @@ -1,57 +0,0 @@ -From 0f0ccfc01cfe72d96eafee57ec6c5107f09c7238 Mon Sep 17 00:00:00 2001 -From: toonn -Date: Wed, 9 Mar 2022 00:08:28 +0100 -Subject: [PATCH 2/2] Add Darwin deps - ---- - Makerules | 34 ++++++++++++++++++++++++++++++++++ - 1 file changed, 34 insertions(+) - -diff --git a/Makerules b/Makerules -index 6d52cca..a6bd0ed 100644 ---- a/Makerules -+++ b/Makerules -@@ -153,6 +153,40 @@ else ifeq ($(OS),MACOS) - LIBCRYPTO_CFLAGS := $(shell pkg-config --cflags libcrypto) -DHAVE_LIBCRYPTO - LIBCRYPTO_LIBS := $(shell pkg-config --libs libcrypto) - endif -+ # Required for mupdf-gl -+ ifeq ($(shell pkg-config --exists harfbuzz && echo yes),yes) -+ SYS_HARFBUZZ_CFLAGS := $(shell pkg-config --cflags harfbuzz) -+ SYS_HARFBUZZ_LIBS := $(shell pkg-config --libs harfbuzz) -+ endif -+ ifeq ($(shell pkg-config --exists libopenjp2 && echo yes),yes) -+ SYS_OPENJPEG_CFLAGS := $(shell pkg-config --cflags libopenjp2) -+ SYS_OPENJPEG_LIBS := $(shell pkg-config --libs libopenjp2) -+ endif -+ ifeq ($(shell pkg-config --exists freetype2 && echo yes),yes) -+ SYS_FREETYPE_CFLAGS := $(shell pkg-config --cflags freetype2) -+ SYS_FREETYPE_LIBS := $(shell pkg-config --libs freetype2) -+ endif -+ ifeq ($(shell pkg-config --exists gumbo && echo yes),yes) -+ SYS_GUMBO_CFLAGS := $(shell pkg-config --cflags gumbo) -+ SYS_GUMBO_LIBS := $(shell pkg-config --libs gumbo) -+ endif -+ # Required for mupdf-x11 -+ HAVE_X11 := $(shell pkg-config --exists x11 xext && echo yes) -+ ifeq ($(HAVE_X11),yes) -+ X11_CFLAGS := $(shell pkg-config --cflags x11 xext) -+ X11_LIBS := $(shell pkg-config --libs x11 xext) -+ endif -+ # Required for mupdf-x11-curl -+ HAVE_SYS_CURL := $(shell pkg-config --exists libcurl && echo yes) -+ ifeq ($(HAVE_SYS_CURL),yes) -+ SYS_CURL_CFLAGS := $(shell pkg-config --cflags libcurl) -+ SYS_CURL_LIBS := $(shell pkg-config --libs libcurl) -+ endif -+ HAVE_PTHREAD := yes -+ ifeq ($(HAVE_PTHREAD),yes) -+ PTHREAD_CFLAGS := -+ PTHREAD_LIBS := -lpthread -+ endif - endif - - else ifeq ($(OS),Linux) --- -2.17.2 (Apple Git-113) - diff --git a/pkgs/applications/misc/mupdf/default.nix b/pkgs/applications/misc/mupdf/default.nix index b54d9dd86157..6eacfd6bde87 100644 --- a/pkgs/applications/misc/mupdf/default.nix +++ b/pkgs/applications/misc/mupdf/default.nix @@ -69,8 +69,12 @@ stdenv.mkDerivation rec { }; patches = [ - ./0002-Add-Darwin-deps.patch - ./0003-Fix-cpp-build.patch + # Upstream makefile does not work with system deps on macOS by default, so + # we reuse the Linux section instead. + ./fix-darwin-system-deps.patch + # Upstream C++ wrap script only defines fixed-sized integers on macOS but + # this is required on aarch64-linux too. + ./fix-cpp-build.patch ]; postPatch = '' diff --git a/pkgs/applications/misc/mupdf/0003-Fix-cpp-build.patch b/pkgs/applications/misc/mupdf/fix-cpp-build.patch similarity index 100% rename from pkgs/applications/misc/mupdf/0003-Fix-cpp-build.patch rename to pkgs/applications/misc/mupdf/fix-cpp-build.patch diff --git a/pkgs/applications/misc/mupdf/fix-darwin-system-deps.patch b/pkgs/applications/misc/mupdf/fix-darwin-system-deps.patch new file mode 100644 index 000000000000..4a170b4c1d06 --- /dev/null +++ b/pkgs/applications/misc/mupdf/fix-darwin-system-deps.patch @@ -0,0 +1,60 @@ +diff --git a/Makerules b/Makerules +index f582dc061..2da5680b6 100644 +--- a/Makerules ++++ b/Makerules +@@ -178,39 +178,20 @@ ifneq "$(CLUSTER)" "" + endif + + ifeq ($(OS),Linux) +- LINUX_OR_OPENBSD := yes ++ LINUX_OR_OPENBSD_OR_MACOS := yes + endif + ifeq ($(OS),OpenBSD) +- LINUX_OR_OPENBSD := yes ++ LINUX_OR_OPENBSD_OR_MACOS := yes ++endif ++ifeq ($(OS),MACOS) ++ LINUX_OR_OPENBSD_OR_MACOS := yes + endif + + ifeq ($(OS),MINGW) + WINDRES := windres + HAVE_WIN32 := yes + +-else ifeq ($(OS),MACOS) +- HAVE_GLUT := yes +- SYS_GLUT_CFLAGS := -Wno-deprecated-declarations +- SYS_GLUT_LIBS := -framework GLUT -framework OpenGL +- CC = xcrun cc +- AR = xcrun ar +- LD = xcrun ld +- RANLIB = xcrun ranlib +- +- ifneq ($(ARCHFLAGS),) +- $(warning "MacOS with ARCHFLAGS set. Assuming we are building for arm64, and setting HAVE_LIBCRYPTO to no.") +- HAVE_LIBCRYPTO := no +- else ifeq (, $(shell command -v pkg-config)) +- $(warning "No pkg-config found, install it for proper integration of libcrypto") +- else +- HAVE_LIBCRYPTO := $(shell pkg-config --exists 'libcrypto >= 1.1.0' && echo yes) +- ifeq ($(HAVE_LIBCRYPTO),yes) +- LIBCRYPTO_CFLAGS := $(shell pkg-config --cflags libcrypto) -DHAVE_LIBCRYPTO +- LIBCRYPTO_LIBS := $(shell pkg-config --libs libcrypto) +- endif +- endif +- +-else ifeq ($(LINUX_OR_OPENBSD),yes) ++else ifeq ($(LINUX_OR_OPENBSD_OR_MACOS),yes) + + ifeq ($(OS),Linux) + HAVE_OBJCOPY := yes +@@ -274,6 +255,9 @@ else ifeq ($(LINUX_OR_OPENBSD),yes) + ifeq ($(OS),OpenBSD) + SYS_GLUT_CFLAGS := $(shell pkg-config --cflags glut gl) + SYS_GLUT_LIBS := $(shell pkg-config --libs glut gl) ++ else ifeq ($(OS),MACOS) ++ SYS_GLUT_CFLAGS := -Wno-deprecated-declarations ++ SYS_GLUT_LIBS := -framework GLUT -framework OpenGL + else + SYS_GLUT_CFLAGS := + SYS_GLUT_LIBS := -lglut -lGL From 41f9b5724bed9d4f5423e98087997523aa32f021 Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Wed, 18 Sep 2024 17:58:43 -0400 Subject: [PATCH 2/6] mupdf: fix soname hell and python bindings import --- pkgs/applications/misc/mupdf/default.nix | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkgs/applications/misc/mupdf/default.nix b/pkgs/applications/misc/mupdf/default.nix index 6eacfd6bde87..baff543c38ef 100644 --- a/pkgs/applications/misc/mupdf/default.nix +++ b/pkgs/applications/misc/mupdf/default.nix @@ -59,6 +59,7 @@ let }); in + stdenv.mkDerivation rec { version = "1.24.8"; pname = "mupdf"; @@ -103,7 +104,7 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ pkg-config ] ++ lib.optional (enableGL || enableX11) copyDesktopItems ++ lib.optional (stdenv.isDarwin && (enableGL || enableX11)) desktopToDarwinBundle - ++ lib.optionals (enableCxx || enablePython) [ python3 python3.pkgs.setuptools python3.pkgs.libclang ] + ++ lib.optionals (enableCxx || enablePython) [ (python3.pythonOnBuildForHost.withPackages (ps: [ ps.setuptools ps.libclang ])) ] ++ lib.optionals (enablePython) [ which swig ] ++ lib.optionals stdenv.isDarwin [ fixDarwinDylibNames xcbuild ]; @@ -118,6 +119,7 @@ stdenv.mkDerivation rec { ) ++ lib.optionals enableOcr [ leptonica tesseract ] ; + outputs = [ "bin" "dev" "out" "man" "doc" ]; preConfigure = '' @@ -170,7 +172,6 @@ stdenv.mkDerivation rec { EOF moveToOutput "bin" "$bin" - cp ./build/shared-release/libmupdf${stdenv.hostPlatform.extensions.sharedLibrary}* $out/lib '' + (lib.optionalString (stdenv.isDarwin) '' for exe in $bin/bin/*; do install_name_tool -change build/shared-release/libmupdf.dylib $out/lib/libmupdf.dylib "$exe" @@ -184,17 +185,19 @@ stdenv.mkDerivation rec { ln -s "$bin/bin/mupdf-x11" "$bin/bin/mupdf" '') + (lib.optionalString (enableCxx) '' cp platform/c++/include/mupdf/*.h $out/include/mupdf - cp build/*/libmupdfcpp.so* $out/lib + cp build/*/libmupdfcpp.so $out/lib '') + (lib.optionalString (enablePython) ('' mkdir -p $out/${python3.sitePackages}/mupdf - cp build/*/_mupdf.so $out/${python3.sitePackages} + cp build/*/_mupdf.so $out/${python3.sitePackages}/mupdf cp build/*/mupdf.py $out/${python3.sitePackages}/mupdf/__init__.py '' + lib.optionalString (stdenv.isDarwin) '' - install_name_tool -add_rpath $out/lib $out/${python3.sitePackages}/_mupdf.so + install_name_tool -add_rpath $out/lib $out/${python3.sitePackages}/mupdf/_mupdf.so '')); enableParallelBuilding = true; + env.USE_SONAME = "no"; + passthru = { tests = { inherit cups-filters zathura; @@ -216,8 +219,5 @@ stdenv.mkDerivation rec { maintainers = with maintainers; [ fpletz ]; platforms = platforms.unix; mainProgram = "mupdf"; - # ImportError: cannot import name '_mupdf' from partially initialized module 'mupdf' - # (most likely due to a circular import) - broken = enablePython; }; } From 53313da4ea166c63d11639d6e5666a3db6bc282c Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Wed, 18 Sep 2024 19:54:48 -0400 Subject: [PATCH 3/6] mupdf: 1.24.8 -> 1.24.9 --- pkgs/applications/misc/mupdf/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/misc/mupdf/default.nix b/pkgs/applications/misc/mupdf/default.nix index baff543c38ef..3086dc07baac 100644 --- a/pkgs/applications/misc/mupdf/default.nix +++ b/pkgs/applications/misc/mupdf/default.nix @@ -61,12 +61,12 @@ let in stdenv.mkDerivation rec { - version = "1.24.8"; + version = "1.24.9"; pname = "mupdf"; src = fetchurl { url = "https://mupdf.com/downloads/archive/${pname}-${version}-source.tar.gz"; - hash = "sha256-pRjZvpds2yAG1FOC1/+xubjWS8P9PLc8picNdS+n9Eg="; + hash = "sha256-C0RqoO7MEU6ZadzNcMl4k1j8y2WJqB1HDclBoIdNqYo="; }; patches = [ From 9c4bcdc56c13051de642165e2cf6f470d7d03e12 Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Wed, 18 Sep 2024 19:57:05 -0400 Subject: [PATCH 4/6] python3Packages.pymupdf: 1.24.8 -> 1.24.10 --- pkgs/development/python-modules/pymupdf/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/python-modules/pymupdf/default.nix b/pkgs/development/python-modules/pymupdf/default.nix index f54a8b7a8462..87178c461693 100644 --- a/pkgs/development/python-modules/pymupdf/default.nix +++ b/pkgs/development/python-modules/pymupdf/default.nix @@ -40,7 +40,7 @@ let in buildPythonPackage rec { pname = "pymupdf"; - version = "1.24.8"; + version = "1.24.10"; pyproject = true; disabled = pythonOlder "3.7"; @@ -49,7 +49,7 @@ buildPythonPackage rec { owner = "pymupdf"; repo = "PyMuPDF"; rev = "refs/tags/${version}"; - hash = "sha256-NG4ZJYMYTQHiqpnaOz7hxf5UW417UKawe5EqXaBnKJ8="; + hash = "sha256-QAcQPWzPTnTg3l5lGJ8me4FUbK7xgXgyYHep+rF3wf4="; }; # swig is not wrapped as Python package From 3d0c8d963a228c03ef6d0e621013ed1c69fc6aa3 Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Wed, 18 Sep 2024 20:11:55 -0400 Subject: [PATCH 5/6] pymupdf-fonts: init at 1.0.5 --- .../python-modules/pymupdf-fonts/default.nix | 31 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 1 + 2 files changed, 32 insertions(+) create mode 100644 pkgs/development/python-modules/pymupdf-fonts/default.nix diff --git a/pkgs/development/python-modules/pymupdf-fonts/default.nix b/pkgs/development/python-modules/pymupdf-fonts/default.nix new file mode 100644 index 000000000000..b50e49e703de --- /dev/null +++ b/pkgs/development/python-modules/pymupdf-fonts/default.nix @@ -0,0 +1,31 @@ +{ + lib, + buildPythonPackage, + fetchPypi, + setuptools, +}: + +buildPythonPackage rec { + pname = "pymupdf-fonts"; + version = "1.0.5"; + pyproject = true; + + src = fetchPypi { + pname = "pymupdf_fonts"; + inherit version; + hash = "sha256-rBLj7Er/o16aCsopE170HCO9vldYwzVdrCNphjCea8Y="; + }; + + build-system = [ + setuptools + ]; + + pythonImportsCheck = [ "pymupdf_fonts" ]; + + meta = { + description = "Collection of optional fonts for PyMuPDF"; + homepage = "https://github.com/pymupdf/pymupdf-fonts"; + license = lib.licenses.ofl; + maintainers = [ ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 2c4b0027a301..48cd1fc57947 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -11655,6 +11655,7 @@ self: super: with self; { }; pymupdf = callPackage ../development/python-modules/pymupdf { }; + pymupdf-fonts = callPackage ../development/python-modules/pymupdf-fonts { }; pymvglive = callPackage ../development/python-modules/pymvglive { }; From 65564f03966f09c0f05d47d586474a83b1082916 Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Wed, 18 Sep 2024 17:59:01 -0400 Subject: [PATCH 6/6] python3Packages.pymupdf: clean up checks and testing exceptions --- .../python-modules/pymupdf/default.nix | 111 ++++-------------- 1 file changed, 25 insertions(+), 86 deletions(-) diff --git a/pkgs/development/python-modules/pymupdf/default.nix b/pkgs/development/python-modules/pymupdf/default.nix index 87178c461693..21b4a6f2b869 100644 --- a/pkgs/development/python-modules/pymupdf/default.nix +++ b/pkgs/development/python-modules/pymupdf/default.nix @@ -25,8 +25,10 @@ mupdf, # tests - fonttools, pytestCheckHook, + fonttools, + pillow, + pymupdf-fonts, }: let @@ -96,97 +98,34 @@ buildPythonPackage rec { nativeCheckInputs = [ pytestCheckHook + ]; + + checkInputs = [ fonttools + pillow + pymupdf-fonts + ]; + + disabledTests = [ + # Do not lint code + "test_codespell" + "test_pylint" + "test_flake8" + # Upstream recommends disabling these when not using bundled MuPDF build + "test_color_count" + "test_3050" + "test_textbox3" + ]; + + pythonImportsCheck = [ + "pymupdf" + "fitz" ]; preCheck = '' - export PATH="$PATH:$out/bin"; + export PATH="$out/bin:$PATH"; ''; - disabledTests = - [ - # Fails in release tarballs without .git - "test_codespell" - "test_pylint" - # fails for indeterminate reasons - "test_2548" - "test_2753" - "test_3020" - "test_3050" - "test_3058" - "test_3177" - "test_3186" - "test_color_count" - "test_pilsave" - "test_fz_write_pixmap_as_jpeg" - # NotImplementedError - "test_1824" - "test_2093" - "test_2093" - "test_2108" - "test_2182" - "test_2182" - "test_2246" - "test_2270" - "test_2270" - "test_2391" - "test_2788" - "test_2861" - "test_2871" - "test_2886" - "test_2904" - "test_2922" - "test_2934" - "test_2957" - "test_2969" - "test_3070" - "test_3131" - "test_3140" - "test_3209" - "test_3209" - "test_3301" - "test_3347" - "test_caret" - "test_deletion" - "test_file_info" - "test_line" - "test_page_links_generator" - "test_polyline" - "test_redact" - "test_techwriter_append" - "test_text2" - # Issue with FzArchive - "test_htmlbox" - "test_2246" - "test_3140" - "test_3400" - "test_707560" - "test_open" - "test_objectstream1" - "test_objectstream2" - "test_objectstream3" - "test_fit_springer" - "test_write_stabilized_with_links" - "test_textbox" - "test_delete_image" - # Fonts not available - "test_fontarchive" - "test_subset_fonts" - # Exclude lint tests - "test_flake8" - ] - ++ lib.optionals stdenv.isDarwin [ - # darwin does not support OCR right now - "test_tesseract" - ]; - - disabledTestPaths = [ - # Issue with FzArchive - "tests/test_docs_samples.py" - ]; - - pythonImportsCheck = [ "fitz" ]; - meta = { description = "Python bindings for MuPDF's rendering library"; homepage = "https://github.com/pymupdf/PyMuPDF";