(
mupdf_local,
build_type,
overwrite_config,
g_py_limited_api,
PYMUPDF_SETUP_MUPDF_REFCHECK_IF,
PYMUPDF_SETUP_MUPDF_TRACE_IF,
)
| 788 | |
| 789 | |
| 790 | def build_mupdf_windows( |
| 791 | mupdf_local, |
| 792 | build_type, |
| 793 | overwrite_config, |
| 794 | g_py_limited_api, |
| 795 | PYMUPDF_SETUP_MUPDF_REFCHECK_IF, |
| 796 | PYMUPDF_SETUP_MUPDF_TRACE_IF, |
| 797 | ): |
| 798 | |
| 799 | assert mupdf_local |
| 800 | mupdf_version_tuple = get_mupdf_version(mupdf_local) |
| 801 | log(f'{overwrite_config=}') |
| 802 | log(f'{mupdf_version_tuple=}') |
| 803 | wp = pipcl.wdev.WindowsPython() |
| 804 | tesseract = '' if os.environ.get('PYMUPDF_SETUP_MUPDF_TESSERACT') == '0' else 'tesseract-' |
| 805 | windows_build_tail = f'build\\shared-{tesseract}{build_type}' |
| 806 | |
| 807 | if overwrite_config: |
| 808 | if mupdf_version_tuple >= (1, 28): |
| 809 | # Tell mupdf build to use, for example, `/Build "ReleaseTofuCjkExt|x64"`. |
| 810 | # This avoids the need for us to modify mupdf's config.h. |
| 811 | windows_build_tail += '-TOFU_CJK_EXT' |
| 812 | log(f'Appending, {windows_build_tail=}') |
| 813 | else: |
| 814 | log(f'modifying mupdf:include/mupdf/fitz/config.h') |
| 815 | mupdf_config_h = f'{mupdf_local}/include/mupdf/fitz/config.h' |
| 816 | prefix = '#define TOFU_CJK_EXT 1 /* PyMuPDF override. */\n' |
| 817 | with open(mupdf_config_h) as f: |
| 818 | text = f.read() |
| 819 | if text.startswith(prefix): |
| 820 | log(f'Not modifying {mupdf_config_h} because already has prefix {prefix!r}.') |
| 821 | else: |
| 822 | log(f'Prefixing {mupdf_config_h} with {prefix!r}.') |
| 823 | text = prefix + text |
| 824 | st = os.stat(mupdf_config_h) |
| 825 | with open(mupdf_config_h, 'w') as f: |
| 826 | f.write(text) |
| 827 | os.utime(mupdf_config_h, (st.st_atime, st.st_mtime)) |
| 828 | |
| 829 | if g_py_limited_api: |
| 830 | windows_build_tail += f'-Py_LIMITED_API_{pipcl.current_py_limited_api()}' |
| 831 | windows_build_tail += f'-x{wp.cpu.bits}-py{wp.version}' |
| 832 | windows_build_dir = f'{mupdf_local}\\{windows_build_tail}' |
| 833 | #log( f'Building mupdf.') |
| 834 | devenv = os.environ.get('PYMUPDF_SETUP_DEVENV') |
| 835 | if not devenv: |
| 836 | try: |
| 837 | # Prefer VS-2022 as that is what Github provide in windows-2022. |
| 838 | log(f'Looking for Visual Studio 2022.') |
| 839 | vs = pipcl.wdev.WindowsVS(year=2022) |
| 840 | except Exception as e: |
| 841 | log(f'Failed to find VS-2022:\n' |
| 842 | f'{textwrap.indent(traceback.format_exc(), " ")}' |
| 843 | ) |
| 844 | log(f'Looking for any Visual Studio.') |
| 845 | vs = pipcl.wdev.WindowsVS() |
| 846 | log(f'vs:\n{vs.description_ml(" ")}') |
| 847 | devenv = vs.devenv |
no test coverage detected
searching dependent graphs…