Repository navigation
Bundle DLLs with the pip-installed package for Windows shared builds - #102
Conversation
Python 3.8+ doesn't search PATH for the DLLs that extension modules depend on. With MATERIALX_BUILD_SHARED_LIBS=ON, the install step pip installs the Python package without the MaterialX DLLs, and __init__.py skips adding the bin folder for pip-installed packages, so importing MaterialX fails. Copy the DLLs from the bin folder into the package before running pip. Signed-off-by: Pavlo Penenko <pavlo.penenko@autodesk.com>
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
What changed in this PR
Ensures pip install . performed during cmake --install on Windows shared-library builds produces a self-contained Python package by bundling required runtime DLLs alongside the installed extension modules.
Changes:
- Add an install-time step (Windows + shared libs) to copy
bin/*.dllinto the Python package staging area before runningpip install .. - Keep the existing final
pip install .step after installation completes.
| File | Description |
|---|---|
| CMakeLists.txt | Adds an install-time DLL bundling step for Windows shared builds so pip-installed packages can import successfully. |
Review effort: Lite
Lets cmake --install --prefix copy the DLLs and run pip in the same, requested location. Signed-off-by: Pavlo Penenko <pavlo.penenko@autodesk.com>
There was a problem hiding this comment.
🟡 Changes recommended
Installing with an alternate --prefix runs pip in a directory missing pyproject.toml because that file remains at the configure-time prefix, preventing Python package installation.
1 open issue
3 resolved since last review
Review effort: Balanced
| file(COPY \${MATERIALX_RUNTIME_DLLS} DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${MATERIALX_PYTHON_FOLDER_NAME}\") | ||
| endif()") | ||
| endif() | ||
| install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install . WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/python\")") |
There was a problem hiding this comment.
Good catch, fixed in the next commit: pyproject.toml is now generated in the build tree and installed into python, so it follows the install-time prefix. Tested with cmake --install build --config Release --prefix <scratch dir>: pyproject.toml and the DLLs land there and pip installs from there.
pip now runs in the install-time prefix, so pyproject.toml has to be there too when installing with cmake --install --prefix. Signed-off-by: Pavlo Penenko <pavlo.penenko@autodesk.com>


With
MATERIALX_BUILD_SHARED_LIBS=ONon Windows,import MaterialXfails aftercmake --install:The install step runs
pip install .on<prefix>/python, which copies the extension modules into site-packages but not the DLLs in<prefix>/bin. Python 3.8+ doesn't searchPATHfor an extension module's dependencies, and the fallback inMaterialX/__init__.pythat adds<prefix>/binwithos.add_dll_directoryonly runs when the package has no pip metadata, so it never runs for this copy. Wheels aren't affected becausepyproject.tomlforces static libraries.This copies the DLLs from
bininto the package before pip runs, so the installed package is self-contained, like the wheels thatdelvewheelproduces. With the current build options that adds about 184 MB to site-packages, mostly the Slang libraries.Tested by reconfiguring an existing shared build, running
cmake --install build --config Release, and importingMaterialX,PyMaterialXGenGlslandPyMaterialXRenderGlslfrom a plain shell.I plan to report this upstream with the same fix.