diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-30 20:32:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-30 20:32:07 +0200 |
commit | 6f9637713587c24789d1c89510e904754860c63d (patch) | |
tree | ebe46506d8114e19f13f09987339a3a0472e1f52 /pyGHDL | |
parent | afae1a4ab13485d3e5d5624ca9231bc5da0ff867 (diff) | |
download | ghdl-6f9637713587c24789d1c89510e904754860c63d.tar.gz ghdl-6f9637713587c24789d1c89510e904754860c63d.tar.bz2 ghdl-6f9637713587c24789d1c89510e904754860c63d.zip |
pyGHDL: Added DLL search path for Python ≥3.8. (#1811)
* Added DLL search path for Python ≥3.8.
Let Windows CPython 64-bit execute GHDL in msys64/mingw64.
* Fix executable name of Python based on the current environment.
(cherry picked from commit 618c8149df1fa53d06cb197d65b3b10a02ae52ee)
* Removed debug code.
Diffstat (limited to 'pyGHDL')
-rw-r--r-- | pyGHDL/libghdl/__init__.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/pyGHDL/libghdl/__init__.py b/pyGHDL/libghdl/__init__.py index d23ffc0e7..39722f3b9 100644 --- a/pyGHDL/libghdl/__init__.py +++ b/pyGHDL/libghdl/__init__.py @@ -31,10 +31,9 @@ # # SPDX-License-Identifier: GPL-2.0-or-later # ============================================================================ - from ctypes import c_char_p, CDLL -import os -import sys +from sys import platform as sys_platform, version_info as sys_version_info +from os import environ as os_environ from pathlib import Path from shutil import which from typing import List @@ -63,7 +62,7 @@ class LibGHDLException(GHDLBaseException): def _get_libghdl_name() -> Path: """Get the name of the libghdl library (with version and extension).""" ver = __version__.replace("-", "_").replace(".", "_") - ext = {"win32": "dll", "cygwin": "dll", "darwin": "dylib"}.get(sys.platform, "so") + ext = {"win32": "dll", "cygwin": "dll", "darwin": "dylib"}.get(sys_platform, "so") return Path("libghdl-{version}.{ext}".format(version=ver, ext=ext)) @@ -103,21 +102,21 @@ def _get_libghdl_path(): # Try GHDL_PREFIX # GHDL_PREFIX is the prefix of the vhdl libraries, so remove the # last path component. - r = os.environ.get("GHDL_PREFIX") + r = os_environ.get("GHDL_PREFIX") try: return _check_libghdl_libdir(Path(r).parent, basename) except (TypeError, FileNotFoundError): pass # Try VUNIT_GHDL_PATH (path of the ghdl binary when using VUnit). - r = os.environ.get("VUNIT_GHDL_PATH") + r = os_environ.get("VUNIT_GHDL_PATH") try: return _check_libghdl_bindir(Path(r), basename) except (TypeError, FileNotFoundError): pass # Try GHDL (name/path of the ghdl binary) - r = os.environ.get("GHDL", "ghdl") + r = os_environ.get("GHDL", "ghdl") r = which(r) try: return _check_libghdl_bindir(Path(r).parent, basename) @@ -145,7 +144,19 @@ def _get_libghdl_path(): def _initialize(): # Load the shared library _libghdl_path = _get_libghdl_path() - # print("Load {}".format(_libghdl_path)) + + # Add DLL search path(s) + if ( + sys_platform == "win32" + and sys_version_info.major == 3 + and sys_version_info.minor >= 8 + ): + from os import add_dll_directory as os_add_dll_directory + + p1 = _libghdl_path.parent.parent / "bin" + os_add_dll_directory(str(p1)) + + # Load libghdl shared object libghdl = CDLL(str(_libghdl_path)) # Initialize it. |