1# Copyright (c) 2021-2024 Huawei Device Co., Ltd. 2# 3# Permission is hereby granted, free of charge, to any person obtaining a copy 4# of this software and associated documentation files (the "Software"), to 5# deal in the Software without restriction, including without limitation the 6# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7# sell copies of the Software, and to permit persons to whom the Software is 8# furnished to do so, subject to the following conditions: 9# 10# The above copyright notice and this permission notice shall be included in 11# all copies or substantial portions of the Software. 12# 13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19# IN THE SOFTWARE. 20 21if (defined(ohos_lite)) { 22 import("//build/lite/config/component/lite_component.gni") 23 import("//build/lite/ndk/ndk.gni") 24 import("//third_party/libuv/libuv.gni") 25 26 # This is the configuration needed to use libuv. 27 config("libuv_config") { 28 include_dirs = [ 29 "include", 30 "src", 31 "src/unix", 32 ] 33 cflags = [ 34 "-Wno-unused-parameter", 35 "-Wno-incompatible-pointer-types", 36 "-D_GNU_SOURCE", 37 "-D_POSIX_C_SOURCE=200112", 38 ] 39 } 40 41 # This is the configuration used to build libuv itself. 42 # It should not be needed outside of this library. 43 config("libuv_private_config") { 44 visibility = [ ":*" ] 45 include_dirs = [ 46 "include", 47 "src", 48 "src/unix", 49 ] 50 } 51 52 source_set("libuv_source") { 53 include_dirs = [ 54 "include", 55 "src", 56 "src/unix", 57 ] 58 59 cflags = [ 60 "-Wno-unused-parameter", 61 "-Wno-incompatible-pointer-types", 62 "-D_GNU_SOURCE", 63 "-D_POSIX_C_SOURCE=200112", 64 "-U__linux__", 65 "-D__GNU__", 66 "-fPIC", 67 ] 68 69 sources = [ 70 # common_source 71 "src/fs-poll.c", 72 "src/idna.c", 73 "src/inet.c", 74 "src/random.c", 75 "src/strscpy.c", 76 "src/strtok.c", 77 "src/thread-common.c", 78 "src/threadpool.c", 79 "src/timer.c", 80 "src/uv-common.c", 81 "src/uv-data-getter-setters.c", 82 "src/version.c", 83 84 # nonwin_srcs 85 "src/unix/async.c", 86 "src/unix/core.c", 87 "src/unix/dl.c", 88 "src/unix/fs.c", 89 "src/unix/getaddrinfo.c", 90 "src/unix/getnameinfo.c", 91 "src/unix/linux.c", 92 "src/unix/loop-watcher.c", 93 "src/unix/loop.c", 94 "src/unix/no-fsevents.c", 95 "src/unix/pipe.c", 96 "src/unix/poll.c", 97 "src/unix/posix-hrtime.c", 98 "src/unix/posix-poll.c", 99 "src/unix/process.c", 100 "src/unix/random-devurandom.c", 101 "src/unix/signal.c", 102 "src/unix/stream.c", 103 "src/unix/tcp.c", 104 "src/unix/thread.c", 105 "src/unix/tty.c", 106 "src/unix/udp.c", 107 ] 108 } 109 110 static_library("uv_static") { 111 deps = [ ":libuv_source" ] 112 public_configs = [ ":libuv_config" ] 113 } 114 115 shared_library("uv") { 116 deps = [ ":libuv_source" ] 117 public_configs = [ ":libuv_config" ] 118 libs = [ 119 "pthread", 120 "dl", 121 ] 122 } 123} else { 124 import("//build/ohos.gni") 125 import("//third_party/libuv/libuv.gni") 126 127 common_source = [ 128 "src/fs-poll.c", 129 "src/idna.c", 130 "src/inet.c", 131 "src/random.c", 132 "src/strscpy.c", 133 "src/threadpool.c", 134 "src/thread-common.c", 135 "src/timer.c", 136 "src/uv-common.c", 137 "src/uv-data-getter-setters.c", 138 "src/version.c", 139 "src/strtok.c", 140 ] 141 if (!is_mingw && !is_win) { 142 nonwin_srcs = [ 143 "src/unix/async.c", 144 "src/unix/core.c", 145 "src/unix/dl.c", 146 "src/unix/fs.c", 147 "src/unix/getaddrinfo.c", 148 "src/unix/getnameinfo.c", 149 "src/unix/loop.c", 150 "src/unix/loop-watcher.c", 151 "src/unix/pipe.c", 152 "src/unix/poll.c", 153 "src/unix/process.c", 154 "src/unix/random-devurandom.c", 155 "src/unix/signal.c", 156 "src/unix/stream.c", 157 "src/unix/tcp.c", 158 "src/unix/thread.c", 159 "src/unix/tty.c", 160 "src/unix/udp.c", 161 ] 162 } 163 164 # This is the configuration needed to use libuv. 165 config("libuv_config") { 166 include_dirs = [ 167 "include", 168 "src", 169 "src/unix", 170 ] 171 cflags = [ "-Wno-unused-parameter" ] 172 if (is_linux || is_ohos) { 173 cflags += [ 174 "-Wno-incompatible-pointer-types", 175 "-D_GNU_SOURCE", 176 "-D_POSIX_C_SOURCE=200112", 177 ] 178 defines = [] 179 if (libuv_use_ffrt && is_ohos) { 180 defines += [ "USE_FFRT" ] 181 } 182 183 if (enable_async_stack && is_ohos) { 184 defines += [ "ASYNC_STACKTRACE" ] 185 } 186 187 if (enable_print_errno_abort && is_ohos) { 188 defines += [ "PRINT_ERRNO_ABORT" ] 189 } 190 191 if (enable_uv_statisic && is_ohos) { 192 defines += [ "UV_STATISTIC" ] 193 cflags += 194 [ "-Wno-frame-address" ] # for use of __builtin_return_address 195 } 196 197 if (use_ohos_dfx && is_ohos && !is_emulator) { 198 defines += [ "USE_OHOS_DFX" ] 199 } 200 } else if (is_mingw || is_win) { 201 cflags += [ 202 "-Wno-missing-braces", 203 "-Wno-implicit-function-declaration", 204 "-Wno-error=return-type", 205 "-Wno-error=sign-compare", 206 "-Wno-error=unused-variable", 207 "-Wno-error=unknown-pragmas", 208 "-Wno-unused-variable", 209 ] 210 defines = [ 211 "WIN32_LEAN_AND_MEAN", 212 "_WIN32_WINNT=0x0600", 213 "_CRT_DECLARE_NONSTDC_NAMES=0", 214 ] 215 216 libs = [ 217 "psapi", 218 "user32", 219 "advapi32", 220 "iphlpapi", 221 "userenv", 222 "ws2_32", 223 "dbghelp", 224 "ole32", 225 "shell32", 226 ] 227 } 228 } 229 230 # This is the configuration used to build libuv itself. 231 # It should not be needed outside of this library. 232 config("libuv_private_config") { 233 visibility = [ ":*" ] 234 include_dirs = [ 235 "include", 236 "src", 237 "src/unix", 238 ] 239 } 240 241 ohos_source_set("libuv_source") { 242 branch_protector_ret = "pac_ret" 243 configs = [ ":libuv_config" ] 244 cflags = [ "-fvisibility=hidden" ] 245 sources = common_source 246 external_deps = [] 247 if (is_mac || (defined(is_ios) && is_ios)) { 248 sources += nonwin_srcs + [ 249 "src/unix/bsd-ifaddrs.c", 250 "src/unix/kqueue.c", 251 "src/unix/random-getentropy.c", 252 "src/unix/darwin-proctitle.c", 253 "src/unix/darwin.c", 254 "src/unix/fsevents.c", 255 "src/unix/os390-proctitle.c", 256 "src/unix/log_unix.c", 257 "src/unix/trace_unix.c", 258 ] 259 } else if (is_mingw || is_win) { 260 sources += [ 261 "src/win/async.c", 262 "src/win/core.c", 263 "src/win/detect-wakeup.c", 264 "src/win/dl.c", 265 "src/win/error.c", 266 "src/win/fs-event.c", 267 "src/win/fs.c", 268 "src/win/getaddrinfo.c", 269 "src/win/getnameinfo.c", 270 "src/win/handle.c", 271 "src/win/log_win.c", 272 "src/win/loop-watcher.c", 273 "src/win/pipe.c", 274 "src/win/poll.c", 275 "src/win/process-stdio.c", 276 "src/win/process.c", 277 "src/win/signal.c", 278 "src/win/snprintf.c", 279 "src/win/stream.c", 280 "src/win/tcp.c", 281 "src/win/thread.c", 282 "src/win/trace_win.c", 283 "src/win/tty.c", 284 "src/win/udp.c", 285 "src/win/util.c", 286 "src/win/winapi.c", 287 "src/win/winsock.c", 288 ] 289 } else if (is_ohos || (defined(is_android) && is_android)) { 290 sources += nonwin_srcs + [ 291 "src/unix/linux.c", 292 "src/unix/procfs-exepath.c", 293 "src/unix/random-getentropy.c", 294 "src/unix/random-getrandom.c", 295 "src/unix/random-sysctl-linux.c", 296 "src/unix/proctitle.c", 297 ] 298 if (libuv_use_ffrt) { 299 external_deps += [ "ffrt:libffrt" ] 300 } 301 if (is_ohos) { 302 sources += [ "src/unix/ohos/trace_ohos.c" ] 303 if (is_emulator) { 304 sources += [ "src/unix/ohos/log_ohos.c" ] 305 } 306 external_deps += [ 307 "hilog:libhilog", 308 "hitrace:hitrace_meter", 309 ] 310 } 311 312 if (is_ohos && enable_async_stack) { 313 sources += [ "src/dfx/async_stack/libuv_async_stack.c" ] 314 } 315 316 if (is_android) { 317 sources += [ 318 "src/win/log_win.c", 319 "src/win/trace_win.c", 320 ] 321 } 322 } else if (is_linux) { 323 sources += nonwin_srcs + [ 324 "src/unix/linux.c", 325 "src/unix/procfs-exepath.c", 326 "src/unix/random-getrandom.c", 327 "src/unix/random-sysctl-linux.c", 328 "src/unix/proctitle.c", 329 "src/unix/log_unix.c", 330 "src/unix/trace_unix.c", 331 ] 332 } else { 333 sources += nonwin_srcs + [ 334 "src/unix/linux.c", 335 "src/unix/procfs-exepath.c", 336 "src/unix/random-getrandom.c", 337 "src/unix/random-sysctl-linux.c", 338 "src/unix/proctitle.c", 339 ] 340 } 341 subsystem_name = "thirdparty" 342 part_name = "libuv" 343 } 344 345 ohos_static_library("uv_static") { 346 deps = [ ":libuv_source" ] 347 public_configs = [ ":libuv_config" ] 348 subsystem_name = "thirdparty" 349 part_name = "libuv" 350 } 351 ohos_shared_library("uv") { 352 deps = [ ":libuv_source" ] 353 public_configs = [ ":libuv_config" ] 354 subsystem_name = "thirdparty" 355 innerapi_tags = [ "platformsdk" ] 356 part_name = "libuv" 357 if (is_ohos) { 358 output_extension = "so" 359 external_deps = [ "hilog:libhilog" ] 360 } 361 install_images = [ 362 "system", 363 "updater", 364 ] 365 } 366} 367