build: Allow generating layers json file for cross-compiling
Upstream change: https://github.com/KhronosGroup/Vulkan-ValidationLayers/pull/2302
This change is the same as upstream change except that it adds Fuchsia
specific BUILD.gn modification.
----------------------------------
`generate_vulkan_layers_json.py` generates validation layer description
JSON file where the layer library file name is determined by the
host system type. However, for Fuchsia cross-compiling this doesn't
work. Instead, we need to specify the target platform type explicitly
in the script.
This change adds an optional argument `--platform Linux|Darwin|
Windows|...` to `generate_vulkan_layers_json.py`, so that it could
generate layers json file with correct library filename for specific
target platforms. It is useful when making cross-platform builds.
Test: Run `generate_vulkan_layers_json.py`
1) without `--platform` argument, 2) with `--platform Windows`,
3) with `--platform Linux`, 4) `--platform Darwin` and
5) with `--platform Fuchsia`.
Verification:
- Run "fx set workstation.x64; fx build" on macOS.
- Verified that out/default/vulkan_layers_data/
VkLayer_khronos_validation.json uses "VkLayer_khronos_validation.so"
as library file name.
Bug: 63670
Change-Id: If0ae9571e9b82c78b1caef7c5ac116ef31270999
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/Vulkan-ValidationLayers/+/447334
Reviewed-by: John Rosasco <rosasco@google.com>
Reviewed-by: Yilong Li <liyl@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 2b01f7e..1127514 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -169,7 +169,22 @@
sources += [ "layers/json/$json_name.in" ]
outputs += [ "$vulkan_data_dir/$json_name" ]
}
+
+ if (is_linux) {
+ _platform = "Linux"
+ } else if (is_win) {
+ _platform = "Windows"
+ } else if (is_mac) {
+ _platform = "Darwin"
+ } else if (is_fuchsia) {
+ _platform = "Fuchsia"
+ } else {
+ _platform = "Other"
+ }
+
args = [
+ "--platform",
+ _platform,
rebase_path("layers/json", root_build_dir),
rebase_path(vulkan_data_dir, root_build_dir),
] + rebase_path(sources, root_build_dir)
diff --git a/build-gn/generate_vulkan_layers_json.py b/build-gn/generate_vulkan_layers_json.py
index 323e680..0aae8b5 100755
--- a/build-gn/generate_vulkan_layers_json.py
+++ b/build-gn/generate_vulkan_layers_json.py
@@ -36,6 +36,9 @@
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--icd', action='store_true')
parser.add_argument('--no-path-prefix', action='store_true')
+ parser.add_argument('--platform', type=str, default=platform.system(),
+ help='Target platform to build validation layers for: '
+ 'Linux|Darwin|Windows|Fuchsia|...')
parser.add_argument('source_dir')
parser.add_argument('target_dir')
parser.add_argument('version_header', help='path to vulkan_core.h')
@@ -98,15 +101,15 @@
# Set json file prefix and suffix for generating files, default to Linux.
if args.no_path_prefix:
relative_path_prefix = ''
- elif platform.system() == 'Windows':
+ elif args.platform == 'Windows':
relative_path_prefix = r'..\\' # json-escaped, hence two backslashes.
else:
relative_path_prefix = '../lib'
file_type_suffix = '.so'
- if platform.system() == 'Windows':
+ if args.platform == 'Windows':
file_type_suffix = '.dll'
- elif platform.system() == 'Darwin':
+ elif args.platform == 'Darwin':
file_type_suffix = '.dylib'
# For each *.json.in template files in source dir generate actual json file