• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("//foundation/arkui/napi/napi.gni")
15
16config("ace_napi_config") {
17  include_dirs = [
18    "//foundation/arkui/napi",
19    "//foundation/arkui/napi/interfaces/inner_api",
20    "//foundation/arkui/napi/interfaces/kits",
21    "//third_party/libuv/include",
22    "//third_party/node/src",
23  ]
24}
25
26if (defined(ohos_lite)) {
27  import("//build/lite/config/component/lite_component.gni")
28  import("//build/lite/config/subsystem/aafwk/config.gni")
29
30  config("ace_napi_jerryscript_config") {
31    include_dirs = [
32      "//foundation/arkui/napi",
33      "//foundation/arkui/napi/native_engine",
34      "//foundation/arkui/napi/native_engine/impl/jerryscript",
35      "//third_party/jerryscript/jerry-ext/include",
36      "//third_party/jerryscript/jerry-core/include",
37      "//third_party/jerryscript/jerry-port/default/include",
38      "//third_party/libuv/include",
39    ]
40  }
41
42  shared_library("ace_napi") {
43    public_configs = [ ":ace_napi_config" ]
44
45    include_dirs = [
46      "//foundation/arkui/napi",
47      "//foundation/arkui/napi/interfaces/inner_api",
48      "//foundation/arkui/napi/interfaces/kits",
49      "//third_party/libuv/include",
50      "//third_party/node/src",
51      "//third_party/bounds_checking_function/include",
52    ]
53
54    sources = napi_sources
55
56    if (current_cpu == "arm64") {
57      defines = [ "_ARM64_" ]
58    }
59
60    deps = [
61      "//base//hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
62      "//third_party/bounds_checking_function:libsec_shared",
63      "//third_party/libuv:uv",
64    ]
65
66    cflags = [
67      "-fPIC",
68      "-DNAPI_TEST",
69    ]
70  }
71
72  shared_library("ace_napi_jerryscript") {
73    configs -= [ "//build/lite/config:language_cpp" ]
74
75    public_configs = [ ":ace_napi_jerryscript_config" ]
76
77    include_dirs = [
78      "//foundation/arkui/napi",
79      "//foundation/arkui/napi/native_engine",
80      "//foundation/arkui/napi/native_engine/impl/jerryscript",
81      "//third_party/jerryscript/jerry-ext/include",
82      "//third_party/jerryscript/jerry-core/include",
83      "//third_party/jerryscript/jerry-port/default/include",
84      "//third_party/libuv/include",
85      "//third_party/bounds_checking_function/include",
86      "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits",
87    ]
88
89    cflags = [ "-fPIC" ]
90    cflags_cc = cflags
91    cflags_cc += [ "-std=c++14" ]
92
93    ldflags = [
94      "-lstdc++",
95      "-lpthread",
96    ]
97
98    sources = [
99      "native_engine/impl/jerryscript/jerryscript_ext.cpp",
100      "native_engine/impl/jerryscript/jerryscript_native_deferred.cpp",
101      "native_engine/impl/jerryscript/jerryscript_native_engine.cpp",
102      "native_engine/impl/jerryscript/jerryscript_native_reference.cpp",
103      "native_engine/impl/jerryscript/native_value/jerryscript_native_array.cpp",
104      "native_engine/impl/jerryscript/native_value/jerryscript_native_array_buffer.cpp",
105      "native_engine/impl/jerryscript/native_value/jerryscript_native_big_int.cpp",
106      "native_engine/impl/jerryscript/native_value/jerryscript_native_boolean.cpp",
107      "native_engine/impl/jerryscript/native_value/jerryscript_native_buffer.cpp",
108      "native_engine/impl/jerryscript/native_value/jerryscript_native_data_view.cpp",
109      "native_engine/impl/jerryscript/native_value/jerryscript_native_date.cpp",
110      "native_engine/impl/jerryscript/native_value/jerryscript_native_external.cpp",
111      "native_engine/impl/jerryscript/native_value/jerryscript_native_function.cpp",
112      "native_engine/impl/jerryscript/native_value/jerryscript_native_number.cpp",
113      "native_engine/impl/jerryscript/native_value/jerryscript_native_object.cpp",
114      "native_engine/impl/jerryscript/native_value/jerryscript_native_string.cpp",
115      "native_engine/impl/jerryscript/native_value/jerryscript_native_typed_array.cpp",
116      "native_engine/impl/jerryscript/native_value/jerryscript_native_value.cpp",
117    ]
118
119    deps = [
120      ":ace_napi",
121      "//base//hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
122      "//third_party/bounds_checking_function:libsec_shared",
123      "//third_party/jerryscript/jerry-core:jerry-core_shared",
124      "//third_party/jerryscript/jerry-ext:jerry-ext_shared",
125      "//third_party/jerryscript/jerry-port/default:jerry-port-default_shared",
126    ]
127  }
128} else {
129  import("//build/ohos.gni")
130  import("//foundation/arkui/ace_engine/ace_config.gni")
131
132  ohos_source_set("ace_napi_static") {
133    defines = []
134    public_configs = [ ":ace_napi_config" ]
135    deps = []
136
137    include_dirs = [
138      "//foundation/arkui/napi",
139      "//foundation/arkui/napi/interfaces/inner_api",
140      "//foundation/arkui/napi/interfaces/kits",
141      "//third_party/libuv/include",
142      "//third_party/node/src",
143      "//commonlibrary/c_utils/base/include",
144    ]
145
146    sources = napi_sources
147
148    if (current_cpu == "arm64") {
149      defines += [ "_ARM64_" ]
150    }
151    if (current_os == "ohos" && current_cpu == "x86_64") {
152      defines += [ "SIMULATOR" ]
153    }
154    if (use_mingw_win || use_mac || use_linux) {
155      defines += [ "PREVIEW" ]
156    }
157    if (use_mingw_win) {
158      defines += [ "WINDOWS_PLATFORM" ]
159    } else if (use_mac) {
160      defines += [ "MAC_PLATFORM" ]
161    } else if (use_linux) {
162      defines += [ "LINUX_PLATFORM" ]
163    } else if (is_cross_platform_build && target_os == "ios") {
164      defines += [ "IOS_PLATFORM" ]
165    } else if (is_cross_platform_build && target_os == "android") {
166      defines += [ "ANDROID_PLATFORM" ]
167      aosp_deps = [ "shared_library:liblog" ]
168    } else {
169      if (is_standard_system) {
170        external_deps = [
171          "hitrace_native:hitrace_meter",
172          "hitrace_native:libhitracechain",
173          "hiviewdfx_hilog_native:libhilog",
174          "init:libbegetutil",
175        ]
176        defines += [ "ENABLE_HITRACE" ]
177        if (product_name != "ohos-sdk") {
178          if (napi_enable_container_scope) {
179            if (target_os == "ios") {
180              deps += [ ":ace_container_scope_static" ]
181            } else {
182              deps += [ ":ace_container_scope" ]
183            }
184            defines += [ "ENABLE_CONTAINER_SCOPE" ]
185          }
186        }
187      } else {
188        external_deps = [ "hilog:libhilog" ]
189      }
190    }
191
192    deps += [
193      "//third_party/bounds_checking_function:libsec_static",
194      "//third_party/libuv:uv",
195    ]
196
197    # Use static libuv for cross build
198    if (is_cross_platform_build) {
199      deps -= [ "//third_party/libuv:uv" ]
200      deps += [ "//third_party/libuv:uv_static" ]
201    }
202
203    cflags_cc = [ "-Wno-missing-braces" ]
204
205    subsystem_name = "arkui"
206    part_name = "napi"
207  }
208
209  if (is_cross_platform_build && target_os == "ios") {
210    ohos_source_set("ace_napi") {
211      deps = [ ":ace_napi_static" ]
212      public_configs = [ ":ace_napi_config" ]
213      subsystem_name = "arkui"
214      part_name = "napi"
215    }
216  } else {
217    ohos_shared_library("ace_napi") {
218      deps = [ ":ace_napi_static" ]
219      public_configs = [ ":ace_napi_config" ]
220      if (!is_cross_platform_build) {
221        public_deps = [ "//third_party/libuv:uv" ]
222      }
223      subsystem_name = "arkui"
224      part_name = "napi"
225    }
226  }
227
228  config("container_scope_config") {
229    visibility = [ ":*" ]
230    include_dirs = [ "$ace_root/frameworks" ]
231  }
232
233  ohos_shared_library("ace_container_scope") {
234    public_configs = [ ":container_scope_config" ]
235
236    configs = [ "$ace_root:ace_config" ]
237
238    sources = [ "$ace_root/frameworks/core/common/container_scope.cpp" ]
239
240    subsystem_name = "arkui"
241    part_name = "napi"
242  }
243
244  ohos_source_set("ace_container_scope_static") {
245    public_configs = [ ":container_scope_config" ]
246
247    configs = [ "$ace_root:ace_config" ]
248
249    sources = [ "$ace_root/frameworks/core/common/container_scope.cpp" ]
250  }
251
252  template("ace_napi_lib") {
253    forward_variables_from(invoker, "*")
254    if (defined(use_js_debug) && use_js_debug) {
255      deps_ = [
256        "native_engine/impl/${engine_path}:ace_napi_impl_${engine_path}_debug",
257      ]
258    } else {
259      deps_ =
260          [ "native_engine/impl/${engine_path}:ace_napi_impl_${engine_path}" ]
261    }
262
263    if (target_os == "ios") {
264      ohos_source_set(target_name) {
265        public_configs = [
266          "native_engine/impl/${engine_path}:ace_napi_${engine_path}_config",
267        ]
268        deps = deps_
269        if (defined(use_icu) && use_icu) {
270          deps += [
271            "//third_party/icu/icu4c:static_icui18n",
272            "//third_party/icu/icu4c:static_icuuc",
273          ]
274        }
275        subsystem_name = "arkui"
276        part_name = "napi"
277      }
278    } else {
279      ohos_shared_library(target_name) {
280        public_configs = [
281          "native_engine/impl/${engine_path}:ace_napi_${engine_path}_config",
282        ]
283        deps = deps_
284        if (defined(use_icu) && use_icu) {
285          deps += [
286            "//third_party/icu/icu4c:shared_icui18n",
287            "//third_party/icu/icu4c:shared_icuuc",
288          ]
289        }
290        subsystem_name = "arkui"
291        part_name = "napi"
292      }
293    }
294  }
295  napi_libs = []
296
297  foreach(item, ace_platforms) {
298    if (item.name == "ohos" || is_cross_platform_build) {
299      engine_config = {
300      }
301      support_engines = {
302      }
303      engine_config = item.config
304      support_engines = engine_config.js_engines
305      foreach(engine, support_engines) {
306        if (engine.engine_name != "ark") {
307          ace_napi_lib("ace_napi_${engine.engine_path}") {
308            engine_path = engine.engine_path
309          }
310          napi_libs += [ ":ace_napi_${engine.engine_path}" ]
311          if (defined(engine.have_debug) && engine.have_debug) {
312            ace_napi_lib("ace_napi_${engine.engine_path}_debug") {
313              engine_path = engine.engine_path
314              use_js_debug = true
315            }
316            napi_libs += [ ":ace_napi_${engine.engine_path}_debug" ]
317          }
318        } else if (engine.engine_name == "ark") {
319          ace_napi_lib("ace_napi_${engine.engine_name}") {
320            engine_path = engine.engine_name
321            use_icu = true
322          }
323          napi_libs += [ ":ace_napi_${engine.engine_name}" ]
324        }
325      }
326    }
327  }
328
329  group("napi_packages") {
330    deps = [ ":ace_napi" ]
331    deps += napi_libs
332  }
333
334  ohos_ndk_library("libnapi_ndk") {
335    ndk_description_file = "./libnapi.ndk.json"
336    min_compact_version = "1"
337    output_name = "ace_napi"
338  }
339
340  ohos_ndk_headers("napi_header") {
341    dest_dir = "$ndk_headers_out_dir/napi"
342    sources = [ "//foundation/arkui/napi/interfaces/kits/napi/native_api.h" ]
343  }
344
345  group("napi_packages_ndk") {
346    deps = [ ":libnapi_ndk" ]
347  }
348
349  if (!build_ohos_ndk && !is_cross_platform_build) {
350    group("napi_packages_test") {
351      testonly = true
352
353      deps = [
354        "sample/native_module_calc:calc",
355        "sample/native_module_calc:number",
356        "sample/native_module_callback:callback",
357        "sample/native_module_demo:demo",
358        "sample/native_module_netserver:netserver",
359        "sample/native_module_storage:storage",
360        "test/unittest:unittest",
361      ]
362    }
363  }
364}
365