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