1# Copyright (c) 2022 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("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
15import("//build/ohos.gni")
16import("//commonlibrary/ets_utils/ets_utils_config.gni")
17import("//foundation/arkui/ace_engine/ace_config.gni")
18import("//foundation/arkui/ace_engine/build/ace_gen_obj.gni")
19
20# compile .ts to .js.
21action("build_ts_js") {
22  script = "${ets_util_path}/js_api_module/build_ts_js.py"
23
24  outFile_Path = target_out_dir + "/" + current_cpu
25  args = [
26    "--dst-file",
27    rebase_path(target_out_dir + "/js_buffer.js"),
28    "--module-path",
29    rebase_path("/commonlibrary/ets_utils/js_api_module/buffer"),
30    "--out-file",
31    rebase_path(outFile_Path + "/js_buffer.js"),
32    "--out-filePath",
33    rebase_path(outFile_Path),
34    "--relative-path",
35    rebase_path("//", root_build_dir),
36  ]
37  outputs = [ target_out_dir + "/js_buffer.js" ]
38}
39
40config("buffer_config") {
41  cflags_cc = [
42    "-std=c++17",
43    "-Wno-deprecated-declarations",
44  ]
45}
46
47base_output_path = get_label_info(":js_buffer", "target_out_dir")
48gen_obj("js_buffer") {
49  input = "$target_out_dir/js_buffer.js"
50  if (use_mac || use_mingw_win || use_ios || use_linux) {
51    js_buffer_obj_path = base_output_path + "/buffer.c"
52  } else {
53    js_buffer_obj_path = base_output_path + "/buffer.o"
54  }
55  output = js_buffer_obj_path
56  snapshot_dep = [ ":build_ts_js" ]
57}
58
59# compile .js to .abc.
60es2abc_gen_abc("gen_buffer_abc") {
61  extra_visibility = [ ":*" ]
62  src_js = rebase_path(target_out_dir + "/js_buffer.js")
63  dst_file = rebase_path(target_out_dir + "/buffer.abc")
64  in_puts = [ target_out_dir + "/js_buffer.js" ]
65  out_puts = [ target_out_dir + "/buffer.abc" ]
66  extra_args = [ "--module" ]
67  extra_dependencies = [ ":build_ts_js" ]
68}
69
70abc_output_path = get_label_info(":buffer_abc", "target_out_dir")
71gen_obj("buffer_abc") {
72  input = "$target_out_dir/buffer.abc"
73  if (use_mac || use_mingw_win || use_ios || use_linux) {
74    buffer_abc_obj_path = abc_output_path + "/buffer_abc.c"
75  } else {
76    buffer_abc_obj_path = abc_output_path + "/buffer_abc.o"
77  }
78  output = buffer_abc_obj_path
79  snapshot_dep = [ ":gen_buffer_abc" ]
80}
81
82buffer_sources = [
83  "converter.cpp",
84  "js_blob.cpp",
85  "js_buffer.cpp",
86  "native_module_buffer.cpp",
87]
88
89ohos_shared_library("buffer") {
90  branch_protector_ret = "pac_ret"
91  sanitize = {
92    cfi = true
93    cfi_cross_dso = true
94    debug = false
95  }
96  deps = [ ":buffer_static" ]
97  external_deps = [ "hilog:libhilog" ]
98  subsystem_name = "commonlibrary"
99  part_name = "ets_utils"
100
101  relative_install_dir = "module"
102}
103
104ohos_source_set("buffer_static") {
105  branch_protector_ret = "pac_ret"
106  sanitize = {
107    cfi = true
108    cfi_cross_dso = true
109    debug = false
110  }
111  include_dirs = [
112    "include",
113    "//third_party/icu/icu4c/source/common",
114    "//third_party/node/src",
115    ets_util_path,
116  ]
117
118  sources = buffer_sources
119
120  deps = [
121    ":gen_obj_src_buffer_abc",
122    ":gen_obj_src_js_buffer",
123  ]
124
125  configs = [ ":buffer_config" ]
126
127  if (is_arkui_x) {
128    include_dirs += [
129      "$plugins_root/hilog/include",
130      "$plugins_root/interfaces",
131      "//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
132    ]
133    if (target_os == "android") {
134      defines = [ "ANDROID_PLATFORM" ]
135    } else if (target_os == "ios") {
136      defines = [ "IOS_PLATFORM" ]
137    }
138    deps += [
139      "$plugins_root/libs/icu:icu_${target_os}",
140      "$plugins_root/libs/napi:napi_${target_os}",
141      "$plugins_root/libs/securec:sec_${target_os}",
142    ]
143  } else {
144    deps += [ "//third_party/icu/icu4c:shared_icuuc" ]
145
146    external_deps = [
147      "bounds_checking_function:libsec_shared",
148      "hilog:libhilog",
149      "napi:ace_napi",
150    ]
151
152    deps += [ "//third_party/icu/icu4c:shared_icuuc" ]
153  }
154  subsystem_name = "commonlibrary"
155  part_name = "ets_utils"
156}
157
158group("buffer_packages") {
159  public_deps = [ ":buffer" ]
160}
161