1# Copyright (c) 2021 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/ets_runtime/js_runtime_config.gni") 15if (defined(timeout)) { 16 _timeout_ = timeout 17} else { 18 _timeout_ = 1200 19} 20 21config("include_maple") { 22 include_dirs = [ 23 "${MAPLEALL_ROOT}/maple_be/include/cg", 24 "${MAPLEALL_ROOT}/maple_be/include/litecg", 25 "${MAPLEALL_ROOT}/maple_be/cg/aarch64", 26 "${MAPLEALL_ROOT}/maple_be/include/ad", 27 "${MAPLEALL_ROOT}/maple_be/include/ad/target", 28 "${MAPLEALL_ROOT}/maple_be/include/be/aarch64", 29 "${MAPLEALL_ROOT}/maple_be/include/be", 30 "${MAPLEALL_ROOT}/maple_driver/include", 31 "${MAPLEALL_ROOT}/maple_driver/defs", 32 "${MAPLEALL_ROOT}/maple_driver/defs/default", 33 "${MAPLEALL_ROOT}/maple_util/include", 34 "${MAPLEALL_ROOT}/mpl2mpl/include", 35 "${MAPLEALL_ROOT}/mempool/include", 36 "${MAPLEALL_ROOT}/maple_phase/include", 37 "${MAPLEALL_ROOT}/maple_ir/include", 38 "${MAPLEALL_ROOT}/maple_me/include", 39 ] 40 cflags_cc = [ "-Wno-gnu-zero-variadic-macro-arguments" ] 41} 42 43libark_jsoptimizer_sources = [ 44 "access_object_stub_builder.cpp", 45 "aot_compilation_env.cpp", 46 "aot_compiler_preprocessor.cpp", 47 "aot_compiler_stats.cpp", 48 "argument_accessor.cpp", 49 "array_bounds_check_elimination.cpp", 50 "assembler/aarch64/assembler_aarch64.cpp", 51 "assembler/aarch64/extend_assembler.cpp", 52 "assembler/aarch64/macro_assembler_aarch64.cpp", 53 "assembler/x64/assembler_x64.cpp", 54 "assembler/x64/extended_assembler_x64.cpp", 55 "assembler/x64/macro_assembler_x64.cpp", 56 "assembler_module.cpp", 57 "async_function_lowering.cpp", 58 "barrier_stub_builder.cpp", 59 "base/depend_chain_helper.cpp", 60 "baseline/baseline_assembler.cpp", 61 "baseline/baseline_call_signature.cpp", 62 "baseline/baseline_compiler.cpp", 63 "baseline/baseline_stubs.cpp", 64 "bc_call_signature.cpp", 65 "builtins/builtins_array_indexof_stub_builder.cpp", 66 "builtins/builtins_array_stub_builder.cpp", 67 "builtins/builtins_array_stub_builder_next_optimization.cpp", 68 "builtins/builtins_call_signature.cpp", 69 "builtins/builtins_collator_stub_builder.cpp", 70 "builtins/builtins_collection_iterator_stub_builder.cpp", 71 "builtins/builtins_collection_stub_builder.cpp", 72 "builtins/builtins_dataview_stub_builder.cpp", 73 "builtins/builtins_function_stub_builder.cpp", 74 "builtins/builtins_number_stub_builder.cpp", 75 "builtins/builtins_object_stub_builder.cpp", 76 "builtins/builtins_proxy_stub_builder.cpp", 77 "builtins/builtins_reflect_stub_builder.cpp", 78 "builtins/builtins_regexp_stub_builder.cpp", 79 "builtins/builtins_string_stub_builder.cpp", 80 "builtins/builtins_stubs.cpp", 81 "builtins/builtins_typedarray_stub_builder.cpp", 82 "builtins/containers_arraylist_stub_builder.cpp", 83 "builtins/containers_deque_stub_builder.cpp", 84 "builtins/containers_hashmap_stub_builder.cpp", 85 "builtins/containers_hashset_stub_builder.cpp", 86 "builtins/containers_lightweightmap_stub_builder.cpp", 87 "builtins/containers_lightweightset_stub_builder.cpp", 88 "builtins/containers_linkedlist_stub_builder.cpp", 89 "builtins/containers_list_stub_builder.cpp", 90 "builtins/containers_plainarray_stub_builder.cpp", 91 "builtins/containers_queue_stub_builder.cpp", 92 "builtins/containers_stack_stub_builder.cpp", 93 "builtins/containers_stub_builder.cpp", 94 "builtins/containers_vector_stub_builder.cpp", 95 "builtins/linked_hashtable_stub_builder.cpp", 96 "builtins_lowering.cpp", 97 "bytecode_circuit_builder.cpp", 98 "bytecode_info_collector.cpp", 99 "bytecodes.cpp", 100 "call_signature.cpp", 101 "call_stub_builder.cpp", 102 "circuit.cpp", 103 "circuit_builder.cpp", 104 "circuit_builder_helper.cpp", 105 "codegen/llvm/aarch64/aarch64_builder.cpp", 106 "codegen/llvm/llvm_codegen.cpp", 107 "codegen/llvm/llvm_ir_builder.cpp", 108 "codegen/llvm/x64/x64_builder.cpp", 109 "combined_pass_visitor.cpp", 110 "common_stubs.cpp", 111 "compilation_driver.cpp", 112 "compilation_env.cpp", 113 "compiler_log.cpp", 114 "constant_folding.cpp", 115 "dead_code_elimination.cpp", 116 "debug_info.cpp", 117 "early_elimination.cpp", 118 "escape_analysis.cpp", 119 "escape_analysis_editor.cpp", 120 "file_generators.cpp", 121 "frame_states.cpp", 122 "gate.cpp", 123 "gate_accessor.cpp", 124 "graph_editor.cpp", 125 "graph_linearizer.cpp", 126 "hash_stub_builder.cpp", 127 "hcr_circuit_builder.cpp", 128 "hcr_gate_meta_data.cpp", 129 "ic_stub_builder.cpp", 130 "induction_variable_analysis.cpp", 131 "instruction_combine.cpp", 132 "interpreter_stub.cpp", 133 "ir_builder.cpp", 134 "ir_module.cpp", 135 "jit_compilation_env.cpp", 136 "jit_compiler.cpp", 137 "later_elimination.cpp", 138 "lcr_circuit_builder.cpp", 139 "lcr_gate_meta_data.cpp", 140 "lexical_env_specialization_pass.cpp", 141 "loop_analysis.cpp", 142 "loop_peeling.cpp", 143 "mcr_circuit_builder.cpp", 144 "mcr_gate_meta_data.cpp", 145 "mcr_lowering.cpp", 146 "native_inline_lowering.cpp", 147 "new_object_stub_builder.cpp", 148 "ntype_bytecode_lowering.cpp", 149 "ntype_hcr_lowering.cpp", 150 "number_speculative_lowering.cpp", 151 "number_speculative_retype.cpp", 152 "number_speculative_runner.cpp", 153 "object_operator_stub_builder.cpp", 154 "operations_stub_builder.cpp", 155 "pass_manager.cpp", 156 "post_schedule.cpp", 157 "precompile_checker.cpp", 158 "profiler_stub_builder.cpp", 159 "range_analysis.cpp", 160 "range_guard.cpp", 161 "rt_call_signature.cpp", 162 "scheduler.cpp", 163 "share_gate_meta_data.cpp", 164 "slowpath_lowering.cpp", 165 "state_split_linearizer.cpp", 166 "string_builder_optimizer.cpp", 167 "stub.cpp", 168 "stub_builder.cpp", 169 "trampoline/aarch64/asm_interpreter_call.cpp", 170 "trampoline/aarch64/baseline_call.cpp", 171 "trampoline/aarch64/common_call.cpp", 172 "trampoline/aarch64/optimized_call.cpp", 173 "trampoline/aarch64/optimized_fast_call.cpp", 174 "trampoline/x64/asm_interpreter_call.cpp", 175 "trampoline/x64/baseline_call.cpp", 176 "trampoline/x64/common_call.cpp", 177 "trampoline/x64/optimized_call.cpp", 178 "trampoline/x64/optimized_fast_call.cpp", 179 "ts_hcr_opt_pass.cpp", 180 "ts_inline_lowering.cpp", 181 "type.cpp", 182 "type_inference/pgo_type_infer.cpp", 183 "type_info_accessors.cpp", 184 "typed_bytecode_lowering.cpp", 185 "typed_hcr_lowering.cpp", 186 "typed_native_inline_lowering.cpp", 187 "useless_gate_elimination.cpp", 188 "value_numbering.cpp", 189 "verifier.cpp", 190] 191 192config("libark_jsoptimizer_set_config") { 193 # Setting up IS_RELEASE_VERSION if compiling as release version 194 if (build_variant == "user") { 195 cflags_c = [ "-DIS_RELEASE_VERSION" ] 196 cflags_cc = [ "-DIS_RELEASE_VERSION" ] 197 } 198 libs = [] 199 if (is_mingw) { 200 libs += [ 201 "kernel32", 202 "shell32", 203 "uuid", 204 "advapi32", 205 "msvcrt", 206 "msvcrt-os", 207 "windowsapp", 208 ] 209 } 210} 211 212ohos_source_set("libark_jsoptimizer_set") { 213 stack_protector_ret = false 214 sources = libark_jsoptimizer_sources 215 if (enable_local_code_sign) { 216 sources += [ "$js_root/ecmascript/platform/unix/ohos/code_sign.cpp" ] 217 } else if (is_mingw) { 218 sources += [ "$js_root/ecmascript/platform/windows/code_sign.cpp" ] 219 } else { 220 sources += [ "$js_root/ecmascript/platform/unix/code_sign.cpp" ] 221 } 222 public_configs = [ 223 "$js_root:include_llvm", 224 "$js_root:ark_jsruntime_compiler_config", 225 "$js_root:ark_jsruntime_public_config", 226 ":libark_jsoptimizer_set_config", 227 ] 228 229 external_deps = [ "zlib:libz" ] 230 deps = [] 231 if (!is_arkui_x) { 232 external_deps += [ "runtime_core:arkfile_header_deps" ] 233 } else { 234 deps += [ "$ark_root/libpandafile:arkfile_header_deps" ] 235 } 236 deps += [ "${LLVM_LIB_ROOT}:libark_llvmcodegen_set" ] 237 238 # hiviewdfx libraries 239 external_deps += hiviewdfx_ext_deps 240 deps += hiviewdfx_deps 241 242 part_name = "ets_runtime" 243 subsystem_name = "arkcompiler" 244} 245 246config("enable_maple_config") { 247 cflags_cc = [ "-DCOMPILE_MAPLE" ] 248 cflags_c = [ "-DCOMPILE_MAPLE" ] 249} 250 251ohos_source_set("libark_jsoptimizer_set_with_maple") { 252 stack_protector_ret = false 253 if (enable_sanitize) { 254 sanitize = { 255 cfi = true 256 cfi_cross_dso = true 257 debug = false 258 } 259 branch_protector_ret = "pac_ret" 260 } 261 cflags_cc = [ "-fvisibility=hidden" ] 262 sources = libark_jsoptimizer_sources 263 if (enable_local_code_sign) { 264 sources += [ "$js_root/ecmascript/platform/unix/ohos/code_sign.cpp" ] 265 } else if (is_mingw) { 266 sources += [ "$js_root/ecmascript/platform/windows/code_sign.cpp" ] 267 } else { 268 sources += [ "$js_root/ecmascript/platform/unix/code_sign.cpp" ] 269 } 270 if (enable_jit_code_sign) { 271 sources += [ "$js_root/ecmascript/compiler/jit_signcode.cpp" ] 272 } 273 sources += [ 274 "codegen/maple/litecg_codegen.cpp", 275 "codegen/maple/litecg_ir_builder.cpp", 276 ] 277 public_configs = [ 278 "$js_root:include_llvm", 279 ":include_maple", 280 "$js_root:ark_jsruntime_compiler_config", 281 "$js_root:ark_jsruntime_public_config", 282 ":libark_jsoptimizer_set_config", 283 ":enable_maple_config", 284 ] 285 286 defines = [] 287 external_deps = [ "zlib:libz" ] 288 289 if (enable_jit_code_sign) { 290 defines += [ "JIT_ENABLE_CODE_SIGN" ] 291 external_deps += [ "code_signature:libjit_code_sign" ] 292 if (disable_fort_switch) { 293 defines += [ "JIT_FORT_DISABLE" ] 294 } 295 } 296 297 if (enable_litecg_emit) { 298 defines += [ "ARK_LITECG_DEBUG" ] 299 } 300 301 deps = [] 302 if (is_ohos) { 303 deps += [ "${LLVM_LIB_ROOT}:libark_llvmcodegen" ] 304 } else { 305 deps += [ "${LLVM_LIB_ROOT}:libark_llvmcodegen_set" ] 306 } 307 if (!is_arkui_x) { 308 external_deps += [ "runtime_core:arkfile_header_deps" ] 309 } else { 310 deps += [ "$ark_root/libpandafile:arkfile_header_deps" ] 311 } 312 313 # hiviewdfx libraries 314 external_deps += hiviewdfx_ext_deps 315 316 part_name = "ets_runtime" 317 subsystem_name = "arkcompiler" 318} 319 320ohos_source_set("libark_stub_set") { 321 stack_protector_ret = false 322 if (enable_sanitize) { 323 sanitize = { 324 ubsan = true 325 } 326 } 327 deps = [ ":build_stub_to_cpp" ] 328 329 sources = [ "$root_gen_dir/arkcompiler/ets_runtime/stub_an.cpp" ] 330 331 public_configs = [ 332 "$js_root:ark_jsruntime_common_config", 333 "$js_root:ark_jsruntime_public_config", 334 ] 335 336 part_name = "ets_runtime" 337 subsystem_name = "arkcompiler" 338} 339 340ohos_source_set("libark_mock_stub_set") { 341 stack_protector_ret = false 342 sources = [ "mock/mock_stub_an.cpp" ] 343 344 public_configs = [ 345 "$js_root:ark_jsruntime_common_config", 346 "$js_root:ark_jsruntime_public_config", 347 ] 348} 349 350ohos_shared_library("libark_jsoptimizer") { 351 stack_protector_ret = false 352 if (enable_sanitize) { 353 sanitize = { 354 cfi = true 355 cfi_cross_dso = true 356 debug = false 357 ubsan = true 358 } 359 branch_protector_ret = "pac_ret" 360 } 361 deps = [ 362 ":libark_jsoptimizer_set_with_maple", 363 "$js_root:libark_jsruntime", 364 "${MAPLEALL_ROOT}/maple_be:libcg", 365 ] 366 367 external_deps = [ "bounds_checking_function:libsec_shared" ] 368 if (!is_arkui_x) { 369 external_deps += [ "runtime_core:libarkfile_static" ] 370 } else { 371 deps += [ "$ark_root/libpandafile:libarkfile_static" ] 372 } 373 374 defines = [] 375 if (run_with_asan) { 376 defines = [ "RUN_WITH_ASAN" ] 377 } 378 if (enable_jit_code_sign) { 379 defines += [ "JIT_ENABLE_CODE_SIGN" ] 380 } 381 382 if (enable_hilog) { 383 external_deps += [ "hilog:libhilog" ] 384 } 385 386 install_enable = true 387 388 if (!is_mingw && !is_mac) { 389 output_extension = "so" 390 } 391 part_name = "ets_runtime" 392 subsystem_name = "arkcompiler" 393} 394 395ohos_executable("ark_stub_compiler") { 396 sources = [ "stub_compiler.cpp" ] 397 include_dirs = [ "$target_gen_dir" ] 398 399 configs = [ 400 "$js_root:include_llvm", 401 "$js_root:ark_jsruntime_compiler_config", 402 "$js_root:ark_jsruntime_public_config", 403 ] 404 405 deps = [ 406 ":libark_jsoptimizer_set", 407 ":libark_mock_stub_set", 408 "$js_root:libark_js_intl_set", 409 "$js_root:libark_jsruntime_set", 410 ] 411 external_deps = [ "zlib:libz" ] 412 if (!is_arkui_x) { 413 external_deps += [ "runtime_core:libarkfile_static" ] 414 } else { 415 deps += [ "$ark_root/libpandafile:libarkfile_static" ] 416 } 417 418 if (!ark_standalone_build && host_os != "mac") { 419 ldflags = [ "-Wl,--lto-O0" ] 420 } 421 422 if (run_with_asan) { 423 defines = [ "RUN_WITH_ASAN" ] 424 } 425 426 if (defined(is_arkui_x) && is_arkui_x) { 427 deps += [ 428 "$ark_third_party_root/icu/icu4c:static_icui18n", 429 "$ark_third_party_root/icu/icu4c:static_icuuc", 430 ] 431 } else { 432 external_deps += [ 433 "icu:shared_icui18n", 434 "icu:shared_icuuc", 435 ] 436 } 437 438 install_enable = false 439 part_name = "ets_runtime" 440 subsystem_name = "arkcompiler" 441} 442 443ohos_executable("ark_aot_compiler") { 444 if (enable_sanitize) { 445 sanitize = { 446 ubsan = true 447 } 448 } 449 sources = [ "aot_compiler.cpp" ] 450 configs = [ 451 "$js_root:include_llvm", 452 ":include_maple", 453 "$js_root:ark_jsruntime_compiler_config", 454 "$js_root:ark_jsruntime_public_config", 455 ] 456 457 deps = [ ":libark_mock_stub_set" ] 458 459 if (is_ohos) { 460 deps += [ 461 ":libark_jsoptimizer", 462 "$js_root:libark_jsruntime", 463 ] 464 } else { 465 deps += [ 466 ":libark_jsoptimizer_set_with_maple", 467 "$js_root:libark_js_intl_set", 468 "$js_root:libark_jsruntime_set", 469 "${MAPLEALL_ROOT}/maple_be:libcg", 470 ] 471 } 472 473 external_deps = [ "zlib:libz" ] 474 if (!is_arkui_x) { 475 external_deps += [ 476 "runtime_core:arkfile_header_deps", 477 "runtime_core:libarkbase_static", 478 "runtime_core:libarkfile_static", 479 ] 480 } else { 481 deps += [ 482 "$ark_root/libpandabase:libarkbase_static", 483 "$ark_root/libpandafile:arkfile_header_deps", 484 "$ark_root/libpandafile:libarkfile_static", 485 ] 486 } 487 488 if (defined(is_arkui_x) && is_arkui_x) { 489 deps += [ 490 "$ark_third_party_root/icu/icu4c:static_icui18n", 491 "$ark_third_party_root/icu/icu4c:static_icuuc", 492 ] 493 } else { 494 external_deps += [ 495 "icu:shared_icui18n", 496 "icu:shared_icuuc", 497 ] 498 } 499 500 # hiviewdfx libraries 501 external_deps += hiviewdfx_ext_deps 502 deps += hiviewdfx_deps 503 504 install_enable = true 505 506 part_name = "ets_runtime" 507 subsystem_name = "arkcompiler" 508} 509 510action("gen_stub_file") { 511 script = "$js_root/script/run_ark_executable.py" 512 513 deps = [ "$js_root/ecmascript/compiler:ark_stub_compiler(${host_toolchain})" ] 514 515 stub_file_gen_dir = "$root_gen_dir/arkcompiler/ets_runtime" 516 root_out_dir_with_host_toolchain = 517 get_label_info(":ark_stub_compiler(${host_toolchain})", "root_out_dir") 518 519 if (current_os == "linux" && current_cpu == "arm64") { 520 stub_option = 521 " --stub-file=" + rebase_path(stub_file_gen_dir) + "/stub.an" + 522 " --compiler-target-triple=aarch64-unknown-linux-gnu" + 523 " --compiler-log=allasm" + " --log-level=info" 524 } else if (current_toolchain == host_toolchain) { 525 stub_option = " --stub-file=" + rebase_path(stub_file_gen_dir) + "/stub.an" 526 } else if (current_cpu == "x86_64") { 527 stub_option = 528 " --stub-file=" + rebase_path(stub_file_gen_dir) + "/stub.an" + 529 " --compiler-target-triple=x86_64-unknown-linux-gnu" 530 } else { 531 stub_option = 532 " --stub-file=" + rebase_path(stub_file_gen_dir) + "/stub.an" + 533 " --compiler-target-triple=aarch64-unknown-linux-gnu" + 534 " --compiler-log=allasm" + " --log-level=info" 535 } 536 537 if (host_cpu == "arm64") { 538 llvm_lib_dir = "//prebuilts/clang/ohos/linux-aarch64/llvm/lib/" 539 } else { 540 llvm_lib_dir = "//prebuilts/clang/ohos/linux-x86_64/llvm/lib/" 541 } 542 543 args = [ 544 "--script-file", 545 rebase_path(root_out_dir_with_host_toolchain) + 546 "/arkcompiler/ets_runtime/ark_stub_compiler", 547 "--script-options", 548 stub_option, 549 "--expect-output", 550 "0", 551 "--timeout-limit", 552 "${_timeout_}", 553 "--env-path", 554 rebase_path(root_out_dir_with_host_toolchain) + 555 "/arkcompiler/ets_runtime:" + 556 rebase_path(root_out_dir_with_host_toolchain) + 557 "/${icu_subsystem_name}/${icu_part_name}:" + 558 rebase_path(root_out_dir_with_host_toolchain) + "/thirdparty/zlib:" + 559 rebase_path(root_out_dir_with_host_toolchain) + 560 "/resourceschedule/frame_aware_sched:" + 561 rebase_path(root_out_dir_with_host_toolchain) + "/hiviewdfx/hilog:" + 562 rebase_path(root_out_dir_with_host_toolchain) + 563 "/thirdparty/bounds_checking_function:" + rebase_path(llvm_lib_dir), 564 ] 565 outputs = [ "$stub_file_gen_dir/stub.an" ] 566 if (is_ohos) { 567 outputs += [ "$stub_file_gen_dir/stub_code_comment.zip" ] 568 } 569} 570 571ohos_prebuilt_shared_library("stub.an") { 572 deps = [ ":gen_stub_file" ] 573 source = "$root_gen_dir/arkcompiler/ets_runtime/stub.an" 574 575 relative_install_dir = arkcompiler_relative_lib_path 576 part_name = "ets_runtime" 577 subsystem_name = "arkcompiler" 578} 579 580action("build_stub_to_cpp") { 581 sources = [ "$root_gen_dir/arkcompiler/ets_runtime/stub.an" ] 582 583 script = "$js_root/script/build_resource_to_cpp.py" 584 585 deps = [ ":gen_stub_file" ] 586 587 args = [ 588 "--input", 589 rebase_path("$root_gen_dir/arkcompiler/ets_runtime/stub.an"), 590 "--output", 591 rebase_path("$root_gen_dir/arkcompiler/ets_runtime/stub_an.cpp"), 592 ] 593 594 outputs = [ "$root_gen_dir/arkcompiler/ets_runtime/stub_an.cpp" ] 595} 596