Skip to content

Commit

Permalink
Added support for Py_LIMITED_API to generates Python bindings that wo…
Browse files Browse the repository at this point in the history
…rk with

all Python versions.

Also involves a small change to name of SWIG-generated .cpp file,
so docs have also been updated with the new name. Also removed some
docs from scripts/wrap/__main__.py that duplicated information in
docs/src/language-bindings.rst.

Changed Windows builds of the Python and C# bindings to use direct invocation
of cl.exe and link.exe instead of using devenv to run .vcxproj files, so that
we can more easily control compiler/linker flags.
  • Loading branch information
julian-smith-artifex-com committed Sep 17, 2024
1 parent b426d88 commit c7ef722
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 141 deletions.
10 changes: 5 additions & 5 deletions docs/src/language-bindings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ General requirements

*
`libclang Python interface onto
<https://libclang.readthedocs.io/en/latest/index.html>`_ the `libclang
<https://libclang.readthedocs.io/en/latest/index.html>`_ the `clang
C/C++ parser <https://clang.llvm.org/>`_.

* `swig <https://swig.org/>`_, for Python and C# bindings.
Expand Down Expand Up @@ -948,7 +948,7 @@ All generated files are within the MuPDF checkout.
functions.h
internal.h
implementation/ [MuPDF C++ implementation source files.]
implementation/ [MuPDF C++ implementation source files.]
classes.cpp
classes2.cpp
exceptions.cpp
Expand All @@ -959,13 +959,13 @@ All generated files are within the MuPDF checkout.
windows_mupdf.def [List of MuPDF public global data, used when linking mupdfcpp.dll.]
python/ [SWIG Python files.]
mupdfcpp_swig.cpp [SWIG output file.]
mupdfcpp_swig.i [SWIG input file.]
mupdfcpp_swig.i.cpp [SWIG output file.]
csharp/ [SWIG C# files.]
mupdf.cs [SWIG output file, no out-params helpers.]
mupdfcpp_swig.cpp [SWIG output file.]
mupdfcpp_swig.i [SWIG input file.]
mupdfcpp_swig.i.cpp [SWIG output file.]
win32/
Release/ [Windows 32-bit .dll, .lib, .exp, .pdb etc.]
Expand Down Expand Up @@ -998,7 +998,7 @@ both in `mupdfcpp.dll`, which is built by running devenv on
`platform/win32/mupdf.sln`.

The Python SWIG library is called `_mupdf.pyd` which, despite the name, is a
standard Windows DLL, built from `platform/python/mupdfcpp_swig.cpp`.
standard Windows DLL, built from `platform/python/mupdfcpp_swig.i.cpp`.

DLL export of functions and data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion platform/win32/mupdfcsharpswig.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\csharp\mupdfcpp_swig.cpp">
<ClCompile Include="..\csharp\mupdfcpp_swig.i.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Disabled|Win32'">true</ExcludedFromBuild>
</ClCompile>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion platform/win32/mupdfpyswig.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\python\mupdfcpp_swig.cpp">
<ClCompile Include="..\python\mupdfcpp_swig.i.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Disabled|Win32'">true</ExcludedFromBuild>
</ClCompile>
</ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions scripts/mupdfwrap_test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ public static void Main(string[] args)
{
System.Console.WriteLine("MuPDF C# test starting.");

// Check FZ_ENABLE_FB2.
System.Console.WriteLine("FZ_VERSION=" + mupdf.mupdf.FZ_VERSION);
System.Console.WriteLine("FZ_ENABLE_FB2=" + mupdf.mupdf.FZ_ENABLE_FB2);

// Check we can load a document.
mupdf.FzDocument document = new mupdf.FzDocument("zlib.3.pdf");
System.Console.WriteLine("document: " + document);
Expand Down
1 change: 1 addition & 0 deletions scripts/mupdfwrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ def olog(text):

if __name__ == '__main__':

print(f'{mupdf.Py_LIMITED_API=}', flush=1)
paths = sys.argv[1:]
if not paths:
paths = [
Expand Down
2 changes: 2 additions & 0 deletions scripts/wdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ class WindowsPython:
.cpu:
A `WindowsCpu` instance, same as `cpu` passed to `__init__()` if
not None, otherwise the inferred cpu.
.libs:
Python libs directory.
We parse the output from `py -0p` to find all available python
installations.
Expand Down
Loading

0 comments on commit c7ef722

Please sign in to comment.