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("//build/config/components/ace_engine/ace_gen_obj.gni") 15import("//build/config/components/ets_frontend/es2abc_config.gni") 16import("//build/ohos.gni") 17import("//commonlibrary/ets_utils/ets_utils_config.gni") 18 19# compile .ts to .js. 20action("build_ts_js") { 21 script = "${ets_util_path}/js_api_module/build_ts_js.py" 22 23 outFile_Path = target_out_dir + "/" + current_cpu 24 args = [ 25 "--dst-file", 26 rebase_path(target_out_dir + "/js_fastbuffer.js"), 27 "--module-path", 28 rebase_path("/commonlibrary/ets_utils/js_api_module/fastbuffer"), 29 "--out-file", 30 rebase_path(outFile_Path + "/js_fastbuffer.js"), 31 "--out-filePath", 32 rebase_path(outFile_Path), 33 "--relative-path", 34 rebase_path("//", root_build_dir), 35 ] 36 outputs = [ target_out_dir + "/js_fastbuffer.js" ] 37} 38 39config("fastbuffer_config") { 40 cflags_cc = [ 41 "-std=c++17", 42 "-Wno-deprecated-declarations", 43 ] 44} 45 46base_output_path = get_label_info(":js_fastbuffer", "target_out_dir") 47gen_obj("js_fastbuffer") { 48 input = "$target_out_dir/js_fastbuffer.js" 49 if (use_mac || use_mingw_win || use_ios || use_linux) { 50 js_fastbuffer_obj_path = base_output_path + "/fastbuffer.c" 51 } else { 52 js_fastbuffer_obj_path = base_output_path + "/fastbuffer.o" 53 } 54 output = js_fastbuffer_obj_path 55 snapshot_dep = [ ":build_ts_js" ] 56} 57 58# compile .js to .abc. 59es2abc_gen_abc("gen_fastbuffer_abc") { 60 extra_visibility = [ ":*" ] 61 src_js = rebase_path(target_out_dir + "/js_fastbuffer.js") 62 dst_file = rebase_path(target_out_dir + "/fastbuffer.abc") 63 in_puts = [ target_out_dir + "/js_fastbuffer.js" ] 64 out_puts = [ target_out_dir + "/fastbuffer.abc" ] 65 extra_args = [ "--module" ] 66 extra_dependencies = [ ":build_ts_js" ] 67} 68 69abc_output_path = get_label_info(":fastbuffer_abc", "target_out_dir") 70gen_obj("fastbuffer_abc") { 71 input = "$target_out_dir/fastbuffer.abc" 72 if (use_mac || use_mingw_win || use_ios || use_linux) { 73 fastbuffer_abc_obj_path = abc_output_path + "/fastbuffer_abc.c" 74 } else { 75 fastbuffer_abc_obj_path = abc_output_path + "/fastbuffer_abc.o" 76 } 77 output = fastbuffer_abc_obj_path 78 snapshot_dep = [ ":gen_fastbuffer_abc" ] 79} 80 81fastbuffer_sources = [ 82 "native_module_fastbuffer.cpp", 83] 84 85ohos_shared_library("fastbuffer") { 86 branch_protector_ret = "pac_ret" 87 sanitize = { 88 cfi = true 89 cfi_cross_dso = true 90 debug = false 91 } 92 deps = [ ":fastbuffer_static" ] 93 external_deps = [ "hilog:libhilog" ] 94 subsystem_name = "commonlibrary" 95 part_name = "ets_utils" 96 97 relative_install_dir = "module" 98} 99 100ohos_source_set("fastbuffer_static") { 101 branch_protector_ret = "pac_ret" 102 sanitize = { 103 cfi = true 104 cfi_cross_dso = true 105 debug = false 106 } 107 include_dirs = [ 108 "include", 109 ets_util_path, 110 ] 111 112 sources = fastbuffer_sources 113 114 deps = [ 115 ":gen_obj_src_fastbuffer_abc", 116 ":gen_obj_src_js_fastbuffer", 117 ] 118 119 configs = [ ":fastbuffer_config" ] 120 121 if (is_arkui_x) { 122 include_dirs += [ 123 "$plugins_root/hilog/include", 124 "$plugins_root/interfaces", 125 "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", 126 ] 127 if (target_os == "android") { 128 defines = [ "ANDROID_PLATFORM" ] 129 } else if (target_os == "ios") { 130 defines = [ "IOS_PLATFORM" ] 131 } 132 deps += [ 133 "$plugins_root/libs/icu:icu_${target_os}", 134 "$plugins_root/libs/napi:napi_${target_os}", 135 "$plugins_root/libs/securec:sec_${target_os}", 136 ] 137 } else { 138 external_deps = [ 139 "bounds_checking_function:libsec_shared", 140 "hilog:libhilog", 141 "icu:shared_icuuc", 142 "napi:ace_napi", 143 ] 144 } 145 subsystem_name = "commonlibrary" 146 part_name = "ets_utils" 147} 148 149group("fastbuffer_packages") { 150 public_deps = [ ":fastbuffer" ] 151} 152