• 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.
13import("//build/ohos.gni")
14
15###############################################################################
16declare_args() {
17  c_utils_feature_coverage = false
18  c_utils_debug_refbase = false
19  c_utils_track_all = false
20  c_utils_print_track_at_once = false
21  c_utils_debug_log_enabled = false
22  c_utils_feature_intsan = true
23  c_utils_parcel_object_check = true
24}
25
26config("utils_config") {
27  include_dirs = [ "include" ]
28  defines = []
29  if (current_os == "ios") {
30    defines += [ "IOS_PLATFORM" ]
31  }
32  if (is_emulator == true) {
33    defines += [ "EMULATOR_PLATFORM" ]
34  }
35  if (current_os == "ohos") {
36    defines += [ "OHOS_PLATFORM" ]
37  }
38}
39
40config("utils_coverage_config") {
41  visibility = [ ":*" ]
42  if (c_utils_feature_coverage) {
43    cflags = [ "--coverage" ]
44    ldflags = [ "--coverage" ]
45  }
46}
47
48config("debug_log_enabled") {
49  visibility = [ ":*" ]
50  defines = [ "DEBUG_UTILS" ]
51}
52
53config("debug_refbase") {
54  visibility = [ ":*" ]
55  defines = [ "DEBUG_REFBASE" ]
56}
57
58config("print_track_at_once") {
59  visibility = [ ":*" ]
60  defines = [ "PRINT_TRACK_AT_ONCE" ]
61}
62
63config("track_all") {
64  visibility = [ ":*" ]
65  defines = [ "TRACK_ALL" ]
66}
67
68config("parcel_object_check") {
69  visibility = [ ":*" ]
70  defines = [ "PARCEL_OBJECT_CHECK" ]
71}
72
73sources_utils = [
74  "src/string_ex.cpp",
75  "src/unicode_ex.cpp",
76  "src/directory_ex.cpp",
77  "src/datetime_ex.cpp",
78  "src/refbase.cpp",
79  "src/parcel.cpp",
80  "src/semaphore_ex.cpp",
81  "src/thread_pool.cpp",
82  "src/file_ex.cpp",
83  "src/mapped_file.cpp",
84  "src/observer.cpp",
85  "src/thread_ex.cpp",
86  "src/io_event_handler.cpp",
87  "src/io_event_reactor.cpp",
88  "src/io_event_epoll.cpp",
89  "src/event_handler.cpp",
90  "src/event_reactor.cpp",
91  "src/event_demultiplexer.cpp",
92  "src/timer.cpp",
93  "src/timer_event_handler.cpp",
94  "src/ashmem.cpp",
95  "src/rwlock.cpp",
96]
97
98if (current_os == "ios") {
99  sources_utils_ios = [
100    "src/directory_ex.cpp",
101    "src/parcel.cpp",
102    "src/refbase.cpp",
103    "src/rwlock.cpp",
104    "src/string_ex.cpp",
105  ]
106}
107
108ohos_static_library("utilsbase") {
109  if (current_os == "ios") {
110    sources = sources_utils_ios
111    configs = [ ":utils_coverage_config" ]
112    public_configs = [ ":utils_config" ]
113
114    public_external_deps = [ "bounds_checking_function:libsec_static" ]
115
116    subsystem_name = "commonlibrary"
117    part_name = "c_utils"
118  } else {
119    sources = sources_utils
120    configs = [ ":utils_coverage_config" ]
121    public_configs = [ ":utils_config" ]
122    if (current_os != "android" && current_os != "ios") {
123      defines = [ "CONFIG_HILOG" ]
124    }
125    if (c_utils_debug_log_enabled) {
126      configs += [ ":debug_log_enabled" ]
127    }
128    external_deps = [ "hilog:libhilog_base" ]
129
130    public_external_deps = [ "bounds_checking_function:libsec_static" ]
131    subsystem_name = "commonlibrary"
132    part_name = "c_utils"
133  }
134}
135
136ohos_static_library("utilsbase_rtti") {
137  visibility = [ "//foundation/multimedia/media_foundation/engine/plugin/plugins/source/video_capture:std_video_capture" ]
138  sources = sources_utils
139  public_configs = [ ":utils_config" ]
140  if (current_os != "android" && current_os != "ios") {
141    defines = [ "CONFIG_HILOG" ]
142  }
143  external_deps = [ "hilog:libhilog_base" ]
144
145  public_external_deps = [ "bounds_checking_function:libsec_static" ]
146  remove_configs = [ "//build/config/compiler:no_rtti" ]
147  cflags = [ "-frtti" ]
148  subsystem_name = "commonlibrary"
149  part_name = "c_utils"
150}
151
152ohos_shared_library("utils") {
153  innerapi_tags = [
154    "chipsetsdk",
155    "platformsdk",
156    "sasdk",
157  ]
158  if (current_os == "ios") {
159    sources = sources_utils_ios
160    configs = [ ":utils_coverage_config" ]
161    all_dependent_configs = [ ":utils_config" ]
162    public_configs = [ ":utils_config" ]
163    public_external_deps = [ "bounds_checking_function:libsec_shared" ]
164
165    subsystem_name = "commonlibrary"
166    part_name = "c_utils"
167  } else {
168    sources = sources_utils
169    configs = [ ":utils_coverage_config" ]
170
171    if (!is_arkui_x) {
172      if (c_utils_feature_intsan) {
173        sanitize = {
174          integer_overflow = true
175        }
176        branch_protector_ret = "pac_ret"
177      }
178    }
179
180    if (c_utils_debug_refbase) {
181      configs += [ ":debug_refbase" ]
182      if (c_utils_track_all) {
183        configs += [ ":track_all" ]
184      }
185      if (c_utils_print_track_at_once) {
186        configs += [ ":print_track_at_once" ]
187      }
188    }
189    if (c_utils_parcel_object_check) {
190      configs += [ ":parcel_object_check" ]
191    }
192    all_dependent_configs = [ ":utils_config" ]
193    public_configs = [ ":utils_config" ]
194    if (current_os != "android" && current_os != "ios") {
195      defines = [ "CONFIG_HILOG" ]
196    }
197    if (c_utils_debug_log_enabled) {
198      configs += [ ":debug_log_enabled" ]
199    }
200    external_deps = [ "hilog:libhilog_base" ]
201    public_external_deps = [ "bounds_checking_function:libsec_shared" ]
202    subsystem_name = "commonlibrary"
203    part_name = "c_utils"
204    install_images = [
205      "system",
206      "updater",
207    ]
208  }
209}
210
211########## modules for `c_utils` in rust ##########
212# rust compiler is not supportted on mac
213if (host_os == "linux" && host_cpu != "arm64" && !is_arkui_x) {
214  import("//build/templates/rust/rust_cxx.gni")  # used for templates rust_cxx()
215  rust_cxx("cxx_rust_gen") {
216    sources = [
217      "src/rust/ashmem.rs",
218      "src/rust/directory_ex.rs",
219      "src/rust/file_ex.rs",
220    ]
221  }
222
223  ohos_static_library("utils_static_cxx_rust") {
224    sources = [
225      "src/ashmem.cpp",
226      "src/directory_ex.cpp",
227      "src/file_ex.cpp",
228      "src/refbase.cpp",
229    ]
230    sources += get_target_outputs(":cxx_rust_gen")
231    defines = [ "UTILS_CXX_RUST" ]
232    include_dirs = [
233      "include",
234      "${target_gen_dir}",
235    ]
236    deps = [
237      ":cxx_rust_gen",
238      "//third_party/rust/crates/cxx:cxx_cppdeps",
239    ]
240    public_external_deps = [ "bounds_checking_function:libsec_shared" ]
241    subsystem_name = "commonlibrary"
242    part_name = "c_utils"
243  }
244}
245
246if (!is_arkui_x && !(host_os == "linux" && host_cpu == "arm64")) {
247  ohos_rust_shared_library("utils_rust") {
248    if (host_os == "linux") {
249      sources = [
250        "src/rust/ashmem.rs",
251        "src/rust/directory_ex.rs",
252        "src/rust/file_ex.rs",
253        "src/rust/lib.rs",
254      ]
255      deps = [
256        ":utils_static_cxx_rust",
257        "//third_party/rust/crates/cxx:lib",
258      ]
259      crate_root = "src/rust/lib.rs"
260      crate_name = "utils_rust"
261      crate_type = "dylib"
262      output_extension = "dylib.so"
263      subsystem_name = "commonlibrary"
264      part_name = "c_utils"
265      install_images = [
266        "system",
267        "updater",
268      ]
269    } else {
270      sources = [
271        "src/rust/ashmem.rs",
272        "src/rust/directory_ex.rs",
273        "src/rust/file_ex.rs",
274        "src/rust/lib.rs",
275      ]
276    }
277  }
278}
279###############################################################################
280