• 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/ace/napi/napi.gni")
15
16config("ace_napi_config") {
17  include_dirs = [
18    "//foundation/ace/napi",
19    "//foundation/ace/napi/interfaces/innerkits",
20    "//foundation/ace/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/ace/napi",
33      "//foundation/ace/napi/native_engine",
34      "//foundation/ace/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/ace/napi",
47      "//foundation/ace/napi/interfaces/innerkits",
48      "//foundation/ace/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 = [ "-fPIC" ]
67  }
68
69  shared_library("ace_napi_jerryscript") {
70    configs -= [ "//build/lite/config:language_cpp" ]
71
72    public_configs = [ ":ace_napi_jerryscript_config" ]
73
74    include_dirs = [
75      "//foundation/ace/napi",
76      "//foundation/ace/napi/native_engine",
77      "//foundation/ace/napi/native_engine/impl/jerryscript",
78      "//third_party/jerryscript/jerry-ext/include",
79      "//third_party/jerryscript/jerry-core/include",
80      "//third_party/jerryscript/jerry-port/default/include",
81      "//third_party/libuv/include",
82      "//third_party/bounds_checking_function/include",
83      "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits",
84    ]
85
86    cflags = [ "-fPIC" ]
87    cflags_cc = cflags
88    cflags_cc += [ "-std=c++14" ]
89
90    ldflags = [
91      "-lstdc++",
92      "-lpthread",
93    ]
94
95    sources = [
96      "native_engine/impl/jerryscript/jerryscript_ext.cpp",
97      "native_engine/impl/jerryscript/jerryscript_native_deferred.cpp",
98      "native_engine/impl/jerryscript/jerryscript_native_engine.cpp",
99      "native_engine/impl/jerryscript/jerryscript_native_reference.cpp",
100      "native_engine/impl/jerryscript/native_value/jerryscript_native_array.cpp",
101      "native_engine/impl/jerryscript/native_value/jerryscript_native_array_buffer.cpp",
102      "native_engine/impl/jerryscript/native_value/jerryscript_native_big_int.cpp",
103      "native_engine/impl/jerryscript/native_value/jerryscript_native_boolean.cpp",
104      "native_engine/impl/jerryscript/native_value/jerryscript_native_buffer.cpp",
105      "native_engine/impl/jerryscript/native_value/jerryscript_native_data_view.cpp",
106      "native_engine/impl/jerryscript/native_value/jerryscript_native_date.cpp",
107      "native_engine/impl/jerryscript/native_value/jerryscript_native_external.cpp",
108      "native_engine/impl/jerryscript/native_value/jerryscript_native_function.cpp",
109      "native_engine/impl/jerryscript/native_value/jerryscript_native_number.cpp",
110      "native_engine/impl/jerryscript/native_value/jerryscript_native_object.cpp",
111      "native_engine/impl/jerryscript/native_value/jerryscript_native_string.cpp",
112      "native_engine/impl/jerryscript/native_value/jerryscript_native_typed_array.cpp",
113      "native_engine/impl/jerryscript/native_value/jerryscript_native_value.cpp",
114    ]
115
116    deps = [
117      ":ace_napi",
118      "//base//hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
119      "//third_party/bounds_checking_function:libsec_shared",
120      "//third_party/jerryscript/jerry-core:jerry-core_shared",
121      "//third_party/jerryscript/jerry-ext:jerry-ext_shared",
122      "//third_party/jerryscript/jerry-port/default:jerry-port-default_shared",
123    ]
124  }
125} else {
126  import("//build/ohos.gni")
127  import("//foundation/ace/ace_engine/ace_config.gni")
128
129  ohos_shared_library("ace_napi") {
130    defines = []
131    public_configs = [ ":ace_napi_config" ]
132    public_deps = [ "//third_party/libuv:uv" ]
133    deps = []
134
135    include_dirs = [
136      "//foundation/ace/napi",
137      "//foundation/ace/napi/interfaces/innerkits",
138      "//foundation/ace/napi/interfaces/kits",
139      "//third_party/libuv/include",
140      "//third_party/node/src",
141      "//utils/native/base/include",
142    ]
143
144    sources = napi_sources
145
146    if (current_cpu == "arm64") {
147      defines += [ "_ARM64_" ]
148    }
149
150    if (use_mingw_win) {
151      defines += [ "WINDOWS_PLATFORM" ]
152    } else if (use_mac) {
153      defines += [ "MAC_PLATFORM" ]
154    } else if (is_cross_platform_build && defined(is_android) && is_android) {
155      defines += [ "ANDROID_PLATFORM" ]
156    } else {
157      if (is_standard_system) {
158        external_deps = [
159          "hitrace_native:libhitrace",
160          "hiviewdfx_hilog_native:libhilog",
161        ]
162        defines += [ "ENABLE_HITRACE" ]
163        if (product_name != "ohos-sdk") {
164          deps += [ "$ace_root/frameworks/core:ace_container_scope" ]
165          defines += [ "ENABLE_CONTAINER_SCOPE" ]
166        }
167      } else {
168        external_deps = [ "hilog:libhilog" ]
169      }
170    }
171
172    deps += [
173      "//third_party/libuv:uv",
174      "//utils/native/base:utilsecurec",
175    ]
176
177    # Use static libuv for cross build
178    if (is_cross_platform_build) {
179      public_deps -= [ "//third_party/libuv:uv" ]
180      deps -= [ "//third_party/libuv:uv" ]
181      deps += [ "//third_party/libuv:uv_static" ]
182    }
183
184    cflags_cc = [ "-Wno-missing-braces" ]
185
186    subsystem_name = "ace"
187    part_name = "napi"
188  }
189
190  template("ace_napi_lib") {
191    forward_variables_from(invoker, "*")
192
193    ohos_shared_library(target_name) {
194      public_configs =
195          [ "native_engine/impl/${engine_path}:ace_napi_${engine_path}_config" ]
196      deps =
197          [ "native_engine/impl/${engine_path}:ace_napi_impl_${engine_path}" ]
198      subsystem_name = "ace"
199      part_name = "napi"
200    }
201  }
202  napi_libs = []
203
204  foreach(item, ace_platforms) {
205    if (item.name == "ohos" || item.name == "android") {
206      engine_config = item.config
207      support_engines = engine_config.js_engines
208      foreach(engine, support_engines) {
209        if (engine.engine_name != "ark") {
210          ace_napi_lib("ace_napi_${engine.engine_path}") {
211            engine_path = engine.engine_path
212          }
213          napi_libs += [ ":ace_napi_${engine.engine_path}" ]
214        } else if (engine.engine_name == "ark") {
215          ace_napi_lib("ace_napi_${engine.engine_name}") {
216            engine_path = engine.engine_name
217          }
218          napi_libs += [ ":ace_napi_${engine.engine_name}" ]
219        }
220      }
221    }
222  }
223
224  group("napi_packages") {
225    deps = [ ":ace_napi" ]
226    deps += napi_libs
227  }
228
229  ohos_ndk_library("libnapi_ndk") {
230    ndk_description_file = "./libnapi.ndk.json"
231    min_compact_version = "1"
232    output_name = "ace_napi"
233  }
234
235  ohos_ndk_headers("napi_header") {
236    dest_dir = "$ndk_headers_out_dir/napi"
237    sources = [ "//foundation/ace/napi/interfaces/kits/napi/native_api.h" ]
238  }
239
240  group("napi_packages_ndk") {
241    deps = [ ":libnapi_ndk" ]
242  }
243
244  if (!build_ohos_ndk && !is_cross_platform_build) {
245    group("napi_packages_test") {
246      testonly = true
247
248      deps = [
249        "sample/native_module_calc:calc",
250        "sample/native_module_calc:number",
251        "sample/native_module_demo:demo",
252        "sample/native_module_netserver:netserver",
253        "sample/native_module_storage:storage",
254        "test/unittest:unittest",
255      ]
256
257      if (is_standard_system) {
258        deps += [ "sample/native_module_ability:ability" ]
259      }
260    }
261  }
262}
263