Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 1 | # Copyright 2019 The Dawn Authors |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import("../scripts/dawn_overrides_with_defaults.gni") |
David 'Digit' Turner | 5dee3e8 | 2019-06-24 14:31:06 +0000 | [diff] [blame] | 16 | import("generator_lib.gni") |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 17 | |
Corentin Wallez | a9a84df | 2019-09-19 23:30:42 +0000 | [diff] [blame] | 18 | # Dawn used to put autogenerated files in a lot of different places. When we |
| 19 | # started to move them around, some compilation issues arised because some |
| 20 | # stale include files stayed in the build directory and were picked up. |
| 21 | # To counter this, now Dawn does the following: |
| 22 | # |
| 23 | # 1. The generated output file directory structure has to match the structure |
| 24 | # of the source tree, starting at dawn_gen_root (gen/ or |
| 25 | # gen/third_party/dawn depending on where we are). |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 26 | # 2. include and dawn_gen_root/include has to match the structure of |
Corentin Wallez | a9a84df | 2019-09-19 23:30:42 +0000 | [diff] [blame] | 27 | # the source tree too. |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 28 | # 3. Dawn files must use include relative to src/ or include such as |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 29 | # "dawn/dawn.h" or "dawn/native/backend/BackendStuff.h". |
Corentin Wallez | a9a84df | 2019-09-19 23:30:42 +0000 | [diff] [blame] | 30 | # |
| 31 | # The allowed list below ensure 1). Include directory rules for Dawn ensure 3) |
| 32 | # and 2) is something we need to enforce in code review. |
| 33 | # |
| 34 | # However GN's toolchains automatically add some include directories for us |
| 35 | # which breaks 3) slightly. To avoid stale headers in for example |
| 36 | # dawn_gen_root/src/dawn/dawn/ to be picked up (instead of |
| 37 | # dawn_gen_root/src/dawn), we have a special action that removes files in |
| 38 | # disallowed gen directories. |
| 39 | |
Corentin Wallez | 05623df | 2019-09-18 23:19:31 +0000 | [diff] [blame] | 40 | dawn_allowed_gen_output_dirs = [ |
| 41 | "src/dawn/", |
Loko Kung | f578672 | 2022-03-31 05:09:04 +0000 | [diff] [blame] | 42 | "src/dawn/common/", |
Ben Clayton | 818001d | 2022-02-04 17:07:46 +0000 | [diff] [blame] | 43 | "src/dawn/native/", |
| 44 | "src/dawn/native/opengl/", |
Ben Clayton | 20cbe6d | 2022-02-04 12:51:25 +0000 | [diff] [blame] | 45 | "src/dawn/wire/client/", |
| 46 | "src/dawn/wire/server/", |
| 47 | "src/dawn/wire/", |
Ben Clayton | 9fb7a51 | 2022-02-04 18:18:18 +0000 | [diff] [blame] | 48 | "include/dawn/", |
Kai Ninomiya | 930e918 | 2021-09-17 19:44:43 +0000 | [diff] [blame] | 49 | "emscripten-bits/", |
| 50 | "webgpu-headers/", |
Corentin Wallez | 05623df | 2019-09-18 23:19:31 +0000 | [diff] [blame] | 51 | ] |
| 52 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 53 | # Template to help invoking Dawn code generators based on generator_lib |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 54 | # |
| 55 | # dawn_generator("my_target_gen") { |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 56 | # # The script and generator specific arguments |
| 57 | # script = [ "my_awesome_generator.py" ] |
| 58 | # args = [ |
| 59 | # "--be-awesome", |
| 60 | # "yes" |
| 61 | # ] |
| 62 | # |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 63 | # # The list of expected outputs, generation fails if there's a mismatch |
| 64 | # outputs = [ |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 65 | # "MyAwesomeTarget.cpp", |
| 66 | # "MyAwesomeTarget.h", |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 67 | # ] |
| 68 | # } |
| 69 | # |
| 70 | # Using the generated files is done like so: |
| 71 | # |
| 72 | # shared_library("my_target") { |
| 73 | # deps = [ ":my_target_gen "] |
| 74 | # sources = get_target_outputs(":my_target_gen") |
| 75 | # } |
| 76 | # |
| 77 | template("dawn_generator") { |
David 'Digit' Turner | 5dee3e8 | 2019-06-24 14:31:06 +0000 | [diff] [blame] | 78 | generator_lib_action(target_name) { |
| 79 | forward_variables_from(invoker, "*") |
Corentin Wallez | a9a84df | 2019-09-19 23:30:42 +0000 | [diff] [blame] | 80 | |
| 81 | # Set arguments required to find the python libraries for the generator |
David 'Digit' Turner | 5dee3e8 | 2019-06-24 14:31:06 +0000 | [diff] [blame] | 82 | generator_lib_dir = "${dawn_root}/generator" |
| 83 | jinja2_path = dawn_jinja2_dir |
Corentin Wallez | a9a84df | 2019-09-19 23:30:42 +0000 | [diff] [blame] | 84 | |
| 85 | # Force Dawn's autogenerated file structure to mirror exactly the source |
| 86 | # tree but start at ${dawn_gen_root} instead of ${dawn_root} |
Corentin Wallez | 05623df | 2019-09-18 23:19:31 +0000 | [diff] [blame] | 87 | allowed_output_dirs = dawn_allowed_gen_output_dirs |
Corentin Wallez | a9a84df | 2019-09-19 23:30:42 +0000 | [diff] [blame] | 88 | custom_gen_dir = dawn_gen_root |
| 89 | |
| 90 | # Make sure that we delete stale autogenerated file in directories that are |
| 91 | # no longer used by code generation to avoid include conflicts. |
| 92 | deps = [ "${dawn_root}/generator:remove_stale_autogen_files" ] |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 93 | } |
| 94 | } |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 95 | |
| 96 | # Helper generator for calling the generator from dawn.json |
| 97 | # |
| 98 | # dawn_json_generator("my_target_gen") { |
| 99 | # # Which generator target to output |
| 100 | # target = "my_target" |
| 101 | # |
| 102 | # # Also supports `outputs` and `custom_gen_dir` like dawn_generator. |
| 103 | # } |
| 104 | template("dawn_json_generator") { |
| 105 | dawn_generator(target_name) { |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 106 | script = "${dawn_root}/generator/dawn_json_generator.py" |
| 107 | |
| 108 | # The base arguments for the generator: from this dawn.json, generate this |
| 109 | # target using templates in this directory. |
| 110 | args = [ |
| 111 | "--dawn-json", |
| 112 | rebase_path("${dawn_root}/dawn.json", root_build_dir), |
| 113 | "--wire-json", |
| 114 | rebase_path("${dawn_root}/dawn_wire.json", root_build_dir), |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 115 | "--targets", |
| 116 | invoker.target, |
| 117 | ] |
| 118 | |
Corentin Wallez | df69f24 | 2019-06-13 10:22:32 +0000 | [diff] [blame] | 119 | forward_variables_from(invoker, "*", [ "target" ]) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 120 | } |
| 121 | } |