Skip to content

Refactor Windows DLL loading in Python packages#559

Merged
ax3l merged 1 commit into
AMReX-Codes:developmentfrom
ax3l:topic-improve-dll-search
May 5, 2026
Merged

Refactor Windows DLL loading in Python packages#559
ax3l merged 1 commit into
AMReX-Codes:developmentfrom
ax3l:topic-improve-dll-search

Conversation

@ax3l
Copy link
Copy Markdown
Member

@ax3l ax3l commented Apr 9, 2026

The existing space1d/space2d/space3d package initializers each carried the same Windows DLL setup code before importing their pybind extension. That logic only added the current package directory plus entries already present on PATH via os.add_dll_directory(). In practice this was fragile for wheel installs because the extension import could still fail if dependent DLLs were bundled in package-local locations that were not already on PATH.

Example: for ImpactX wheels we just build one ImpactX wheel that vendors the AMReX and ImpactX libs and both the pyAMReX and pyImpactX sources: BLAST-ImpactX/impactx-wheels#22 (We do not yet publish AMReX wheels.)

Centralize the DLL search setup in amrex._dll and call it from each spaceNd package before importing amrex_*d_pybind. The new helper prefers package-local locations first: the current spaceNd directory, spaceNd/.libs, the parent amrex package directory, and amrex/.libs. It then falls back to PATH for source and developer installs.

Keep the os.add_dll_directory() handles alive for the lifetime of the process and deduplicate discovered paths. This keeps the Windows import workaround in one place and makes it compatible with vendored wheel layouts as well as traditional shared- library installs.

@ax3l ax3l added the install Build and installation label Apr 9, 2026
The existing space1d/space2d/space3d package initializers each
carried the same Windows DLL setup code before importing their
pybind extension. That logic only added the current package
directory plus entries already present on PATH via
os.add_dll_directory(). In practice this was fragile for wheel
installs because the extension import could still fail if
dependent DLLs were bundled in package-local locations that were
not already on PATH.

Centralize the DLL search setup in amrex._dll and call it from
each spaceNd package before importing amrex_*d_pybind. The new
helper prefers package-local locations first: the current
spaceNd directory, spaceNd/.libs, the parent amrex package
directory, and amrex/.libs. It then falls back to PATH for
source and developer installs.

Keep the os.add_dll_directory() handles alive for the lifetime
of the process and deduplicate discovered paths. This keeps the
Windows import workaround in one place and makes it compatible
with vendored wheel layouts as well as traditional shared-
library installs.
@ax3l ax3l force-pushed the topic-improve-dll-search branch from 70bf3fd to 3a9b82c Compare April 9, 2026 16:11
@ax3l ax3l merged commit 8543513 into AMReX-Codes:development May 5, 2026
18 checks passed
@ax3l ax3l deleted the topic-improve-dll-search branch May 5, 2026 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

install Build and installation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant