From 6f9637713587c24789d1c89510e904754860c63d Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Wed, 30 Jun 2021 20:32:07 +0200 Subject: =?UTF-8?q?pyGHDL:=20Added=20DLL=20search=20path=20for=20Python=20?= =?UTF-8?q?=E2=89=A53.8.=20(#1811)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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. --- pyGHDL/libghdl/__init__.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'pyGHDL/libghdl') 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. -- cgit v1.2.3