diff options
| author | unknown <vid512@gmail.com> | 2024-09-05 20:56:01 +0200 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2024-09-21 08:17:41 -0700 |
| commit | 59f6105f7980a7e615df8b2c7700a40d707415a3 (patch) | |
| tree | 0933198cb42738f52a8b438b09c279025e8cf9ce /mesonbuild/dependencies | |
| parent | cbbe455ba4f7da2d9056023d8e8647da96eeaf09 (diff) | |
| download | meson-59f6105f7980a7e615df8b2c7700a40d707415a3.tar.gz | |
add diasdk dependency
Diffstat (limited to 'mesonbuild/dependencies')
| -rw-r--r-- | mesonbuild/dependencies/__init__.py | 1 | ||||
| -rw-r--r-- | mesonbuild/dependencies/dev.py | 102 |
2 files changed, 103 insertions, 0 deletions
diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py index 89d2285ba..a3eb6623f 100644 --- a/mesonbuild/dependencies/__init__.py +++ b/mesonbuild/dependencies/__init__.py @@ -195,6 +195,7 @@ packages.defaults.update({ 'zlib': 'dev', 'jni': 'dev', 'jdk': 'dev', + 'diasdk': 'dev', 'boost': 'boost', 'cuda': 'cuda', diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index de85516fe..94f51ff69 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -28,8 +28,10 @@ from .pkgconfig import PkgConfigDependency if T.TYPE_CHECKING: from ..envconfig import MachineInfo from ..environment import Environment + from ..compilers import Compiler from ..mesonlib import MachineChoice from typing_extensions import TypedDict + from ..interpreter.type_checking import PkgConfigDefineType class JNISystemDependencyKW(TypedDict): modules: T.List[str] @@ -700,6 +702,106 @@ class JDKSystemDependency(JNISystemDependency): packages['jdk'] = JDKSystemDependency +class DiaSDKSystemDependency(SystemDependency): + + def _try_path(self, diadir: str, cpu: str) -> bool: + if not os.path.isdir(diadir): + return False + + include = os.path.join(diadir, 'include') + if not os.path.isdir(include): + mlog.error('DIA SDK is missing include directory:', include) + return False + + lib = os.path.join(diadir, 'lib', cpu, 'diaguids.lib') + if not os.path.exists(lib): + mlog.error('DIA SDK is missing library:', lib) + return False + + bindir = os.path.join(diadir, 'bin', cpu) + if not os.path.exists(bindir): + mlog.error(f'Directory {bindir} not found') + return False + + found = glob.glob(os.path.join(bindir, 'msdia*.dll')) + if not found: + mlog.error("Can't find msdia*.dll in " + bindir) + return False + if len(found) > 1: + mlog.error('Multiple msdia*.dll files found in ' + bindir) + return False + self.dll = found[0] + + # Parse only major version from DLL name (eg '8' from 'msdia80.dll', '14' from 'msdia140.dll', etc.). + # Minor version is not reflected in the DLL name, instead '0' is always used. + # Aside from major version in DLL name, the SDK version is not visible to user anywhere. + # The only place where the full version is stored, seems to be the Version field in msdia*.dll resources. + dllname = os.path.basename(self.dll) + versionstr = dllname[len('msdia'):-len('.dll')] + if versionstr[-1] == '0': + self.version = versionstr[:-1] + else: + mlog.error(f"Unexpected DIA SDK version string in '{dllname}'") + self.version = 'unknown' + + self.compile_args.append('-I' + include) + self.link_args.append(lib) + self.is_found = True + return True + + # Check if compiler has a built-in macro defined + @staticmethod + def _has_define(compiler: 'Compiler', dname: str, env: 'Environment') -> bool: + defval, _ = compiler.get_define(dname, '', env, [], []) + return defval is not None + + def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> None: + super().__init__('diasdk', environment, kwargs) + self.is_found = False + + compilers = environment.coredata.compilers.host + if 'cpp' in compilers: + compiler = compilers['cpp'] + elif 'c' in compilers: + compiler = compilers['c'] + else: + raise DependencyException('DIA SDK is only supported in C and C++ projects') + + is_msvc_clang = compiler.id == 'clang' and self._has_define(compiler, '_MSC_VER', environment) + if compiler.id not in {'msvc', 'clang-cl'} and not is_msvc_clang: + raise DependencyException('DIA SDK is only supported with Microsoft Visual Studio compilers') + + cpu_translate = {'arm': 'arm', 'aarch64': 'arm64', 'x86': '.', 'x86_64': 'amd64'} + cpu_family = environment.machines.host.cpu_family + cpu = cpu_translate.get(cpu_family) + if cpu is None: + raise DependencyException(f'DIA SDK is not supported for "{cpu_family}" architecture') + + vsdir = os.environ.get('VSInstallDir') + if vsdir is None: + raise DependencyException("Environment variable VSInstallDir required for DIA SDK is not set") + + diadir = os.path.join(vsdir, 'DIA SDK') + if self._try_path(diadir, cpu): + mlog.debug('DIA SDK was found at default path: ', diadir) + self.is_found = True + return + mlog.debug('DIA SDK was not found at default path: ', diadir) + + return + + def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None, + configtool: T.Optional[str] = None, internal: T.Optional[str] = None, + system: T.Optional[str] = None, default_value: T.Optional[str] = None, + pkgconfig_define: PkgConfigDefineType = None) -> str: + if system == 'dll' and self.is_found: + return self.dll + if default_value is not None: + return default_value + raise DependencyException(f'Could not get system variable and no default was set for {self!r}') + +packages['diasdk'] = DiaSDKSystemDependency + packages['llvm'] = llvm_factory = DependencyFactory( 'LLVM', [DependencyMethods.CMAKE, DependencyMethods.CONFIG_TOOL], |
