diff options
Diffstat (limited to 'tools/Vulkan-Tools/scripts/gn')
7 files changed, 347 insertions, 0 deletions
diff --git a/tools/Vulkan-Tools/scripts/gn/DEPS b/tools/Vulkan-Tools/scripts/gn/DEPS new file mode 100644 index 00000000..8cf931a8 --- /dev/null +++ b/tools/Vulkan-Tools/scripts/gn/DEPS @@ -0,0 +1,68 @@ +gclient_gn_args_file = 'build/config/gclient_args.gni' + +vars = { + 'chromium_git': 'https://chromium.googlesource.com', + 'ninja_version': 'version:2@1.11.1.chromium.6', +} + +deps = { + + 'build': { + 'url': '{chromium_git}/chromium/src/build.git@1015724d82945f9ef7e51c6f804034ccf5f79951', + }, + + 'buildtools': { + 'url': '{chromium_git}/chromium/src/buildtools.git@3c7e3f1b8b1e4c0b6ec693430379cea682de78d6', + }, + + 'buildtools/linux64': { + 'packages': [ + { + 'package': 'gn/gn/linux-${{arch}}', + 'version': 'git_revision:5e19d2fb166fbd4f6f32147fbb2f497091a54ad8', + } + ], + 'dep_type': 'cipd', + 'condition': 'host_os == "linux"', + }, + + 'testing': { + 'url': '{chromium_git}/chromium/src/testing@949b2864b6bd27656753b917c9aa7731dc7a06f6', + }, + + 'tools/clang': { + 'url': '{chromium_git}/chromium/src/tools/clang.git@566877f1ff1a5fa6beaca3ab4b47bd0b92eb614f', + }, + + 'third_party/ninja': { + 'packages': [ + { + 'package': 'infra/3pp/tools/ninja/${{platform}}', + 'version': Var('ninja_version'), + } + ], + 'dep_type': 'cipd', + }, + +} + +hooks = [ + { + 'name': 'sysroot_x64', + 'pattern': '.', + 'condition': 'checkout_linux and checkout_x64', + 'action': ['python3', 'build/linux/sysroot_scripts/install-sysroot.py', + '--arch=x64'], + }, + { + # Note: On Win, this should run after win_toolchain, as it may use it. + 'name': 'clang', + 'pattern': '.', + 'action': ['python3', 'tools/clang/scripts/update.py'], + }, +] + +recursedeps = [ + # buildtools provides clang_format. + 'buildtools', +] diff --git a/tools/Vulkan-Tools/scripts/gn/generate_vulkan_icd_json.py b/tools/Vulkan-Tools/scripts/gn/generate_vulkan_icd_json.py new file mode 100755 index 00000000..467ba616 --- /dev/null +++ b/tools/Vulkan-Tools/scripts/gn/generate_vulkan_icd_json.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python + +# Copyright (c) 2022-2023 LunarG, Inc. +# Copyright (C) 2016 The ANGLE Project Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Generate copies of the Vulkan layers JSON files, with no paths, forcing +Vulkan to use the default search path to look for layers.""" + +from __future__ import print_function + +import argparse +import glob +import json +import os +import platform +import sys + +def glob_slash(dirname): + r"""Like regular glob but replaces \ with / in returned paths.""" + return [s.replace('\\', '/') for s in glob.glob(dirname)] + +def main(): + 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('json_files', nargs='*') + args = parser.parse_args() + + source_dir = args.source_dir + target_dir = args.target_dir + + json_files = [j for j in args.json_files if j.endswith('.json')] + json_in_files = [j for j in args.json_files if j.endswith('.json.in')] + + data_key = 'ICD' if args.icd else 'layer' + + if not os.path.isdir(source_dir): + print(source_dir + ' is not a directory.', file=sys.stderr) + return 1 + + if not os.path.exists(target_dir): + os.makedirs(target_dir) + + # Copy the *.json files from source dir to target dir + if (set(glob_slash(os.path.join(source_dir, '*.json'))) != set(json_files)): + print(glob.glob(os.path.join(source_dir, '*.json'))) + print('.json list in gn file is out-of-date', file=sys.stderr) + return 1 + + for json_fname in json_files: + if not json_fname.endswith('.json'): + continue + with open(json_fname) as infile: + data = json.load(infile) + + # Update the path. + if not data_key in data: + raise Exception( + "Could not find '%s' key in %s" % (data_key, json_fname)) + + # The standard validation layer has no library path. + if 'library_path' in data[data_key]: + prev_name = os.path.basename(data[data_key]['library_path']) + data[data_key]['library_path'] = prev_name + + target_fname = os.path.join(target_dir, os.path.basename(json_fname)) + with open(target_fname, 'w') as outfile: + json.dump(data, outfile) + + # Set json file prefix and suffix for generating files, default to Linux. + if args.no_path_prefix: + relative_path_prefix = '' + elif args.platform == 'Windows': + relative_path_prefix = r'..\\' # json-escaped, hence two backslashes. + else: + relative_path_prefix = '../lib' + file_type_suffix = '.so' + if args.platform == 'Windows': + file_type_suffix = '.dll' + elif args.platform == 'Darwin': + file_type_suffix = '.dylib' + + # For each *.json.in template files in source dir generate actual json file + # in target dir + if (set(glob_slash(os.path.join(source_dir, '*.json.in'))) != + set(json_in_files)): + print('.json.in list in gn file is out-of-date', file=sys.stderr) + return 1 + for json_in_name in json_in_files: + if not json_in_name.endswith('.json.in'): + continue + json_in_fname = os.path.basename(json_in_name) + layer_name = json_in_fname[:-len('.json.in')] + layer_lib_name = layer_name + file_type_suffix + json_out_fname = os.path.join(target_dir, json_in_fname[:-len('.in')]) + with open(json_out_fname,'w') as json_out_file, \ + open(json_in_name) as infile: + for line in infile: + line = line.replace('@JSON_LIBRARY_PATH@', relative_path_prefix + layer_lib_name) + json_out_file.write(line) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/Vulkan-Tools/scripts/gn/gn.py b/tools/Vulkan-Tools/scripts/gn/gn.py new file mode 100755 index 00000000..52b20c58 --- /dev/null +++ b/tools/Vulkan-Tools/scripts/gn/gn.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +# Copyright 2023 The Khronos Group Inc. +# Copyright 2023 Valve Corporation +# Copyright 2023 LunarG, Inc. +# +# SPDX-License-Identifier: Apache-2.0 + +import os +import subprocess +import sys + +# helper to define paths relative to the repo root +def RepoRelative(path): + return os.path.abspath(os.path.join(os.path.dirname(__file__), '../../', path)) + +def BuildGn(): + if not os.path.exists(RepoRelative("depot_tools")): + print("Cloning Chromium depot_tools\n", flush=True) + clone_cmd = 'git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git depot_tools'.split(" ") + subprocess.call(clone_cmd) + + os.environ['PATH'] = os.environ.get('PATH') + ":" + RepoRelative("depot_tools") + + print("Updating Repo Dependencies and GN Toolchain\n", flush=True) + update_cmd = './scripts/gn/update_deps.sh' + subprocess.call(update_cmd) + + print("Checking Header Dependencies\n", flush=True) + gn_check_cmd = 'gn gen --check out/Debug'.split(" ") + subprocess.call(gn_check_cmd) + + print("Generating Ninja Files\n", flush=True) + gn_gen_cmd = 'gn gen out/Debug'.split(" ") + subprocess.call(gn_gen_cmd) + + print("Running Ninja Build\n", flush=True) + ninja_build_cmd = 'ninja -C out/Debug'.split(" ") + subprocess.call(ninja_build_cmd) + +# +# Module Entrypoint +def main(): + try: + BuildGn() + + except subprocess.CalledProcessError as proc_error: + print('Command "%s" failed with return code %s' % (' '.join(proc_error.cmd), proc_error.returncode)) + sys.exit(proc_error.returncode) + except Exception as unknown_error: + print('An unkown error occured: %s', unknown_error) + sys.exit(1) + + sys.exit(0) + +if __name__ == '__main__': + main() diff --git a/tools/Vulkan-Tools/scripts/gn/secondary/build_overrides/build.gni b/tools/Vulkan-Tools/scripts/gn/secondary/build_overrides/build.gni new file mode 100644 index 00000000..dbf47039 --- /dev/null +++ b/tools/Vulkan-Tools/scripts/gn/secondary/build_overrides/build.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2019-2023 LunarG, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +build_with_chromium = false +ignore_elf32_limitations = true +linux_use_bundled_binutils_override = false +use_system_xcode = true diff --git a/tools/Vulkan-Tools/scripts/gn/secondary/build_overrides/vulkan_headers.gni b/tools/Vulkan-Tools/scripts/gn/secondary/build_overrides/vulkan_headers.gni new file mode 100644 index 00000000..5f24b39e --- /dev/null +++ b/tools/Vulkan-Tools/scripts/gn/secondary/build_overrides/vulkan_headers.gni @@ -0,0 +1,15 @@ +# Copyright (c) 2020-2023 LunarG, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +vulkan_use_x11 = true diff --git a/tools/Vulkan-Tools/scripts/gn/secondary/build_overrides/vulkan_tools.gni b/tools/Vulkan-Tools/scripts/gn/secondary/build_overrides/vulkan_tools.gni new file mode 100644 index 00000000..c62fb64d --- /dev/null +++ b/tools/Vulkan-Tools/scripts/gn/secondary/build_overrides/vulkan_tools.gni @@ -0,0 +1,21 @@ +# Copyright (c) 2019-2023 LunarG, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Paths to vulkan tools dependencies +vulkan_headers_dir = "//external/Vulkan-Headers" + +# Subdirectories for generated files +vulkan_data_subdir = "" +vulkan_gen_subdir = "" + diff --git a/tools/Vulkan-Tools/scripts/gn/update_deps.sh b/tools/Vulkan-Tools/scripts/gn/update_deps.sh new file mode 100755 index 00000000..763c3058 --- /dev/null +++ b/tools/Vulkan-Tools/scripts/gn/update_deps.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# Copyright (c) 2019-2023 LunarG, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Execute at repo root +cd "$(dirname $0)/../../" + +# Use update_deps.py to update source dependencies from /scripts/known_good.json +scripts/update_deps.py --dir="external" --no-build + +cat << EOF > .gn +buildconfig = "//build/config/BUILDCONFIG.gn" +secondary_source = "//scripts/gn/secondary/" + +script_executable = "python3" + +default_args = { + clang_use_chrome_plugins = false + use_custom_libcxx = false +} +EOF + +# Use gclient to update toolchain dependencies from /scripts/gn/DEPS (from chromium) +cat << EOF >> .gclient +solutions = [ + { "name" : ".", + "url" : "https://github.com/KhronosGroup/Vulkan-Tools", + "deps_file" : "scripts/gn/DEPS", + "managed" : False, + "custom_deps" : { + }, + "custom_vars": {}, + }, +] +EOF +gclient sync + |
