1# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//arkcompiler/runtime_core/static_core/ark_config.gni")
15
16plugin_ark_host_linux_tools_packages = []
17plugin_ark_host_mac_tools_packages = []
18plugin_ark_host_windows_tools_packages = []
19plugin_ark_packages = []
20
21plugin_ark_configs = []
22plugin_libarkassembler_configs = []
23plugin_runtime_configs = []
24plugin_runtime_interpreter_impl_configs = []
25plugin_bytecodeopt_configs = []
26
27plugin_arkruntime_header_plugin_deps = []
28plugin_arkruntime_stdlib_plugin_deps = []
29plugin_assembler_deps = []
30plugin_bytecodeopt_deps = []
31plugin_compiler_deps = []
32plugin_runtime_deps = []
33
34plugin_arkdisassembler_sources = []
35plugin_libarkassembler_sources = []
36plugin_libarkbytecodeopt_sources = []
37plugin_libarkcompiler_sources = []
38plugin_runtime_sources = []
39plugin_verifier_sources = []
40plugin_abc2program_sources = []
41
42plugin_entrypoints_yamls = []
43plugin_inst_templates_yamls = []
44plugin_option_yamls = []
45plugin_runtime_options_yamls = []
46plugin_compiler_options_yamls = []
47plugin_runtime_yamls = []
48
49plugin_irtoc_scripts = []
50plugin_irtoc_plugins = []
51
52plugin_isa_paths = []
53
54plugin_create_pipeline_paths = []
55plugin_read_profile_paths = []
56plugin_destroy_profile_paths = []
57plugin_find_method_in_profile_paths = []
58plugin_dump_profile_paths = []
59plugin_clear_profile_paths = []
60plugin_profiling_includes_paths = []
61plugin_profiling_includes_disasm_paths = []
62plugin_get_profiling_any_type_paths = []
63
64plugin_enable_bytecode_optimizer = false
65
66# All paths and labels in the exported variables should be source-absolute.
67
68foreach(plugin, ark_enabled_plugins) {
69  print("Reading plugin sources: $plugin ($current_toolchain)")
70  _plugin_dir = "$ark_root/plugins/$plugin"
71  _plugin_vars = {
72  }
73
74  # To read variables defined by plugins into a scope while avoiding conflict
75  # with the current scope, we read plugin.gn which should be a wrapper around
76  # subproject_sources.gn that simply `import`s the latter. The import command
77  # is more powerful than read_file in that it resolves paths relative to the
78  # current file and also has `current_cpu`, etc. values defined which allows to
79  # write more conventional GN code.
80  _plugin_vars = read_file("$_plugin_dir/plugin.gn", "scope")
81
82  if (defined(_plugin_vars.enable_bytecode_optimizer)) {
83    plugin_bytecodeopt_configs += [ "$_plugin_dir:bytecodeopt" ]
84    plugin_enable_bytecode_optimizer = plugin_enable_bytecode_optimizer ||
85                                       _plugin_vars.enable_bytecode_optimizer
86  }
87
88  plugin_ark_host_linux_tools_packages +=
89      [ "$_plugin_dir:ark_host_linux_tools_packages" ]
90  plugin_ark_host_windows_tools_packages +=
91      [ "$_plugin_dir:ark_host_windows_tools_packages" ]
92  plugin_ark_host_mac_tools_packages +=
93      [ "$_plugin_dir:ark_host_mac_tools_packages" ]
94  plugin_ark_packages += [ "$_plugin_dir:ark_packages" ]
95
96  plugin_ark_configs += [ "$_plugin_dir:ark_config" ]
97  plugin_libarkassembler_configs += [ "$_plugin_dir:assembler" ]
98  plugin_runtime_configs += [ "$_plugin_dir:runtime" ]
99  plugin_runtime_interpreter_impl_configs +=
100      [ "$_plugin_dir:runtime_interpreter_impl" ]
101
102  plugin_assembler_deps += [ "$_plugin_dir:assembler_deps" ]
103
104  if (defined(_plugin_vars.arkruntime_header_sub_deps)) {
105    foreach(sub_dep, _plugin_vars.arkruntime_header_sub_deps) {
106      plugin_arkruntime_header_plugin_deps += [ sub_dep ]
107    }
108  }
109  if (defined(_plugin_vars.arkruntime_stdlib_sub_deps)) {
110    foreach(sub_dep, _plugin_vars.arkruntime_stdlib_sub_deps) {
111      plugin_arkruntime_stdlib_plugin_deps += [ sub_dep ]
112    }
113  }
114  if (defined(_plugin_vars.arkbytecodeopt_deps)) {
115    foreach(sub_dep, _plugin_vars.arkbytecodeopt_deps) {
116      plugin_bytecodeopt_deps += [ sub_dep ]
117    }
118  }
119  if (defined(_plugin_vars.arkcompiler_deps)) {
120    foreach(sub_dep, _plugin_vars.arkcompiler_deps) {
121      plugin_compiler_deps += [ sub_dep ]
122    }
123  }
124  if (defined(_plugin_vars.arkruntime_deps)) {
125    foreach(sub_dep, _plugin_vars.arkruntime_deps) {
126      plugin_runtime_deps += [ sub_dep ]
127    }
128  }
129
130  if (defined(_plugin_vars.srcs_abc2program)) {
131    foreach(src, _plugin_vars.srcs_abc2program) {
132      plugin_abc2program_sources += [ "$_plugin_dir/$src" ]
133    }
134  }
135  if (defined(_plugin_vars.srcs_disassembler)) {
136    foreach(src, _plugin_vars.srcs_disassembler) {
137      plugin_arkdisassembler_sources += [ "$_plugin_dir/$src" ]
138    }
139  }
140  if (defined(_plugin_vars.srcs_assembler)) {
141    foreach(src, _plugin_vars.srcs_assembler) {
142      plugin_libarkassembler_sources += [ "$_plugin_dir/$src" ]
143    }
144  }
145  if (defined(_plugin_vars.srcs_bytecode_optimizer)) {
146    foreach(src, _plugin_vars.srcs_bytecode_optimizer) {
147      plugin_libarkbytecodeopt_sources += [ "$_plugin_dir/$src" ]
148    }
149  }
150  if (defined(_plugin_vars.srcs_compiler)) {
151    foreach(src, _plugin_vars.srcs_compiler) {
152      plugin_libarkcompiler_sources += [ "$_plugin_dir/$src" ]
153    }
154  }
155  if (defined(_plugin_vars.srcs_runtime)) {
156    foreach(src, _plugin_vars.srcs_runtime) {
157      plugin_runtime_sources += [ "$_plugin_dir/$src" ]
158    }
159  }
160  if (defined(_plugin_vars.configs_runtime)) {
161    foreach(src, _plugin_vars.configs_runtime) {
162      plugin_runtime_configs += [ "$_plugin_dir/$src" ]
163    }
164  }
165  if (defined(_plugin_vars.srcs_verification)) {
166    foreach(src, _plugin_vars.srcs_verification) {
167      plugin_verifier_sources += [ "$_plugin_dir/$src" ]
168    }
169  }
170
171  if (defined(_plugin_vars.entrypoints_yaml_path)) {
172    plugin_entrypoints_yamls +=
173        [ "$_plugin_dir/${_plugin_vars.entrypoints_yaml_path}" ]
174  }
175  if (defined(_plugin_vars.inst_templates_yaml_path)) {
176    plugin_inst_templates_yamls +=
177        [ "$_plugin_dir/${_plugin_vars.inst_templates_yaml_path}" ]
178  }
179  if (defined(_plugin_vars.option_yaml_path)) {
180    plugin_option_yamls += [ "$_plugin_dir/${_plugin_vars.option_yaml_path}" ]
181  }
182  if (defined(_plugin_vars.runtime_option_yaml_path)) {
183    plugin_runtime_options_yamls +=
184        [ "$_plugin_dir/${_plugin_vars.runtime_option_yaml_path}" ]
185  }
186  if (defined(_plugin_vars.compiler_options_yaml_path)) {
187    plugin_compiler_options_yamls +=
188        [ "$_plugin_dir/${_plugin_vars.compiler_options_yaml_path}" ]
189  }
190  if (defined(_plugin_vars.runtime_yamls)) {
191    plugin_runtime_yamls +=
192        rebase_path(_plugin_vars.runtime_yamls, "", _plugin_dir)
193  }
194  if (defined(_plugin_vars.irtoc_scripts)) {
195    plugin_irtoc_scripts +=
196        rebase_path(_plugin_vars.irtoc_scripts, "", _plugin_dir)
197  }
198  if (defined(_plugin_vars.irtoc_plugins)) {
199    plugin_irtoc_plugins +=
200        rebase_path(_plugin_vars.irtoc_plugins, "", _plugin_dir)
201  }
202  if (defined(_plugin_vars.srcs_isa)) {
203    plugin_isa_paths += rebase_path(_plugin_vars.srcs_isa, "", _plugin_dir)
204  }
205
206  if (defined(_plugin_vars.create_pipeline)) {
207    plugin_create_pipeline_paths +=
208        [ rebase_path(_plugin_vars.create_pipeline, "", _plugin_dir) ]
209  }
210  if (defined(_plugin_vars.read_profile)) {
211    plugin_read_profile_paths +=
212        [ rebase_path(_plugin_vars.read_profile, "", _plugin_dir) ]
213  }
214  if (defined(_plugin_vars.destroy_profile)) {
215    plugin_destroy_profile_paths +=
216        [ rebase_path(_plugin_vars.destroy_profile, "", _plugin_dir) ]
217  }
218  if (defined(_plugin_vars.find_method_in_profile)) {
219    plugin_find_method_in_profile_paths +=
220        [ rebase_path(_plugin_vars.find_method_in_profile, "", _plugin_dir) ]
221  }
222  if (defined(_plugin_vars.dump_profile)) {
223    plugin_dump_profile_paths +=
224        [ rebase_path(_plugin_vars.dump_profile, "", _plugin_dir) ]
225  }
226  if (defined(_plugin_vars.clear_profile)) {
227    plugin_clear_profile_paths +=
228        [ rebase_path(_plugin_vars.clear_profile, "", _plugin_dir) ]
229  }
230  if (defined(_plugin_vars.profiling_includes)) {
231    plugin_profiling_includes_paths +=
232        [ rebase_path(_plugin_vars.profiling_includes, "", _plugin_dir) ]
233  }
234  if (defined(_plugin_vars.profiling_includes_disasm)) {
235    plugin_profiling_includes_disasm_paths +=
236        [ rebase_path(_plugin_vars.profiling_includes_disasm, "", _plugin_dir) ]
237  }
238  if (defined(_plugin_vars.get_profiling_any_type)) {
239    plugin_get_profiling_any_type_paths +=
240        [ rebase_path(_plugin_vars.get_profiling_any_type, "", _plugin_dir) ]
241  }
242}
243