1# Copyright (c) 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("../js_runtime_config.gni") 15 16if (!ark_standalone_build && is_ohos) { 17 import("//build/ohos.gni") 18} 19 20source_Base = [ 21 "base/sys_call.cpp", 22 "base/c_string.cpp", 23 "base/time_utils.cpp", 24 "base/mem_utils.cpp", 25] 26source_Common = [ "common/run_type.cpp" ] 27 28source_Heap = [ 29 "heap/ark_collector/ark_collector.cpp", 30 "heap/ark_collector/copy_barrier.cpp", 31 "heap/ark_collector/idle_barrier.cpp", 32 "heap/ark_collector/enum_barrier.cpp", 33 "heap/ark_collector/marking_barrier.cpp", 34 "heap/ark_collector/remark_barrier.cpp", 35 "heap/ark_collector/preforward_barrier.cpp", 36 "heap/ark_collector/post_marking_barrier.cpp", 37 "heap/heap.cpp", 38 "heap/allocator/allocator.cpp", 39 "heap/allocator/treap.cpp", 40 "heap/allocator/memory_map.cpp", 41 "heap/allocator/region_manager.cpp", 42 "heap/allocator/region_space.cpp", 43 "heap/allocator/fix_heap.cpp", 44 "heap/barrier/barrier.cpp", 45 "heap/verification.cpp", 46 "heap/collector/collector.cpp", 47 "heap/collector/collector_proxy.cpp", 48 "heap/collector/collector_resources.cpp", 49 "heap/collector/finalizer_processor.cpp", 50 "heap/collector/gc_request.cpp", 51 "heap/collector/gc_stats.cpp", 52 "heap/collector/heuristic_gc_policy.cpp", 53 "heap/collector/task_queue.cpp", 54 "heap/collector/copy_data_manager.cpp", 55 "heap/collector/marking_collector.cpp", 56 "heap/space/from_space.cpp", 57 "heap/space/old_space.cpp", 58 "heap/space/to_space.cpp", 59 "heap/space/young_space.cpp", 60 "heap/heap_manager.cpp", 61 "common/page_cache.cpp", 62] 63 64source_Mutator = [ 65 "mutator/mutator.cpp", 66 "mutator/satb_buffer.cpp", 67 "mutator/mutator_manager.cpp", 68 "mutator/thread_local.cpp", 69] 70 71ohos_source_set("libarkcommon-runtime") { 72 configs = [ 73 "..:ark_jsruntime_public_config", 74 "..:ark_jsruntime_common_config", 75 ] 76 77 cflags_cc = [ "-Wno-unused-lambda-capture" ] 78 79 sources = [] 80 sources += source_Base 81 sources += source_Common 82 sources += source_Heap 83 sources += source_Mutator 84 85 include_dirs = [] 86 include_dirs += [ "./" ] 87 88 # hiviewdfx libraries 89 external_deps = hiviewdfx_ext_deps 90 if (defined(ohos_indep_compiler_enable) && ohos_indep_compiler_enable) { 91 external_deps += [ sdk_libc_secshared_dep ] 92 } 93 deps = hiviewdfx_deps 94 95 part_name = "ets_runtime" 96 subsystem_name = "arkcompiler" 97} 98 99config("common_components_public_config") { 100 configs = [ 101 "$ark_root/common_interfaces:common_interfaces_public_config", 102 "$ark_root/libpandabase:arkbase_public_config", 103 "$ark_root/libpandafile:arkfile_public_config", 104 ] 105 if (ark_standalone_build || 106 (defined(ohos_indep_compiler_enable) && !ohos_indep_compiler_enable)) { 107 configs += [ 108 "$ark_third_party_root/icu/icu4c:icu_config", 109 sdk_libc_secshared_config, 110 ] 111 } 112 113 include_dirs = [ 114 "//arkcompiler/ets_runtime", 115 ] 116 117 defines = [] 118 ldflags = [] 119 120 if (ark_hybrid) { 121 defines += [ "ARK_HYBRID" ] 122 123 if (current_cpu == "amd64" || current_cpu == "x64" || 124 current_cpu == "x86_64") { 125 ldflags += [ "-latomic" ] 126 } 127 } 128 129 if (ark_js_hybrid) { 130 defines += [ "PANDA_JS_ETS_HYBRID_MODE" ] 131 configs += [ "$ark_root/arkplatform:arkplatform_public_config" ] 132 } 133} 134 135config("common_components_common_config") { 136 configs = [ "//arkcompiler/ets_runtime/:hiviewdfx_config" ] 137 138 defines = [ "PANDA_ENABLE_LTO" ] 139 140 if (ets_runtime_enable_cmc_gc) { 141 defines += [ "USE_CMC_GC" ] 142 if (is_ohos) { 143 defines += [ "ENABLE_COLD_STARTUP_GC_POLICY" ] 144 } 145 } else { 146 print("########## ets_runtime disable cmc-gc ##############") 147 } 148 149 if (ark_standalone_build) { 150 defines += [ "STANDALONE_MODE" ] 151 } 152 153 if (enable_next_optimization) { 154 defines += [ "NEXT_OPTIMIZATION_MACRO" ] 155 } 156 157 cflags_cc = [ 158 "-Wall", 159 "-Wshadow", 160 "-Werror", 161 "-Wextra", 162 "-pedantic", 163 "-Wno-invalid-offsetof", 164 "-Wno-gnu-statement-expression", 165 "-pipe", 166 "-Wdate-time", 167 "-funwind-tables", 168 "-fno-rtti", 169 "-fasynchronous-unwind-tables", 170 "-Wformat=2", 171 "-std=c++17", 172 ] 173 174 cflags_cc += [ 175 "-Wno-unused-command-line-argument", 176 "-Wno-variadic-macros", 177 "-Wno-gnu-anonymous-struct", 178 "-Wno-zero-length-array", 179 "-Wno-nested-anon-types", 180 "-Wno-c99-extensions", 181 "-Wno-unused-parameter", 182 "-Wno-shadow", 183 "-Wno-pedantic", 184 "-Wno-gnu-zero-variadic-macro-arguments", 185 "-Wno-unused-lambda-capture", 186 "-Wno-unused-function", 187 "-Wno-unused-variable", 188 "-Wno-unused-but-set-variable", 189 ] 190 cflags_c = [] 191 192 if (is_ohos && is_clang && (target_cpu == "arm" || target_cpu == "arm64")) { 193 if (ets_runtime_feature_enable_pgo) { 194 cflags = [ 195 "-fprofile-use=" + rebase_path( 196 "${ets_runtime_feature_pgo_path}/libark_jsruntime.profdata", 197 root_build_dir), 198 "-Wno-error=backend-plugin", 199 "-Wno-profile-instr-out-of-date", 200 "-Wno-profile-instr-unprofiled", 201 "-mllvm", 202 "-enable-partial-inlining", 203 ] 204 } 205 } 206 207 if (use_musl) { 208 defines += [ "PANDA_USE_MUSL" ] 209 } 210 211 if (build_public_version) { 212 defines += [ "IS_PUBLIC_VERSION" ] 213 } 214 215 if (is_arkui_x) { 216 defines += [ "CROSS_PLATFORM" ] 217 } 218 219 if (target_os == "android") { 220 defines += [ "ANDROID_PLATFORM" ] 221 } 222 223 if (is_ohos) { 224 defines += [ "PANDA_TARGET_OHOS" ] 225 } 226 227 if (is_qemu_runtime && is_ohos) { 228 defines += [ "OHOS_FOR_QEMU" ] 229 } 230 231 if (use_libfuzzer) { 232 defines += [ "FUZZ_TEST" ] 233 } 234 235 if (is_fastverify) { 236 cflags_cc += [ 237 "-O3", 238 "-ggdb3", 239 "-gdwarf-4", 240 "-fno-omit-frame-pointer", 241 "-D_GLIBCXX_ASSERTIONS", 242 ] 243 cflags_c += [ 244 "-O3", 245 "-ggdb3", 246 "-gdwarf-4", 247 "-fno-omit-frame-pointer", 248 "-D_GLIBCXX_ASSERTIONS", 249 ] 250 } else if (is_debug) { 251 cflags_cc += [ 252 "-O0", 253 "-ggdb3", 254 "-gdwarf-4", 255 ] 256 } else { 257 defines += [ "NDEBUG" ] 258 } 259 260 if (enable_asm_assert) { 261 defines += [ "ENABLE_ASM_ASSERT" ] 262 } 263 264 if (run_with_asan) { 265 defines += [ "RUN_WITH_ASAN" ] 266 } 267 268 if (enable_cow_array) { 269 defines += [ "ENABLE_COW_ARRAY" ] 270 } 271 272 if (current_cpu == "arm") { 273 defines += [ 274 "PANDA_TARGET_ARM32_ABI_SOFT=1", 275 "PANDA_TARGET_ARM32", 276 "PANDA_TARGET_32", 277 ] 278 } else if (current_cpu == "arm64") { 279 defines += [ 280 "PANDA_TARGET_ARM64", 281 "PANDA_TARGET_64", 282 "PANDA_ENABLE_GLOBAL_REGISTER_VARIABLES", 283 "PANDA_USE_32_BIT_POINTER", 284 ] 285 } else if (current_cpu == "x86") { 286 defines += [ "PANDA_TARGET_X86" ] 287 } else if (current_cpu == "amd64" || current_cpu == "x64" || 288 current_cpu == "x86_64") { 289 defines += [ 290 "PANDA_TARGET_64", 291 "PANDA_TARGET_AMD64", 292 "PANDA_USE_32_BIT_POINTER", 293 ] 294 } 295 if (enable_ark_intl) { 296 defines += [ "ARK_SUPPORT_INTL" ] 297 } else { 298 if (target_os == "android" || target_os == "ios") { 299 defines += [ "ARK_NOT_SUPPORT_INTL_GLOBAL" ] 300 } else { 301 configs += [ "$global_root/frameworks/intl:intl_util_config" ] 302 } 303 } 304 305 if (enable_handle_leak_detect) { 306 defines += [ "ENABLE_LOCAL_HANDLE_LEAK_DETECT" ] 307 } 308 309 if (is_ohos && is_standard_system) { 310 defines += [ "ENABLE_EXCEPTION_BACKTRACE" ] 311 312 if (use_musl && (current_cpu == "arm" || current_cpu == "arm64") && 313 !is_mac && !is_mingw && target_os != "ios" && !is_asan) { 314 defines += [ "HOOK_ENABLE" ] 315 } 316 } 317 318 code_encrypto_enable = true 319 if (defined(global_parts_info) && 320 !defined(global_parts_info.security_code_crypto_metadata_process)) { 321 code_encrypto_enable = false 322 } 323 if (is_mingw && ark_standalone_build) { 324 code_encrypto_enable = false 325 } 326 if (code_encrypto_enable) { 327 defines += [ "CODE_ENCRYPTION_ENABLE" ] 328 } 329} 330 331# common_components unit testcase config 332config("common_components_test_config") { 333 visibility = [ 334 "./*", 335 ] 336 337 configs = [ 338 ":common_components_public_config", 339 ":common_components_common_config", 340 ] 341 342 if (enable_handle_leak_detect) { 343 defines = [ "ENABLE_LOCAL_HANDLE_LEAK_DETECT" ] 344 } 345 if (!is_mac) { 346 ldflags = [ "-Wl,-rpath=\$ORIGIN/" ] 347 } else { 348 ldflags = [ "-Wl" ] 349 } 350 351 if (!ark_standalone_build) { 352 ldflags += [ "-Wl,--lto-O0" ] 353 } 354} 355 356ohos_shared_library("libark_common_components_test") { 357 testonly = true 358 stack_protector_ret = false 359 360 configs = [ ":common_components_test_config" ] 361 362 sources = [ 363 "common_runtime/base_runtime.cpp", 364 "common_runtime/base_runtime_param.cpp", 365 "base/utf_helper.cpp", 366 "heap/heap_allocator.cpp", 367 "log/log.cpp", 368 "objects/base_object.cpp", 369 "objects/base_string_table.cpp", 370 "objects/base_string.cpp", 371 "objects/composite_base_class.cpp", 372 "taskpool/taskpool.cpp", 373 "taskpool/runner.cpp", 374 "taskpool/task_queue.cpp", 375 "tests/test_hooks.cpp", 376 "heap/heap_visitor.cpp", 377 "profiler/heap_profiler_listener.cpp", 378 "thread/thread_holder.cpp", 379 "thread/thread_holder_manager.cpp", 380 "platform/unix/map.cpp", 381 ] 382 383 if (is_mingw) { 384 sources += [ 385 "platform/windows/cpu.cpp", 386 "platform/windows/os.cpp", 387 ] 388 } else if (is_mac) { 389 sources += [ 390 "platform/unix/mac/cpu.cpp", 391 "platform/unix/mac/os.cpp", 392 ] 393 } else if (is_ohos || target_os == "android") { 394 sources += [ 395 "platform/unix/linux/cpu.cpp", 396 "platform/unix/linux/os.cpp", 397 ] 398 } else if (is_linux) { 399 sources += [ 400 "platform/unix/linux/cpu.cpp", 401 "platform/unix/linux/os.cpp", 402 ] 403 } 404 405 deps = [ ":libarkcommon-runtime" ] 406 407 public_configs = [ ":common_components_public_config" ] 408 public_configs += [ "//arkcompiler/ets_runtime:include_llvm" ] 409 410 external_deps = [] 411 if (!ark_standalone_build) { 412 public_external_deps = [ 413 "zlib:libz", 414 "bounds_checking_function:libsec_shared", 415 ] 416 public_external_deps += hiviewdfx_ext_deps 417 } else { 418 external_deps += [ 419 "zlib:libz", 420 "bounds_checking_function:libsec_shared", 421 ] 422 external_deps += hiviewdfx_ext_deps 423 } 424 425 ldflags = [] 426 if (enable_coverage) { 427 ldflags += [ "--coverage" ] 428 cflags_cc = [ "--coverage" ] 429 } 430 if (!ark_standalone_build) { 431 ldflags += [ "-Wl,--lto-O0" ] 432 } 433 434 install_enable = false 435 if (!is_mingw && !is_mac) { 436 output_extension = "so" 437 } 438 439 if (!is_arkui_x) { 440 external_deps += [ "runtime_core:libarkfile_runtime_static" ] 441 } else { 442 deps += [ "$ark_root/libpandafile:libarkfile_runtime_static" ] 443 } 444 445 part_name = "ets_runtime" 446 subsystem_name = "arkcompiler" 447} 448 449ohos_shared_library("libark_common_components_fuzz_test") { 450 testonly = true 451 stack_protector_ret = false 452 453 configs = [ ":common_components_test_config" ] 454 455 sources = [ 456 "log/log.cpp", 457 "base/utf_helper.cpp", 458 ] 459 460 if (is_mingw) { 461 sources += [ 462 "platform/windows/cpu.cpp", 463 "platform/windows/os.cpp", 464 ] 465 } else if (is_mac) { 466 sources += [ 467 "platform/unix/mac/cpu.cpp", 468 "platform/unix/mac/os.cpp", 469 ] 470 } else if (is_ohos || target_os == "android") { 471 sources += [ 472 "platform/unix/linux/cpu.cpp", 473 "platform/unix/linux/os.cpp", 474 ] 475 } else if (is_linux) { 476 sources += [ 477 "platform/unix/linux/cpu.cpp", 478 "platform/unix/linux/os.cpp", 479 ] 480 } 481 482 # deps = [ ":libarkcommon-runtime" ] 483 484 public_configs = [ ":common_components_public_config" ] 485 public_configs += [ "//arkcompiler/ets_runtime:include_llvm" ] 486 487 external_deps = [] 488 if (!ark_standalone_build) { 489 public_external_deps = [ 490 "zlib:libz", 491 ] 492 public_external_deps += hiviewdfx_ext_deps 493 } else { 494 external_deps += [ 495 "zlib:libz", 496 ] 497 external_deps += hiviewdfx_ext_deps 498 } 499 500 ldflags = [] 501 if (enable_coverage) { 502 ldflags += [ "--coverage" ] 503 cflags_cc = [ "--coverage" ] 504 } 505 if (!ark_standalone_build) { 506 ldflags += [ "-Wl,--lto-O0" ] 507 } 508 509 install_enable = false 510 if (!is_mingw && !is_mac) { 511 output_extension = "so" 512 } 513 514 if (!is_arkui_x) { 515 external_deps += [ "runtime_core:libarkfile_runtime_static" ] 516 } else { 517 deps = [ "$ark_root/libpandafile:libarkfile_runtime_static" ] 518 } 519 520 part_name = "ets_runtime" 521 subsystem_name = "arkcompiler" 522} 523