From 2078b721de488dc598b22b1a1140c472ee84d3c9 Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Thu, 19 Oct 2023 16:38:50 +0300 Subject: [PATCH] WIP: Refactor Windows DLL path handling --- .cibw/merge-wheels.py | 4 ++++ .cibw/mpi4py_mpiabi.py | 38 ++++++++++++++++++++++++++++++++++ .github/workflows/cd-wheel.yml | 18 ++++++++-------- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/.cibw/merge-wheels.py b/.cibw/merge-wheels.py index 81de692..0a68e8d 100644 --- a/.cibw/merge-wheels.py +++ b/.cibw/merge-wheels.py @@ -142,6 +142,10 @@ def wheel_tagline(tags: list[str]) -> str: fh.write("# Register MPI ABI variants\n") for variant in variant_registry: fh.write(f"_mpiabi._register({variant!r})\n") + mpi_pth = root_dir / "mpi.pth" + if mpi_pth.exists(): + fh.write("_mpiabi._bootstrap_windows()\n") + mpi_pth.unlink() output_dir.mkdir(parents=True, exist_ok=True) wheel_pack.pack(root_dir, output_dir, None) diff --git a/.cibw/mpi4py_mpiabi.py b/.cibw/mpi4py_mpiabi.py index 00188ec..836ea36 100644 --- a/.cibw/mpi4py_mpiabi.py +++ b/.cibw/mpi4py_mpiabi.py @@ -226,3 +226,41 @@ def find_spec(cls, fullname, path, target=None): def _install_finder(): if _Finder not in sys.meta_path: sys.meta_path.append(_Finder) + + +def _bootstrap_windows(): + dllpath = [] + + def add(root, *subdir, dll=""): + path = os.path.join(root, *subdir) + dll = os.path.join(path, dll) + if os.path.exists(dll): + dllpath.append(path) + + I_MPI_ROOT = os.environ.get("I_MPI_ROOT") + if I_MPI_ROOT: + library_kind = ( + os.environ.get("I_MPI_LIBRARY_KIND") or + os.environ.get("library_kind") or + "release" + ) + ofi_internal = os.environ.get("I_MPI_OFI_LIBRARY_INTERNAL") + if ofi_internal not in ("0", "no", "off", "disable"): + add(I_MPI_ROOT, "libfabric", "bin", dll="libfabric.dll") + add(I_MPI_ROOT, "bin", "libfabric", dll="libfabric.dll") + add(I_MPI_ROOT, "bin", library_kind, dll="impi.dll") + add(I_MPI_ROOT, "bin", dll="impi.dll") + + MSMPI_BIN = os.environ.get("MSMPI_BIN") + if I_MPI_ROOT: + add(MSMPI_BIN, dll="msmpi.dll") + + if hasattr(os, "add_dll_directory"): + for entry in dllpath: + os.add_dll_directory(entry) + else: + ospath = os.environ["PATH"].split(os.path.pathsep) + for entry in dllpath: + if entry not in ospath: + ospath.append(entry) + os.environ["PATH"] = os.path.pathsep.join(ospath) diff --git a/.github/workflows/cd-wheel.yml b/.github/workflows/cd-wheel.yml index 142c40c..d432afc 100644 --- a/.github/workflows/cd-wheel.yml +++ b/.github/workflows/cd-wheel.yml @@ -334,16 +334,16 @@ jobs: *NT*-impi_rt) I_MPI_ROOT=$(cygpath -w "$CONDA_PREFIX/Library") echo "I_MPI_ROOT=$I_MPI_ROOT" >> $GITHUB_ENV - echo "$I_MPI_ROOT\\bin" >> $GITHUB_PATH - echo "$I_MPI_ROOT\\bin\\libfabric" >> $GITHUB_PATH + #echo "$I_MPI_ROOT\\bin" >> $GITHUB_PATH + #echo "$I_MPI_ROOT\\bin\\libfabric" >> $GITHUB_PATH ;; *NT*-msmpi) MSMPI_ROOT=$(cygpath -w "$CONDA_PREFIX/Library") echo "MSMPI_BIN=$MSMPI_ROOT\\bin" >> $GITHUB_ENV - echo "MSMPI_INC=$MSMPI_ROOT\\include" >> $GITHUB_ENV - echo "MSMPI_LIB64=$MSMPI_ROOT\\lib" >> $GITHUB_ENV - echo "$MSMPI_BIN" >> $GITHUB_PATH - ;; + #echo "MSMPI_INC=$MSMPI_ROOT\\include" >> $GITHUB_ENV + #echo "MSMPI_LIB64=$MSMPI_ROOT\\lib" >> $GITHUB_ENV + #echo "$MSMPI_BIN" >> $GITHUB_PATH + #;; esac - run: python -m pip install mpi4py --no-index --find-links=dist @@ -413,7 +413,7 @@ jobs: mpiexec: ${{steps.user.outputs.mpiexec }} env: PYTHONUSERBASE: ${{ runner.temp }}/user - I_MPI_FABRICS: shm + #I_MPI_FABRICS: shm - if: ${{ matrix.mpi == 'impi' }} id: venv @@ -442,8 +442,8 @@ jobs: with: python: ${{ steps.venv.outputs.python }} mpiexec: ${{steps.venv.outputs.mpiexec }} - env: - I_MPI_FABRICS: shm + #env: + # I_MPI_FABRICS: shm - uses: mpi4py/setup-mpi@v1 with: