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