2019-03-06 23:17:39 +00:00
|
|
|
# Copyright 2019 The Dawn 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
|
|
|
|
#
|
|
|
|
# http://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.
|
|
|
|
|
|
|
|
import("../scripts/dawn_overrides_with_defaults.gni")
|
2019-06-24 14:31:06 +00:00
|
|
|
import("generator_lib.gni")
|
2019-03-06 23:17:39 +00:00
|
|
|
|
2019-09-19 23:30:42 +00:00
|
|
|
# Dawn used to put autogenerated files in a lot of different places. When we
|
|
|
|
# started to move them around, some compilation issues arised because some
|
|
|
|
# stale include files stayed in the build directory and were picked up.
|
|
|
|
# To counter this, now Dawn does the following:
|
|
|
|
#
|
|
|
|
# 1. The generated output file directory structure has to match the structure
|
|
|
|
# of the source tree, starting at dawn_gen_root (gen/ or
|
|
|
|
# gen/third_party/dawn depending on where we are).
|
2022-02-04 18:18:18 +00:00
|
|
|
# 2. include and dawn_gen_root/include has to match the structure of
|
2019-09-19 23:30:42 +00:00
|
|
|
# the source tree too.
|
2022-02-04 18:18:18 +00:00
|
|
|
# 3. Dawn files must use include relative to src/ or include such as
|
2022-02-04 17:07:46 +00:00
|
|
|
# "dawn/dawn.h" or "dawn/native/backend/BackendStuff.h".
|
2019-09-19 23:30:42 +00:00
|
|
|
#
|
|
|
|
# The allowed list below ensure 1). Include directory rules for Dawn ensure 3)
|
|
|
|
# and 2) is something we need to enforce in code review.
|
|
|
|
#
|
|
|
|
# However GN's toolchains automatically add some include directories for us
|
|
|
|
# which breaks 3) slightly. To avoid stale headers in for example
|
|
|
|
# dawn_gen_root/src/dawn/dawn/ to be picked up (instead of
|
|
|
|
# dawn_gen_root/src/dawn), we have a special action that removes files in
|
|
|
|
# disallowed gen directories.
|
|
|
|
|
2019-09-18 23:19:31 +00:00
|
|
|
dawn_allowed_gen_output_dirs = [
|
|
|
|
"src/dawn/",
|
2022-02-04 17:07:46 +00:00
|
|
|
"src/dawn/native/",
|
|
|
|
"src/dawn/native/opengl/",
|
2022-02-04 12:51:25 +00:00
|
|
|
"src/dawn/wire/client/",
|
|
|
|
"src/dawn/wire/server/",
|
|
|
|
"src/dawn/wire/",
|
2022-02-04 18:18:18 +00:00
|
|
|
"include/dawn/",
|
2021-09-17 19:44:43 +00:00
|
|
|
"emscripten-bits/",
|
|
|
|
"webgpu-headers/",
|
2019-09-18 23:19:31 +00:00
|
|
|
]
|
|
|
|
|
2019-06-11 18:03:05 +00:00
|
|
|
# Template to help invoking Dawn code generators based on generator_lib
|
2019-03-06 23:17:39 +00:00
|
|
|
#
|
|
|
|
# dawn_generator("my_target_gen") {
|
2019-06-11 18:03:05 +00:00
|
|
|
# # The script and generator specific arguments
|
|
|
|
# script = [ "my_awesome_generator.py" ]
|
|
|
|
# args = [
|
|
|
|
# "--be-awesome",
|
|
|
|
# "yes"
|
|
|
|
# ]
|
|
|
|
#
|
2019-03-06 23:17:39 +00:00
|
|
|
# # The list of expected outputs, generation fails if there's a mismatch
|
|
|
|
# outputs = [
|
2019-06-11 18:03:05 +00:00
|
|
|
# "MyAwesomeTarget.cpp",
|
|
|
|
# "MyAwesomeTarget.h",
|
2019-03-06 23:17:39 +00:00
|
|
|
# ]
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# Using the generated files is done like so:
|
|
|
|
#
|
|
|
|
# shared_library("my_target") {
|
|
|
|
# deps = [ ":my_target_gen "]
|
|
|
|
# sources = get_target_outputs(":my_target_gen")
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
template("dawn_generator") {
|
2019-06-24 14:31:06 +00:00
|
|
|
generator_lib_action(target_name) {
|
|
|
|
forward_variables_from(invoker, "*")
|
2019-09-19 23:30:42 +00:00
|
|
|
|
|
|
|
# Set arguments required to find the python libraries for the generator
|
2019-06-24 14:31:06 +00:00
|
|
|
generator_lib_dir = "${dawn_root}/generator"
|
|
|
|
jinja2_path = dawn_jinja2_dir
|
2019-09-19 23:30:42 +00:00
|
|
|
|
|
|
|
# Force Dawn's autogenerated file structure to mirror exactly the source
|
|
|
|
# tree but start at ${dawn_gen_root} instead of ${dawn_root}
|
2019-09-18 23:19:31 +00:00
|
|
|
allowed_output_dirs = dawn_allowed_gen_output_dirs
|
2019-09-19 23:30:42 +00:00
|
|
|
custom_gen_dir = dawn_gen_root
|
|
|
|
|
|
|
|
# Make sure that we delete stale autogenerated file in directories that are
|
|
|
|
# no longer used by code generation to avoid include conflicts.
|
|
|
|
deps = [ "${dawn_root}/generator:remove_stale_autogen_files" ]
|
2019-03-06 23:17:39 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-11 18:03:05 +00:00
|
|
|
|
|
|
|
# Helper generator for calling the generator from dawn.json
|
|
|
|
#
|
|
|
|
# dawn_json_generator("my_target_gen") {
|
|
|
|
# # Which generator target to output
|
|
|
|
# target = "my_target"
|
|
|
|
#
|
|
|
|
# # Also supports `outputs` and `custom_gen_dir` like dawn_generator.
|
|
|
|
# }
|
|
|
|
template("dawn_json_generator") {
|
|
|
|
dawn_generator(target_name) {
|
|
|
|
script = "${dawn_root}/generator/dawn_json_generator.py"
|
|
|
|
|
|
|
|
# The base arguments for the generator: from this dawn.json, generate this
|
|
|
|
# target using templates in this directory.
|
|
|
|
args = [
|
|
|
|
"--dawn-json",
|
|
|
|
rebase_path("${dawn_root}/dawn.json", root_build_dir),
|
|
|
|
"--wire-json",
|
|
|
|
rebase_path("${dawn_root}/dawn_wire.json", root_build_dir),
|
|
|
|
"--targets",
|
|
|
|
invoker.target,
|
|
|
|
]
|
|
|
|
|
2019-06-13 10:22:32 +00:00
|
|
|
forward_variables_from(invoker, "*", [ "target" ])
|
2019-06-11 18:03:05 +00:00
|
|
|
}
|
|
|
|
}
|