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