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