1# Copyright (c) 2021-2022 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_root.gni") 15import("//build/ohos.gni") 16 17ark_subsystem_name = "arkcompiler" 18ark_part_name = "runtime_core" 19 20if (is_standard_system) { 21 import("$ark_root/platforms/ohos/ark_config.gni") 22} else { 23 import("$ark_root/platforms/mobile/ark_config.gni") 24} 25 26declare_args() { 27 ark_enabled_plugins = default_ark_enabled_plugins 28 extras = [] 29 if (!defined(is_ohos)) { 30 is_ohos = false 31 } 32 if (!defined(is_standard_system)) { 33 is_standard_system = true 34 } 35} 36 37if (current_cpu == "arm") { 38 if (!defined(arm_float_abi) || arm_float_abi == "") { 39 arm_float_abi = "softfp" 40 } 41 42 assert(arm_float_abi == "soft" || arm_float_abi == "softfp" || 43 arm_float_abi == "hard", 44 "arm_float_abi should be soft, softfp or hard") 45} 46 47ark_root_gen_dir = "$root_gen_dir/ark_sig" 48 49concat_gen_dir = 50 get_label_info("$ark_root:concat_plugins_yamls", "target_gen_dir") 51ark_plugin_options_yaml = "$concat_gen_dir/plugin_options.yaml" 52 53isa_gen_dir = get_label_info("$ark_root/isa:isa_combine", "target_gen_dir") 54ark_isa_yaml = "$isa_gen_dir/isa.yaml" 55 56enable_irtoc = true 57enable_codegen = true 58is_llvmbackend = false 59if (ark_standalone_build) { 60 enable_irtoc = true 61 enable_codegen = true 62 is_llvmbackend = true 63} else if (target_cpu == "x64" || target_cpu == "x86_64") { 64 enable_irtoc = false 65 enable_codegen = false 66} 67ark_enable_global_register_variables = true 68enable_bytecode_optimizer = true 69enable_relayout_profile = false 70vixl_with_panda = true 71 72sdk_libc_secshared_dep = "" 73sdk_libc_secshared_config = "" 74 75if (ark_standalone_build) { 76 sdk_libc_secshared_dep = "$ark_third_party_root/securec:libc_secshared" 77 sdk_libc_secshared_config = 78 "$ark_third_party_root/securec:libsec_public_config" 79 80 if (is_mingw || is_mac || is_linux) { 81 sdk_libc_secshared_dep = "$ark_third_party_root/securec:libc_secstatic" 82 } 83} else { 84 # For OpenHarmony build, always link with the static lib: 85 sdk_libc_secshared_dep = 86 "$ark_third_party_root/bounds_checking_function:libsec_static" 87 sdk_libc_secshared_config = 88 "$ark_third_party_root/bounds_checking_function:libsec_public_config" 89} 90 91is_mob = !is_ohos && !is_linux && !is_mingw && !is_mac && 92 (current_cpu != "arm" || is_wearable_product) 93 94if (is_ohos && is_standard_system) { 95 hilog_root = "//base/hiviewdfx/hilog/interfaces/native/innerkits" 96} 97 98## TODO add other arch 99 100# Generate file for a template and YAML data provided. 101# 102# Mandatory arguments: 103# data_file -- YAML data full name 104# template_file -- template full name 105# output_file -- output file full name 106# requires -- a list of scripts that provide data-querying API for templates 107# extra_dependencies -- a list of files that should be considered as dependencies, must be lable 108template("ark_gen_file") { 109 assert(defined(invoker.data_file), "data_file is required!") 110 assert(defined(invoker.template_file), "template_file is required!") 111 assert(defined(invoker.output_file), "output_file is required!") 112 113 requires = "" 114 if (defined(invoker.requires)) { 115 requires = string_join(",", rebase_path(invoker.requires, root_build_dir)) 116 } 117 118 extra_dependencies = [] 119 if (defined(invoker.extra_dependencies)) { 120 extra_dependencies += invoker.extra_dependencies 121 } 122 123 positional_argv = [] 124 if (defined(invoker.extra_argv)) { 125 positional_argv += invoker.extra_argv 126 } 127 keyword_argv = [ 128 "--template", 129 rebase_path(invoker.template_file, root_build_dir), 130 "--data", 131 rebase_path(invoker.data_file, root_build_dir), 132 "--require", 133 requires, 134 "--output", 135 rebase_path(invoker.output_file), 136 ] 137 138 action("$target_name") { 139 script = "$ark_root/isa/gen.rb" 140 141 # rerun action when data file or template file update 142 inputs = [ 143 invoker.template_file, 144 invoker.data_file, 145 ] 146 outputs = [ invoker.output_file ] 147 args = positional_argv + keyword_argv 148 deps = extra_dependencies 149 } 150} 151 152template("concat_yamls") { 153 assert(defined(invoker.output_file), "output_file is required!") 154 assert(defined(invoker.default_file), "default_file is required!") 155 156 extra_dependencies = [] 157 if (defined(invoker.extra_dependencies)) { 158 extra_dependencies += invoker.extra_dependencies 159 } 160 161 outputs = [ invoker.output_file ] 162 163 action("$target_name") { 164 script = "$ark_root/templates/concat_yamls.sh" 165 166 # rerun action when data file or template file update 167 inputs = [ invoker.default_file ] 168 169 args = [ 170 rebase_path(invoker.output_file, root_build_dir), 171 rebase_path(invoker.default_file, root_build_dir), 172 ] 173 174 foreach(yaml, invoker.add_yamls) { 175 args += [ rebase_path(yaml, root_build_dir) ] 176 } 177 178 deps = extra_dependencies 179 } 180} 181 182template("merge_yamls") { 183 assert(defined(invoker.output_file), "output_file is required!") 184 assert(defined(invoker.add_yamls), "add_yamls is required!") 185 186 extra_dependencies = [] 187 if (defined(invoker.extra_dependencies)) { 188 extra_dependencies += invoker.extra_dependencies 189 } 190 191 outputs = [ invoker.output_file ] 192 193 action("$target_name") { 194 script = "$ark_root/templates/merge.rb" 195 196 data = [] 197 foreach(yaml, invoker.add_yamls) { 198 data += [ rebase_path(yaml, root_build_dir) ] 199 } 200 args = [ 201 "-d", 202 string_join(",", data), 203 "-o", 204 rebase_path(invoker.output_file, root_build_dir), 205 ] 206 207 deps = extra_dependencies 208 } 209} 210 211# Generate files based on templates and YAML data provided. 212# Adds targets for every template. Also adds a target for the whole function invocation 213# with name ${data_name}_gen_${PROJECT_NAME} for ease of declaring dependencies on generated files. 214# 215# Mandatory arguments: 216# * data -- data source, YAML file 217# * template_files -- a list of templates to generate files 218# * requires -- a list of Ruby scripts that provide data-querying API for templates 219# 220# Optional arguments: 221# * sources -- a directory with templates, default is ${PROJECT_SOURCE_DIR}/templates 222# * destination -- a directory for output files, default is ${PANDA_BINARY_ROOT} 223# * extra_dependencies -- a list of files that should be considered as dependencies 224# * extra_argv -- a list of positional arguments that could be accessed in '.erb' files via ARGV[] 225template("ark_gen") { 226 assert(defined(invoker.data), "data were not passed to ark_gen") 227 assert(defined(invoker.template_files), 228 "template_files were not passed to ark_gen") 229 230 dir = "" 231 if (defined(invoker.sources)) { 232 dir = invoker.sources 233 } else { 234 dir = "templates" 235 } 236 237 destination = "" 238 if (defined(invoker.destination)) { 239 destination = invoker.destination 240 } else { 241 destination = target_out_dir 242 } 243 244 input_requires = "" 245 if (defined(invoker.requires)) { 246 input_requires = invoker.requires 247 } 248 249 foreach(t, invoker.template_files) { 250 name = string_replace(t, ".erb", "") 251 output = "${destination}/${name}" 252 name = string_replace(name, ".", "_") 253 name = string_replace(name, "/", "_") 254 target = "${target_name}_${name}" 255 256 ark_gen_file(target) { 257 data_file = invoker.data 258 template_file = "${dir}/${t}" 259 output_file = output 260 requires = input_requires 261 extra_dependencies = [] 262 if (defined(invoker.extra_dependencies)) { 263 extra_dependencies += invoker.extra_dependencies 264 } 265 extra_argv = [] 266 if (defined(invoker.extra_argv)) { 267 extra_argv += invoker.extra_argv 268 } 269 } 270 } 271} 272 273# Calls `ark_gen` for ISA YAML. 274# Adds targets for every template. Also adds a target for the whole function invocation 275# with name isa_gen_${PROJECT_NAME} for ease of declaring dependencies on generated files. 276# 277# Mandatory arguments: 278# * template_files -- a list of templates to generate files 279# 280# Optional arguments: 281# * sources -- a directory with templates, default is ${PROJECT_SOURCE_DIR}/templates 282# * destination -- a directory for output files, default is ${target_out_dir} 283# * requires -- if defined, will require additional Ruby files for template generation, must be list 284# * extra_dependencies -- a list of files that should be considered as dependencies lable, must be list, not used 285template("ark_isa_gen") { 286 isa_data = "$ark_isa_yaml" 287 isa_requires = [ "$ark_root/isa/isapi.rb" ] 288 if (defined(invoker.requires)) { 289 isa_requires += invoker.requires 290 } 291 292 dependencies = [ "$ark_root/isa:isa_combine" ] 293 if (defined(invoker.extra_dependencies)) { 294 dependencies += invoker.extra_dependencies 295 } 296 297 ark_gen("$target_name") { 298 data = isa_data 299 template_files = invoker.template_files 300 sources = invoker.sources 301 destination = invoker.destination 302 requires = isa_requires 303 extra_dependencies = dependencies 304 } 305} 306 307# Run ark_asm 308# 309# Arguments: 310# * input_file -- Path to the source assembly code 311# * output_file -- Path to the generated binary code 312template("ark_asm_gen") { 313 action(target_name) { 314 ark_asm_root_out = 315 get_label_info("$ark_root/assembler:arkts_asm(${host_toolchain})", 316 "root_out_dir") 317 script = ark_asm_root_out + "/$ark_subsystem_name/$ark_part_name/ark_asm" 318 319 inputs = [ invoker.input_file ] 320 outputs = [ invoker.output_file ] 321 args = [ 322 rebase_path(invoker.input_file, root_build_dir), 323 rebase_path(invoker.output_file, root_build_dir), 324 ] 325 326 deps = [ "$ark_root/assembler:arkts_asm(${host_toolchain})" ] 327 } 328} 329 330# Run es2panda 331# 332# Arguments: 333# The same you would pass to action except script and deps. 334template("es2panda_gen") { 335 action(target_name) { 336 es2panda_root_out = 337 get_label_info("$ark_es2panda_root/aot:es2panda(${host_toolchain})", 338 "root_out_dir") 339 script = es2panda_root_out + "/arkcompiler/ets_frontend/es2panda" 340 deps = [ "$ark_es2panda_root/aot:es2panda(${host_toolchain})" ] 341 342 inputs = invoker.inputs 343 outputs = invoker.outputs 344 sources = invoker.sources 345 args = invoker.args 346 } 347} 348