import MaterialX fails on Windows after cmake --install of a shared-library build

Aperta
#3,129 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cmake, python
Ambito
build-system

Direzione di ricerca

Start with the install rules in CMakeLists.txt and python/CMakeLists.txt, then trace how the install prefix is used by the pip install step. Reproduce on Windows with a shared library build and Python enabled, then run python -c "import MaterialX" after installation. Done means the installed package can import successfully and cmake --install --prefix <other> installs Python files under the requested prefix.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Steps to reproduce

  1. On Windows, with Python 3.8 or later, configure with -DMATERIALX_BUILD_SHARED_LIBS=ON -DMATERIALX_BUILD_PYTHON=ON. MATERIALX_INSTALL_PYTHON defaults to ON.
  2. Run cmake --build build --config Release, then cmake --install build --config Release.
  3. Run python -c "import MaterialX" from a new shell:
ImportError: DLL load failed while importing PyMaterialXCore: The specified module could not be found.

Cause
The last install step runs pip install . in <prefix>/python. That copies the extension modules into site-packages, but not the MaterialX DLLs they depend on, which are in <prefix>/bin. Since Python 3.8, Windows doesn't search PATH for an extension module's DLL dependencies. MaterialX/__init__.py has a fallback that calls os.add_dll_directory(<prefix>/bin), but it only runs when the package has no pip metadata, so it never runs for the copy pip installed. Wheels aren't affected, because pyproject.toml forces static libraries.

CI doesn't catch this, because the Windows_VS2022_x64_SharedLibs job runs with python: None.

A related problem with --prefix
The pip install step and python/CMakeLists.txt, which writes pyproject.toml directly into the install prefix, both use the prefix from configure time. So cmake --install --prefix <other> runs pip in the original install folder instead of the requested one.

Proposed fix
For Windows shared builds, copy the DLLs from <prefix>/bin into <prefix>/python/MaterialX before pip runs, so the installed package is self-contained. That's the same idea as delvewheel, minus the renaming of the DLLs. Also resolve the prefix at install time, and install pyproject.toml with an install rule. This is in use on our fork: https://github.com/metashade/MaterialX/pull/102. It adds about 180 MB to site-packages with the Slang libraries enabled. I can open a PR against main.

Related: #2503.

Lingua principale
C++
Stelle
2.3k
Fork
472
Merge medio
1g 4h
PR unite (30g)
7

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di AcademySoftwareFoundation/MaterialX

Tutte le issue di AcademySoftwareFoundation/MaterialX

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.