1# Copyright (c) 2021-2025 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") 15import("//arkcompiler/runtime_core/static_vm_config.gni") 16import("$ark_root/plugins/plugins.gni") 17 18if (ark_standalone_build) { 19 import("$build_root/ark.gni") 20} else { 21 import("//build/ohos.gni") 22} 23 24group("ark_packages") { 25 if (enable_static_vm) { 26 deps = plugin_ark_packages 27 if (host_os != "mac") { 28 deps += [ 29 "$ark_root/compiler:libarktscompiler", 30 "$ark_root/compiler/aot:libarkaotmanager", 31 "$ark_root/libpandabase:libarktsbase", 32 "$ark_root/libpandafile:libarktsfile", 33 "$ark_root/libpandafile/external:libarkfileExt", 34 "$ark_root/libpandafile/external:libarksupport", 35 "$ark_root/libziparchive:libarktsziparchive", 36 "$ark_root/panda:arkts_bin", 37 "$ark_root/runtime:libarkruntime", 38 "$ark_root/runtime/tooling/inspector:libarkinspector", 39 "$ark_root/verification/verifier:verifier.config", 40 "$ark_root/verification/verifier:verifier_bin", 41 ] 42 if (enable_codegen) { 43 deps += [ 44 "$ark_root/compiler/optimizer/code_generator:libarkencoder", 45 "$ark_root/compiler/tools/paoc:ark_aot", 46 ] 47 } 48 } 49 } 50} 51 52group("ark_host_linux_tools_packages") { 53 deps = plugin_ark_host_linux_tools_packages 54 if (host_os != "mac" && current_cpu != "arm") { 55 deps += [ 56 "$ark_root/abc2program:arkts_abc2prog(${host_toolchain})", 57 "$ark_root/abc2program:arkts_abc2program(${host_toolchain})", 58 "$ark_root/assembler:arkts_asm(${host_toolchain})", 59 "$ark_root/compiler:libarktscompiler(${host_toolchain})", 60 "$ark_root/compiler/aot:libarkaotmanager(${host_toolchain})", 61 "$ark_root/libpandabase:libarktsbase(${host_toolchain})", 62 "$ark_root/libpandafile:libarktsfile(${host_toolchain})", 63 "$ark_root/libpandafile/external:libarkfileExt(${host_toolchain})", 64 "$ark_root/libpandafile/external:libarksupport(${host_toolchain})", 65 "$ark_root/libziparchive:libarktsziparchive(${host_toolchain})", 66 "$ark_root/panda:arkts_bin(${host_toolchain})", 67 "$ark_root/runtime:libarkruntime(${host_toolchain})", 68 ] 69 if (enable_codegen) { 70 deps += [ "$ark_root/compiler/optimizer/code_generator:libarkencoder(${host_toolchain})" ] 71 } 72 73 # TODO: don't exclude these targets from OHOS build 74 if (ark_static_standalone_build) { 75 deps += [ 76 "$ark_root/compiler/tools/aotdump:ark_aotdump(${host_toolchain})", 77 "$ark_root/compiler/tools/paoc:ark_aot(${host_toolchain})", 78 "$ark_root/disassembler:arkts_disasm(${host_toolchain})", 79 "$ark_root/static_linker:ark_link(${host_toolchain})", 80 ] 81 } 82 } 83} 84 85group("ark_host_windows_tools_packages") { 86 deps = plugin_ark_host_windows_tools_packages 87 if (host_os != "mac" && current_cpu != "arm" && 88 !ark_static_standalone_build && !ark_standalone_build) { 89 deps += [ 90 "$ark_root/abc2program:arkts_abc2prog(//build/toolchain/mingw:mingw_x86_64)", 91 "$ark_root/abc2program:arkts_abc2program(//build/toolchain/mingw:mingw_x86_64)", 92 "$ark_root/assembler:arkts_asm(//build/toolchain/mingw:mingw_x86_64)", 93 "$ark_root/disassembler:arkts_disasm(//build/toolchain/mingw:mingw_x86_64)", 94 "$ark_root/static_linker:ark_link(//build/toolchain/mingw:mingw_x86_64)", 95 ] 96 } 97} 98 99group("ark_host_mac_tools_packages") { 100 deps = plugin_ark_host_mac_tools_packages 101 if (host_os == "mac") { 102 if (host_cpu == "arm64") { 103 deps += [ 104 "$ark_root/abc2program:arkts_abc2prog($build_root/toolchain/mac:clang_arm64)", 105 "$ark_root/abc2program:arkts_abc2program($build_root/toolchain/mac:clang_arm64)", 106 "$ark_root/assembler:arkts_asm($build_root/toolchain/mac:clang_arm64)", 107 "$ark_root/disassembler:arkts_disasm($build_root/toolchain/mac:clang_arm64)", 108 "$ark_root/libpandabase:libarktsbase($build_root/toolchain/mac:clang_arm64)", 109 "$ark_root/libpandafile:libarktsfile($build_root/toolchain/mac:clang_arm64)", 110 "$ark_root/libziparchive:libarktsziparchive($build_root/toolchain/mac:clang_arm64)", 111 "$ark_root/static_linker:ark_link($build_root/toolchain/mac:clang_arm64)", 112 ] 113 } else { 114 deps += [ 115 "$ark_root/abc2program:arkts_abc2prog($build_root/toolchain/mac:clang_x64)", 116 "$ark_root/abc2program:arkts_abc2program($build_root/toolchain/mac:clang_x64)", 117 "$ark_root/assembler:arkts_asm($build_root/toolchain/mac:clang_x64)", 118 "$ark_root/disassembler:arkts_disasm($build_root/toolchain/mac:clang_x64)", 119 "$ark_root/libpandabase:libarktsbase($build_root/toolchain/mac:clang_x64)", 120 "$ark_root/libpandafile:libarktsfile($build_root/toolchain/mac:clang_x64)", 121 "$ark_root/libziparchive:libarktsziparchive($build_root/toolchain/mac:clang_x64)", 122 "$ark_root/static_linker:ark_link($build_root/toolchain/mac:clang_x64)", 123 ] 124 } 125 } 126} 127 128group("ark_host_tests") { 129 testonly = true 130 deps = [] 131 if (defined(extras)) { 132 foreach(ext, extras) { 133 deps += [ "${ext}:host_tests" ] 134 } 135 } 136} 137 138# Common config for ark source 139config("ark_config") { 140 if (!ark_static_standalone_build) { 141 visibility = [ 142 "$abckit_root/*", 143 "$ark_es2panda_root:libes2panda", 144 "$ark_es2panda_root:libes2panda_frontend_static", 145 "$ark_es2panda_root:libes2panda_public", 146 "$ark_es2panda_root:libes2panda_public_frontend_static", 147 "$ark_es2panda_root/aot:ets2panda", 148 "$ark_es2panda_root/bindings:ts_bindings", 149 "$ark_es2panda_root/driver/dependency_analyzer:dependency_analyzer", 150 "$ark_es2panda_root/lsp:libes2panda_lsp", 151 "$ark_es2panda_root/lsp:libes2panda_lsp_static", 152 "$ark_third_party_root/asmjit:*", 153 "$ark_third_party_root/vixl:*", 154 "./*", 155 ] 156 } 157 158 include_dirs = [ 159 "$ark_root", 160 get_label_info(":create_pipeline(${default_toolchain})", "target_gen_dir"), 161 ] 162 defines = [ "PANDA_TARGET_MOBILE_WITH_MANAGED_LIBS=1" ] 163 if (enable_codegen) { 164 defines += [ "PANDA_COMPILER_ENABLE" ] 165 } 166 if (is_emulator) { 167 defines += [ "PANDA_TARGET_EMULATOR" ] 168 } 169 170 if (is_llvm_interpreter || is_llvm_fastpath) { 171 defines += [ "PANDA_LLVM_IRTOC" ] 172 if (is_llvm_interpreter) { 173 defines += [ "PANDA_LLVM_INTERPRETER" ] 174 } 175 if (is_llvm_fastpath) { 176 defines += [ "PANDA_LLVM_FASTPATH" ] 177 } 178 } 179 if (is_llvm_aot) { 180 defines += [ "PANDA_LLVM_AOT" ] 181 } 182 183 if (is_ohos && is_standard_system) { 184 defines += [ "PANDA_TARGET_OHOS" ] 185 } 186 187 if (is_linux) { 188 defines += [ 189 "PANDA_TARGET_UNIX", 190 "PANDA_TARGET_LINUX", 191 "PANDA_WITH_BYTECODE_OPTIMIZER", 192 "PANDA_WITH_COMPILER", 193 ] 194 if (enable_irtoc) { 195 defines += [ "PANDA_WITH_IRTOC" ] 196 } 197 if (enable_codegen) { 198 defines += [ "PANDA_WITH_CODEGEN" ] 199 } 200 if (!is_asan) { 201 defines += [ "PANDA_USE_FUTEX" ] 202 } 203 } else if (is_mingw) { 204 defines += [ 205 "PANDA_TARGET_WINDOWS", 206 "PANDA_WITH_BYTECODE_OPTIMIZER", 207 "PANDA_WITH_COMPILER", 208 "__LIBMSVCRT__", 209 ] 210 if (enable_irtoc) { 211 defines += [ "PANDA_WITH_IRTOC" ] 212 } 213 if (enable_codegen) { 214 defines += [ "PANDA_WITH_CODEGEN" ] 215 } 216 } else if (is_mac) { 217 defines += [ 218 "PANDA_TARGET_UNIX", 219 "PANDA_TARGET_MACOS", 220 "PANDA_WITH_BYTECODE_OPTIMIZER", 221 "PANDA_WITH_COMPILER", 222 223 # "PANDA_USE_FUTEX", 224 ] 225 if (enable_irtoc) { 226 defines += [ "PANDA_WITH_IRTOC" ] 227 } 228 if (enable_codegen) { 229 defines += [ "PANDA_WITH_CODEGEN" ] 230 } 231 } else if (is_mob) { 232 defines += [ 233 "PANDA_TARGET_UNIX", 234 "PANDA_USE_FUTEX", 235 "PANDA_TARGET_MOBILE", 236 "PANDA_TARGET_MOBILE_WITH_NATIVE_LIBS", 237 ] 238 } else if (is_ohos) { 239 defines += [ 240 # TODO: use PANDA_TARGET_OHOS instead of PANDA_TARGET_UNIX 241 "PANDA_TARGET_UNIX", 242 "PANDA_WITH_COMPILER", 243 ] 244 if (!is_asan) { 245 defines += [ "PANDA_USE_FUTEX" ] 246 } 247 if (enable_irtoc) { 248 defines += [ "PANDA_WITH_IRTOC" ] 249 } 250 if (enable_codegen) { 251 defines += [ "PANDA_WITH_CODEGEN" ] 252 } 253 } else { 254 defines += [ 255 "PANDA_TARGET_UNIX", 256 "PANDA_USE_FUTEX", 257 ] 258 } 259 260 if (!is_debug) { 261 defines += [ "NDEBUG" ] 262 } 263 264 cflags_cc = [ 265 "-std=c++17", 266 "-pedantic", 267 "-Wall", 268 "-Wextra", 269 "-Werror", 270 "-fno-rtti", 271 "-fno-exceptions", 272 "-Wno-invalid-offsetof", 273 274 "-Wno-gnu-statement-expression", 275 "-Wno-unused-parameter", 276 "-Wno-unused-result", 277 ] 278 279 cflags_c = [] 280 281 if (ark_static_standalone_build) { 282 cflags_cc += [ "-Wno-bitwise-instead-of-logical" ] 283 } 284 285 if (!is_mac && use_pbqp) { 286 cflags_cc += [ 287 # PBQP regalloc 288 "-mllvm", 289 "-regalloc=pbqp", 290 ] 291 } 292 293 if (is_fastverify) { 294 cflags_cc += [ 295 "-O3", 296 "-ggdb3", 297 "-fno-omit-frame-pointer", 298 "-D_GLIBCXX_ASSERTIONS", 299 ] 300 cflags_c += [ 301 "-O3", 302 "-ggdb3", 303 "-fno-omit-frame-pointer", 304 "-D_GLIBCXX_ASSERTIONS", 305 ] 306 } else if (is_debug) { 307 cflags_cc += [ 308 "-Og", 309 "-ggdb3", 310 "-gdwarf-4", 311 ] 312 } 313 314 if (is_asan) { 315 cflags_cc += [ "-g" ] 316 if (defined(use_hwasan) && use_hwasan) { 317 defines += [ "__SANITIZE_HWADDRESS__" ] 318 } else { 319 defines += [ "__SANITIZE_ADDRESS__" ] 320 } 321 print("ASAN is enabled") 322 } 323 324 configs = plugin_ark_configs 325 326 if (ark_static_standalone_build) { 327 configs += [ sdk_libc_secshared_config ] 328 } 329 330 if (ark_hybrid) { 331 defines += [ "ARK_HYBRID" ] 332 } 333 334 if (current_cpu == "arm") { 335 cflags_cc += [ 336 "-march=armv7-a", 337 "-mfloat-abi=${arm_float_abi}", 338 "-marm", 339 "-mfpu=vfp", 340 ] 341 342 if (arm_float_abi == "soft") { 343 defines += [ "PANDA_TARGET_ARM32_ABI_SOFT=1" ] 344 } else if (arm_float_abi == "softfp") { 345 defines += [ "PANDA_TARGET_ARM32_ABI_SOFTFP=1" ] 346 } else if (arm_float_abi == "hard") { 347 defines += [ "PANDA_TARGET_ARM32_ABI_HARD=1" ] 348 } 349 350 defines += [ 351 "PANDA_TARGET_32", 352 "PANDA_TARGET_ARM32", 353 ] 354 } else if (current_cpu == "arm64") { 355 defines += [ 356 "PANDA_TARGET_ARM64", 357 "PANDA_TARGET_64", 358 "PANDA_ENABLE_GLOBAL_REGISTER_VARIABLES", 359 ] 360 if (!defined(ark_hybrid) || !ark_hybrid) { 361 defines += [ "PANDA_USE_32_BIT_POINTER" ] 362 } 363 } else if (current_cpu == "x86") { 364 defines += [ 365 "PANDA_TARGET_32", 366 "PANDA_TARGET_X86", 367 ] 368 } else if (current_cpu == "amd64" || current_cpu == "x64" || 369 current_cpu == "x86_64") { 370 defines += [ 371 "PANDA_TARGET_64", 372 "PANDA_TARGET_AMD64", 373 ] 374 if (!defined(ark_hybrid) || !ark_hybrid) { 375 defines += [ "PANDA_USE_32_BIT_POINTER" ] 376 } 377 } 378} 379 380concat_yamls("concat_plugins_yamls") { 381 output_file = ark_plugin_options_yaml 382 default_file = "$ark_root/templates/plugin_options.yaml" 383 add_yamls = plugin_option_yamls 384} 385 386concat_yamls("concat_entrypoints_yamls") { 387 output_file = "$target_gen_dir/runtime/entrypoints.yaml" 388 default_file = "$ark_root/runtime/entrypoints/entrypoints.yaml" 389 add_yamls = plugin_entrypoints_yamls 390} 391 392concat_yamls("concat_inst_templates_yamls") { 393 output_file = "$target_gen_dir/compiler/generated/inst_templates.yaml" 394 default_file = "$ark_root/compiler/optimizer/ir_builder/inst_templates.yaml" 395 add_yamls = plugin_inst_templates_yamls 396} 397 398merge_yamls("merge_runtime_options_yamls") { 399 output_file = "$target_gen_dir/runtime_options.yaml" 400 add_yamls = 401 [ "$ark_root/runtime/options.yaml" ] + plugin_runtime_options_yamls 402} 403 404merge_yamls("merge_compiler_options_yamls") { 405 output_file = "$target_gen_dir/compiler/generated/compiler_options.yaml" 406 add_yamls = 407 [ "$ark_root/compiler/compiler.yaml" ] + plugin_compiler_options_yamls 408} 409