summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian "sp1rit"​ <sp1rit@disroot.org>2024-11-16 13:43:48 +0100
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2025-01-13 23:09:31 +0530
commitdfb449d099d6f3066ca646af197bc7af85059a86 (patch)
tree18bb7e2e439b20089191be5920058f09cb7b6196
parent6b99eeb2c99d4af4be2562b25507541bfd842692 (diff)
downloadmeson-dfb449d099d6f3066ca646af197bc7af85059a86.tar.gz
vulkan system dep: determine version on cross builds
Currently, the vulkan system dep detects its vulkan version by building and running: int main() { printf("%i.%i.%i", VK_VERSION_MAJOR(VK_HEADER_VERSION_COMPLETE), VK_VERSION_MINOR(VK_HEADER_VERSION_COMPLETE), VK_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE)); return 0; } this causes cross builds that do not have the possibility of running on the build machine to evaluate the vulkan dependency with an 'Unknown' version. Instead of evaluating beforementioned piece of C code, the new implementation will instead use cc.compute_int to evaluate the three preprocessor macros. This is relativly expensive for cross builds right now but further optimizations can be made. See #13910 for more details.
-rw-r--r--mesonbuild/dependencies/ui.py46
1 files changed, 21 insertions, 25 deletions
diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py
index 7adac5e75..fc44037f1 100644
--- a/mesonbuild/dependencies/ui.py
+++ b/mesonbuild/dependencies/ui.py
@@ -12,7 +12,6 @@ import typing as T
from .. import mlog
from .. import mesonlib
-from ..compilers.compilers import CrossNoRunException
from ..mesonlib import (
Popen_safe, extract_as_list, version_compare_many
)
@@ -235,31 +234,28 @@ class VulkanDependencySystem(SystemDependency):
self.link_args.append(lib)
if self.is_found:
- get_version = '''\
-#include <stdio.h>
-#include <vulkan/vulkan.h>
-
-int main() {
- printf("%i.%i.%i", VK_VERSION_MAJOR(VK_HEADER_VERSION_COMPLETE),
- VK_VERSION_MINOR(VK_HEADER_VERSION_COMPLETE),
- VK_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE));
- return 0;
-}
-'''
try:
- run = self.clib_compiler.run(get_version, environment, extra_args=self.compile_args)
- except CrossNoRunException:
- run = None
- if run and run.compiled and run.returncode == 0:
- self.version = run.stdout
- elif self.vulkan_sdk:
- # fall back to heuristics: detect version number in path
- # matches the default install path on Windows
- match = re.search(rf'VulkanSDK{re.escape(os.path.sep)}([0-9]+(?:\.[0-9]+)+)', self.vulkan_sdk)
- if match:
- self.version = match.group(1)
- else:
- mlog.warning(f'Environment variable VULKAN_SDK={self.vulkan_sdk} is present, but Vulkan version could not be extracted.')
+ # VK_VERSION_* is deprecated and replaced by VK_API_VERSION_*. We'll continue to use the old one in
+ # order to support older Vulkan versions that don't have the new one yet, but we might have to update
+ # this code to also check VK_API_VERSION in the future if they decide to drop the old one at some point.
+ components = [str(self.clib_compiler.compute_int(f'VK_VERSION_{c}(VK_HEADER_VERSION_COMPLETE)',
+ low=0, high=None, guess=e,
+ prefix='#include <vulkan/vulkan.h>',
+ env=environment,
+ extra_args=None,
+ dependencies=None))
+ # list containing vulkan version components and their expected value
+ for c, e in [('MAJOR', 1), ('MINOR', 3), ('PATCH', None)]]
+ self.version = '.'.join(components)
+ except mesonlib.EnvironmentException:
+ if self.vulkan_sdk:
+ # fall back to heuristics: detect version number in path
+ # matches the default install path on Windows
+ match = re.search(rf'VulkanSDK{re.escape(os.path.sep)}([0-9]+(?:\.[0-9]+)+)', self.vulkan_sdk)
+ if match:
+ self.version = match.group(1)
+ else:
+ mlog.warning(f'Environment variable VULKAN_SDK={self.vulkan_sdk} is present, but Vulkan version could not be extracted.')
packages['gl'] = gl_factory = DependencyFactory(
'gl',