Delocate/auditwheel, but for Windows?`

I’m trying to wrap a poppler utility using pybind11, and getting up to speed on packaging C extensions (that have shared library dependencies) in the process. It was relatively easy to build Linux/macOS wheels compared to Windows ones, but this week I was able to build Windows wheels thanks to all the replies in this post (and all the linked posts)! I’m using cibuildwheel to build the wheels using GitHub Actions, vcpkg to install the external shared libraries, and a wheel_repair.py to copy the shared library DLLs into the wheel. wheel_repair.py follows a scoped down version of the workflow that @njs described in this post:

  • Look for a PYD file in the wheel
  • Get the DLL dependencies (both direct and transitive) for that PYD file using pefile, and look for them in the vcpkg directory
  • Mangle the DLL names using their sha256 hash (using the same function as auditwheel) and copy them into the wheel directory (alongside the PYD file)
  • Modify the PYD import table with the new mangled DLL names using machomachomangler by Nathaniel (and also do this for each DLL which depends on other mangled DLLs)

There are some limitations to this approach, (1) it assumes that there’s just one PYD file in the wheel which might not be the case for complex projects but works for my simple extension, and (2) it doesn’t look for DLLs in system directories (as I wasn’t sure what all directories to look into).

The built Windows wheel worked on my machine but I need to test it on a fresh Windows instance to see if I need to bundle any other DLLs.

I wanted to ask you all if this is an ok approach to bundle DLLs within a Windows wheel, if the wheels would work on Windows versions older than 10, and if there’s anything that I might’ve missed or could improve. @steve.dower I would love to have your advice on this! And if you have some more time, could you please look at the DLL imports (Dependencies tool output as a GitHub gist) for my compiled PYD file and tell me if I need to bundle any other system DLLs apart from freetype, libpng16, jpeg62 (and all of their DLL dependencies that I install using vcpkg)?

I’ve also documented my experience building Windows wheels for others looking to do the same. Here are the blog posts in reverse chronological order:

1 Like