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("//build/ohos.gni") 15import("//foundation/arkui/ace_engine/ace_config.gni") 16import("napi.gni") 17 18config("ace_napi_config") { 19 include_dirs = [ 20 ".", 21 "interfaces/inner_api", 22 "interfaces/kits", 23 "native_engine", 24 "native_engine/impl/ark", 25 ] 26 defines = [] 27 cflags_cc = [] 28 if (is_mingw || is_mac || is_linux) { 29 defines += [ "PREVIEW" ] 30 } 31 32 if (is_arkui_x) { 33 include_dirs += [ 34 "//third_party/node/src", 35 "//third_party/libuv/include", 36 ] 37 } 38 39 if (current_cpu == "amd64" || current_cpu == "x64" || 40 current_cpu == "x86_64") { 41 defines += [ 42 "NAPI_TARGET_AMD64", 43 "NAPI_TARGET_64", 44 ] 45 } else if (current_cpu == "x86") { 46 defines += [ 47 "NAPI_TARGET_X86", 48 "NAPI_TARGET_32", 49 ] 50 } else if (current_cpu == "arm64") { 51 defines += [ 52 "NAPI_TARGET_ARM64", 53 "NAPI_TARGET_64", 54 ] 55 } else if (current_cpu == "arm") { 56 defines += [ 57 "NAPI_TARGET_ARM32", 58 "NAPI_TARGET_32", 59 ] 60 } 61 62 if (current_os == "ohos" && current_cpu == "x86_64") { 63 defines += [ "SIMULATOR" ] 64 } 65 if (is_ohos) { 66 defines += [ "OHOS_PLATFORM" ] 67 if (use_musl && !is_asan) { 68 defines += [ "HOOK_ENABLE" ] 69 } 70 if (!is_arkui_x) { 71 defines += [ "OHOS_STANDARD_PLATFORM" ] 72 } 73 } else if (is_mingw) { 74 defines += [ "WINDOWS_PLATFORM" ] 75 cflags_cc += [ "-std=c++17" ] 76 } else if (is_mac) { 77 defines += [ "MAC_PLATFORM" ] 78 } else if (is_linux) { 79 defines += [ "LINUX_PLATFORM" ] 80 cflags_cc += [ "-std=c++17" ] 81 } else if (is_arkui_x && target_os == "ios") { 82 defines += [ "IOS_PLATFORM" ] 83 } else if (is_arkui_x && target_os == "android") { 84 defines += [ "ANDROID_PLATFORM" ] 85 } 86} 87 88config("module_manager_config") { 89 include_dirs = [ "module_manager" ] 90} 91 92ohos_source_set("ace_napi_static") { 93 defines = [] 94 public_configs = [ ":ace_napi_config" ] 95 deps = [] 96 external_deps = [] 97 configs = [] 98 99 sources = napi_sources 100 101 if (current_cpu == "arm64") { 102 defines += [ "_ARM64_" ] 103 } 104 if (is_ohos && !is_arkui_x) { 105 external_deps += [ "faultloggerd:libunwinder" ] 106 } 107 if (is_arkui_x) { 108 if (napi_enable_container_scope) { 109 deps += [ ":ace_container_scope_static" ] 110 defines += [ "ENABLE_CONTAINER_SCOPE" ] 111 } 112 if (target_os == "android") { 113 libs = [ "log" ] 114 } 115 } else if (!is_mingw && !is_mac && !is_linux && is_ohos_standard_system) { 116 external_deps += [ 117 "eventhandler:libeventhandler", 118 "ffrt:libffrt", 119 "hilog:libhilog", 120 "hitrace:hitrace_meter", 121 "hitrace:libhitracechain", 122 "hiview:libucollection_client", 123 "init:libbegetutil", 124 ] 125 defines += [ 126 "ENABLE_HITRACE", 127 "ENABLE_EVENT_HANDLER", 128 "ENABLE_UCOLLECTION", 129 "ENABLE_FFRT", 130 ] 131 if (product_name != "ohos-sdk" && napi_enable_container_scope) { 132 deps += [ ":ace_container_scope" ] 133 defines += [ "ENABLE_CONTAINER_SCOPE" ] 134 } 135 } 136 137 # Use static libuv and icu for cross build 138 if (is_arkui_x) { 139 deps += [ 140 "${ets_runtime_path}:libark_jsruntime_static", 141 "//third_party/bounds_checking_function:libsec_static", 142 "//third_party/icu/icu4c:static_icui18n", 143 "//third_party/icu/icu4c:static_icuuc", 144 "//third_party/libuv:uv_static", 145 ] 146 configs += [ "${ets_runtime_path}:ark_jsruntime_public_config" ] 147 } else { 148 external_deps += [ 149 "ets_runtime:libark_jsruntime", 150 "icu:shared_icui18n", 151 "icu:shared_icuuc", 152 "libuv:uv", 153 "node:node_header_notice", 154 ] 155 } 156 157 cflags_cc = [ "-Wno-missing-braces" ] 158 159 if (is_ohos && is_clang && enhanced_opt) { 160 if (ace_engine_feature_enable_pgo) { 161 cflags_cc += [ 162 "-fprofile-use=" + 163 rebase_path("${ace_engine_feature_pgo_path}/libace_napi.profdata", 164 root_build_dir), 165 "-Wno-error=backend-plugin", 166 "-Wno-profile-instr-out-of-date", 167 "-Wno-profile-instr-unprofiled", 168 ] 169 } 170 } 171 172 subsystem_name = "arkui" 173 part_name = "napi" 174} 175 176if (is_arkui_x) { 177 ohos_static_library("ace_napi") { 178 deps = [ ":ace_napi_static" ] 179 public_configs = [ ":ace_napi_config" ] 180 subsystem_name = "arkui" 181 part_name = "napi" 182 } 183} else { 184 ohos_shared_library("ace_napi") { 185 deps = [ ":ace_napi_static" ] 186 external_deps = [ 187 "bounds_checking_function:libsec_shared", 188 "hilog:libhilog", 189 ] 190 public_configs = [ 191 ":ace_napi_config", 192 ":module_manager_config", 193 ] 194 public_external_deps = [ 195 "libuv:uv", 196 "node:node_header_notice", 197 ] 198 199 subsystem_name = "arkui" 200 innerapi_tags = [ "platformsdk" ] 201 part_name = "napi" 202 203 if (is_ohos && is_clang && enhanced_opt) { 204 if (ace_engine_feature_enable_pgo) { 205 ldflags = [ "-Wl,-mllvm,-align-all-functions=4" ] 206 } 207 } 208 } 209} 210 211config("container_scope_config") { 212 visibility = [ ":*" ] 213 include_dirs = [ "$ace_root/frameworks" ] 214} 215 216ohos_shared_library("ace_container_scope") { 217 public_configs = [ ":container_scope_config" ] 218 219 configs = [ "$ace_root:ace_config" ] 220 221 sources = [ "$ace_root/frameworks/core/common/container_scope.cpp" ] 222 223 subsystem_name = "arkui" 224 innerapi_tags = [ "platformsdk_indirect" ] 225 part_name = "napi" 226} 227 228#cj_ffi 229config("ffi_bind_native_config") { 230 include_dirs = [ "interfaces/inner_api/cjffi/native" ] 231 cflags_cc = [ "-std=c++17" ] 232} 233 234ohos_shared_library("cj_bind_native") { 235 public_configs = [ ":ffi_bind_native_config" ] 236 237 branch_protector_ret = "pac_ret" 238 239 cflags_cc = [ 240 "-fdata-sections", 241 "-ffunction-sections", 242 ] 243 244 sources = [ 245 "interfaces/inner_api/cjffi/native/cj_fn_invoker.cpp", 246 "interfaces/inner_api/cjffi/native/ffi_remote_data.cpp", 247 ] 248 249 include_dirs = [ "interfaces/inner_api/cjffi" ] 250 251 external_deps = [ "hilog:libhilog" ] 252 public_external_deps = [ "c_utils:utils" ] 253 254 innerapi_tags = [ "platformsdk" ] 255 subsystem_name = "arkui" 256 part_name = "napi" 257} 258 259ohos_source_set("cj_bind_ffi_source") { 260 branch_protector_ret = "pac_ret" 261 262 sources = [ 263 "interfaces/inner_api/cjffi/cj_ffi/cj_common_ffi.cpp", 264 "interfaces/inner_api/cjffi/cj_ffi/cj_data_ffi.cpp", 265 ] 266 267 public_deps = [ ":cj_bind_native" ] 268 269 include_dirs = [ 270 "interfaces/inner_api/cjffi/cj_ffi", 271 "interfaces/inner_api/cjffi/native", 272 "interfaces/inner_api/cjffi", 273 ] 274 275 subsystem_name = "arkui" 276 part_name = "napi" 277} 278 279config("ffi_bind_ffi_public_config") { 280 include_dirs = [ 281 "interfaces/inner_api/cjffi/cj_ffi", 282 "interfaces/inner_api/cjffi/native", 283 "interfaces/inner_api/cjffi", 284 ] 285 cflags_cc = [ "-std=c++17" ] 286} 287 288group("cj_ffi_libraries") { 289 deps = [ ":cj_bind_ffi" ] 290} 291 292ohos_shared_library("cj_bind_ffi") { 293 public_configs = [ ":ffi_bind_ffi_public_config" ] 294 branch_protector_ret = "pac_ret" 295 296 cflags_cc = [ 297 "-fvisibility=hidden", 298 "-fdata-sections", 299 "-ffunction-sections", 300 ] 301 deps = [ 302 ":cj_bind_ffi_source", 303 ":cj_bind_native", 304 ] 305 306 external_deps = [] 307 308 if (is_standard_system) { 309 external_deps += [ "c_utils:utils" ] 310 } 311 innerapi_tags = [ "platformsdk" ] 312 subsystem_name = "arkui" 313 part_name = "napi" 314} 315 316ohos_source_set("ace_container_scope_static") { 317 public_configs = [ ":container_scope_config" ] 318 319 configs = [ "$ace_root:ace_config" ] 320 321 sources = [ "$ace_root/frameworks/core/common/container_scope.cpp" ] 322 subsystem_name = "arkui" 323 part_name = "napi" 324} 325 326group("napi_packages") { 327 deps = [ 328 ":ace_napi", 329 "interfaces/inner_api/cjffi/ark_interop:ark_interop", 330 ] 331 if (target_cpu == "arm64") { 332 deps += [ "jsvm:libjsvm" ] 333 } 334} 335 336if (!build_ohos_ndk && !is_arkui_x) { 337 group("napi_packages_test") { 338 testonly = true 339 340 deps = [ 341 "sample/native_module_calc:calc", 342 "sample/native_module_calc:number", 343 "sample/native_module_callback:callback", 344 "sample/native_module_demo:demo", 345 "sample/native_module_netserver:netserver", 346 "sample/native_module_storage:storage", 347 "test/fuzztest:fuzztest", 348 "test/unittest:unittest", 349 ] 350 } 351} 352