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/ark_root.gni") 15 16if (is_standard_system) { 17 import("$ark_root/platforms/ohos/ark_config.gni") 18} else { 19 import("$ark_root/platforms/common/ark_config.gni") 20} 21 22declare_args() { 23 enabled_plugins = default_enabled_plugins 24 enabled_pac_data_protect = false 25} 26 27if (!ark_standalone_build && !(defined(is_arkui_x) && is_arkui_x) && is_ohos && 28 is_standard_system && target_cpu == "arm64" && !is_emulator && 29 defined(global_parts_info) && 30 defined(global_parts_info.security_code_signature)) { 31 enabled_pac_data_protect = true 32} 33 34if (current_cpu == "arm") { 35 if (!defined(arm_float_abi) || arm_float_abi == "") { 36 arm_float_abi = "softfp" 37 } 38 39 assert(arm_float_abi == "soft" || arm_float_abi == "softfp" || 40 arm_float_abi == "hard", 41 "arm_float_abi should be soft, softfp or hard") 42} 43 44# We don't support x64 compiler in GN build, since asmjit is not available here 45ark_enable_compiler_x64 = false 46 47ark_enable_global_register_variables = true 48enable_bytecode_optimizer = true 49enable_relayout_profile = false 50 51sdk_libc_secshared_dep = "bounds_checking_function:libsec_shared" 52sdk_libc_secshared_config = 53 "$ark_third_party_root/bounds_checking_function:libsec_public_config" 54 55if (is_mingw || is_mac || is_linux || target_os == "ios" || 56 target_os == "android" || (is_build_sdk && is_ohos)) { 57 sdk_libc_secshared_dep = "bounds_checking_function:libsec_static" 58} 59 60is_mob = !ark_standalone_build && !is_standard_system && 61 (current_cpu != "arm" || is_wearable_product) 62 63enable_hilog = 64 !ark_standalone_build && is_standard_system && current_os == "ohos" && 65 (current_cpu == "arm64" || current_cpu == "arm") 66 67## TODO add other arch 68 69# Generate file for a template and YAML data provided. 70# 71# Mandatory arguments: 72# data_file -- YAML data full name 73# template_file -- template full name 74# output_file -- output file full name 75# requires -- a list of scripts that provide data-querying API for templates 76# extra_dependencies -- a list of files that should be considered as dependencies, must be lable 77template("ark_gen_file") { 78 assert(defined(invoker.data_file), "data_file is required!") 79 assert(defined(invoker.template_file), "template_file is required!") 80 assert(defined(invoker.output_file), "output_file is required!") 81 82 requires = "" 83 if (defined(invoker.requires)) { 84 requires = string_join(",", rebase_path(invoker.requires, root_build_dir)) 85 } 86 87 extra_dependencies = [] 88 if (defined(invoker.extra_dependencies)) { 89 extra_dependencies += invoker.extra_dependencies 90 } 91 92 positional_argv = [] 93 if (defined(invoker.extra_argv)) { 94 positional_argv += invoker.extra_argv 95 } 96 keyword_argv = [ 97 "--template", 98 rebase_path(invoker.template_file, root_build_dir), 99 "--data", 100 rebase_path(invoker.data_file, root_build_dir), 101 "--require", 102 requires, 103 "--output", 104 rebase_path(invoker.output_file), 105 ] 106 107 action("$target_name") { 108 script = "$ark_root/isa/gen.rb" 109 110 # rerun action when data file or template file update 111 inputs = [ 112 invoker.template_file, 113 invoker.data_file, 114 ] 115 if (defined(invoker.requires)) { 116 inputs += invoker.requires 117 } 118 outputs = [ invoker.output_file ] 119 args = positional_argv + keyword_argv 120 deps = extra_dependencies 121 } 122} 123 124template("concat_yamls") { 125 assert(defined(invoker.output_file), "output_file is required!") 126 assert(defined(invoker.default_file), "default_file is required!") 127 128 extra_dependencies = [] 129 if (defined(invoker.extra_dependencies)) { 130 extra_dependencies += invoker.extra_dependencies 131 } 132 133 outputs = [ invoker.output_file ] 134 135 action("$target_name") { 136 script = "$ark_root/templates/concat_yamls.sh" 137 138 # rerun action when data file or template file update 139 inputs = [ invoker.default_file ] 140 141 args = [ 142 rebase_path(invoker.output_file, root_build_dir), 143 rebase_path(invoker.default_file, root_build_dir), 144 ] 145 146 foreach(yaml, invoker.add_yamls) { 147 args += [ rebase_path(yaml, root_build_dir) ] 148 } 149 150 deps = extra_dependencies 151 } 152} 153 154template("merge_yamls") { 155 assert(defined(invoker.output_file), "output_file is required!") 156 assert(defined(invoker.add_yamls), "add_yamls is required!") 157 158 extra_dependencies = [] 159 if (defined(invoker.extra_dependencies)) { 160 extra_dependencies += invoker.extra_dependencies 161 } 162 163 outputs = [ invoker.output_file ] 164 165 action("$target_name") { 166 script = "$ark_root/templates/merge.rb" 167 168 data = [] 169 foreach(yaml, invoker.add_yamls) { 170 data += [ rebase_path(yaml, root_build_dir) ] 171 } 172 args = [ 173 "-d", 174 string_join(",", data), 175 "-o", 176 rebase_path(invoker.output_file, root_build_dir), 177 ] 178 179 deps = extra_dependencies 180 } 181} 182 183# Generate files based on templates and YAML data provided. 184# Adds targets for every template. Also adds a target for the whole function invocation 185# with name ${data_name}_gen_${PROJECT_NAME} for ease of declaring dependencies on generated files. 186# 187# Mandatory arguments: 188# * data -- data source, YAML file 189# * template_files -- a list of templates to generate files 190# * requires -- a list of Ruby scripts that provide data-querying API for templates 191# 192# Optional arguments: 193# * sources -- a directory with templates, default is ${PROJECT_SOURCE_DIR}/templates 194# * destination -- a directory for output files, default is ${PANDA_BINARY_ROOT} 195# * extra_dependencies -- a list of files that should be considered as dependencies 196# * extra_argv -- a list of positional arguments that could be accessed in '.erb' files via ARGV[] 197template("ark_gen") { 198 assert(defined(invoker.data), "data were not passed to ark_gen") 199 assert(defined(invoker.template_files), 200 "template_files were not passed to ark_gen") 201 202 dir = "" 203 if (defined(invoker.sources)) { 204 dir = invoker.sources 205 } else { 206 dir = "templates" 207 } 208 209 destination = "" 210 if (defined(invoker.destination)) { 211 destination = invoker.destination 212 } else { 213 destination = target_out_dir 214 } 215 216 input_requires = "" 217 if (defined(invoker.requires)) { 218 input_requires = invoker.requires 219 } 220 221 foreach(t, invoker.template_files) { 222 name = string_replace(t, ".erb", "") 223 output = "${destination}/${name}" 224 name = string_replace(name, ".", "_") 225 name = string_replace(name, "/", "_") 226 target = "${target_name}_${name}" 227 228 ark_gen_file(target) { 229 data_file = invoker.data 230 template_file = "${dir}/${t}" 231 output_file = output 232 requires = input_requires 233 extra_dependencies = [] 234 if (defined(invoker.extra_dependencies)) { 235 extra_dependencies += invoker.extra_dependencies 236 } 237 extra_argv = [] 238 if (defined(invoker.extra_argv)) { 239 extra_argv += invoker.extra_argv 240 } 241 } 242 } 243} 244 245# Calls `ark_gen` for ISA YAML. 246# Adds targets for every template. Also adds a target for the whole function invocation 247# with name isa_gen_${PROJECT_NAME} for ease of declaring dependencies on generated files. 248# 249# Mandatory arguments: 250# * template_files -- a list of templates to generate files 251# 252# Optional arguments: 253# * sources -- a directory with templates, default is ${PROJECT_SOURCE_DIR}/templates 254# * destination -- a directory for output files, default is ${target_out_dir} 255# * requires -- if defined, will require additional Ruby files for template generation, must be list 256# * extra_dependencies -- a list of files that should be considered as dependencies lable, must be list, not used 257template("ark_isa_gen") { 258 isa_data = "$root_gen_dir/isa/isa.yaml" 259 isa_requires = [ "$ark_root/isa/isapi.rb" ] 260 if (defined(invoker.requires)) { 261 isa_requires += invoker.requires 262 } 263 264 dependencies = [ "$ark_root/isa:isa_combine" ] 265 if (defined(invoker.extra_dependencies)) { 266 dependencies += invoker.extra_dependencies 267 } 268 269 ark_gen("$target_name") { 270 data = isa_data 271 template_files = invoker.template_files 272 sources = invoker.sources 273 destination = invoker.destination 274 requires = isa_requires 275 extra_dependencies = dependencies 276 } 277} 278