Skip to content

Bundle DLLs with the pip-installed package for Windows shared builds - #102

Merged
ppenenko merged 3 commits into
metashade/devfrom
metashade/win-shared-python-dlls-dev
Nov 10, 2026
Merged

ppenenko merged 3 commits into
metashade/devfrom
metashade/win-shared-python-dlls-dev

Conversation

@ppenenko

Copy link
Copy Markdown
Member

With MATERIALX_BUILD_SHARED_LIBS=ON on Windows, import MaterialX fails after cmake --install:

ImportError: DLL load failed while importing PyMaterialXCore: The specified module could not be found.

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 search PATH for an extension module's dependencies, and the fallback in MaterialX/__init__.py that adds <prefix>/bin with os.add_dll_directory only runs when the package has no pip metadata, so it never runs for this copy. Wheels aren't affected because pyproject.toml forces static libraries.

This copies the DLLs from bin into the package before pip runs, so the installed package is self-contained, like the wheels that delvewheel produces. 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 importing MaterialX, PyMaterialXGenGlsl and PyMaterialXRenderGlsl from a plain shell.

I plan to report this upstream with the same fix.

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>
@ppenenko
ppenenko requested a balanced review from Copilot November 10, 2026 19:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/*.dll into the Python package staging area before running pip 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

Comment thread CMakeLists.txt Resolved
Comment thread CMakeLists.txt Resolved
Comment thread CMakeLists.txt Resolved
@ppenenko ppenenko closed this Nov 10, 2026
@ppenenko ppenenko reopened this Nov 10, 2026
Lets cmake --install --prefix copy the DLLs and run pip in the same,
requested location.

Signed-off-by: Pavlo Penenko <pavlo.penenko@autodesk.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread CMakeLists.txt
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\")")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the Windows packaging changes.

1 open issue

Review effort: Balanced

@ppenenko
ppenenko merged commit 1c18243 into metashade/dev Nov 10, 2026
35 of 37 checks passed
@ppenenko
ppenenko deleted the metashade/win-shared-python-dlls-dev branch November 10, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants