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