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_uv_statisic && is_ohos) { 188 defines += [ "UV_STATISTIC" ] 189 cflags += 190 [ "-Wno-frame-address" ] # for use of __builtin_return_address 191 } 192 193 if (use_ohos_dfx && is_ohos && !is_emulator) { 194 defines += [ "USE_OHOS_DFX" ] 195 } 196 } else if (is_mingw || is_win) { 197 cflags += [ 198 "-Wno-missing-braces", 199 "-Wno-implicit-function-declaration", 200 "-Wno-error=return-type", 201 "-Wno-error=sign-compare", 202 "-Wno-error=unused-variable", 203 "-Wno-error=unknown-pragmas", 204 "-Wno-unused-variable", 205 ] 206 defines = [ 207 "WIN32_LEAN_AND_MEAN", 208 "_WIN32_WINNT=0x0600", 209 "_CRT_DECLARE_NONSTDC_NAMES=0", 210 ] 211 212 libs = [ 213 "psapi", 214 "user32", 215 "advapi32", 216 "iphlpapi", 217 "userenv", 218 "ws2_32", 219 "dbghelp", 220 "ole32", 221 "shell32", 222 ] 223 } 224 } 225 226 # This is the configuration used to build libuv itself. 227 # It should not be needed outside of this library. 228 config("libuv_private_config") { 229 visibility = [ ":*" ] 230 include_dirs = [ 231 "include", 232 "src", 233 "src/unix", 234 ] 235 } 236 237 ohos_source_set("libuv_source") { 238 branch_protector_ret = "pac_ret" 239 configs = [ ":libuv_config" ] 240 cflags = [ "-fvisibility=hidden" ] 241 sources = common_source 242 external_deps = [] 243 if (is_mac || (defined(is_ios) && is_ios)) { 244 sources += nonwin_srcs + [ 245 "src/unix/bsd-ifaddrs.c", 246 "src/unix/kqueue.c", 247 "src/unix/random-getentropy.c", 248 "src/unix/darwin-proctitle.c", 249 "src/unix/darwin.c", 250 "src/unix/fsevents.c", 251 "src/unix/os390-proctitle.c", 252 "src/unix/log_unix.c", 253 "src/unix/trace_unix.c", 254 ] 255 } else if (is_mingw || is_win) { 256 sources += [ 257 "src/win/async.c", 258 "src/win/core.c", 259 "src/win/detect-wakeup.c", 260 "src/win/dl.c", 261 "src/win/error.c", 262 "src/win/fs-event.c", 263 "src/win/fs.c", 264 "src/win/getaddrinfo.c", 265 "src/win/getnameinfo.c", 266 "src/win/handle.c", 267 "src/win/log_win.c", 268 "src/win/loop-watcher.c", 269 "src/win/pipe.c", 270 "src/win/poll.c", 271 "src/win/process-stdio.c", 272 "src/win/process.c", 273 "src/win/signal.c", 274 "src/win/snprintf.c", 275 "src/win/stream.c", 276 "src/win/tcp.c", 277 "src/win/thread.c", 278 "src/win/trace_win.c", 279 "src/win/tty.c", 280 "src/win/udp.c", 281 "src/win/util.c", 282 "src/win/winapi.c", 283 "src/win/winsock.c", 284 ] 285 } else if (is_ohos || (defined(is_android) && is_android)) { 286 sources += nonwin_srcs + [ 287 "src/unix/linux.c", 288 "src/unix/procfs-exepath.c", 289 "src/unix/random-getentropy.c", 290 "src/unix/random-getrandom.c", 291 "src/unix/random-sysctl-linux.c", 292 "src/unix/proctitle.c", 293 ] 294 if (libuv_use_ffrt) { 295 external_deps += [ "ffrt:libffrt" ] 296 } 297 if (is_ohos) { 298 sources += [ "src/unix/ohos/trace_ohos.c" ] 299 if (is_emulator) { 300 sources += [ "src/unix/ohos/log_ohos.c" ] 301 } 302 external_deps += [ 303 "hilog:libhilog", 304 "hitrace:hitrace_meter", 305 ] 306 } 307 308 if (is_ohos && enable_async_stack) { 309 sources += [ "src/dfx/async_stack/libuv_async_stack.c" ] 310 } 311 312 if (is_android) { 313 sources += [ 314 "src/win/log_win.c", 315 "src/win/trace_win.c", 316 ] 317 } 318 } else if (is_linux) { 319 sources += nonwin_srcs + [ 320 "src/unix/linux.c", 321 "src/unix/procfs-exepath.c", 322 "src/unix/random-getrandom.c", 323 "src/unix/random-sysctl-linux.c", 324 "src/unix/proctitle.c", 325 "src/unix/log_unix.c", 326 "src/unix/trace_unix.c", 327 ] 328 } else { 329 sources += nonwin_srcs + [ 330 "src/unix/linux.c", 331 "src/unix/procfs-exepath.c", 332 "src/unix/random-getrandom.c", 333 "src/unix/random-sysctl-linux.c", 334 "src/unix/proctitle.c", 335 ] 336 } 337 subsystem_name = "thirdparty" 338 part_name = "libuv" 339 } 340 341 ohos_static_library("uv_static") { 342 deps = [ ":libuv_source" ] 343 public_configs = [ ":libuv_config" ] 344 subsystem_name = "thirdparty" 345 part_name = "libuv" 346 } 347 ohos_shared_library("uv") { 348 deps = [ ":libuv_source" ] 349 public_configs = [ ":libuv_config" ] 350 subsystem_name = "thirdparty" 351 innerapi_tags = [ "platformsdk" ] 352 part_name = "libuv" 353 if (is_ohos) { 354 output_extension = "so" 355 external_deps = [ "hilog:libhilog" ] 356 } 357 install_images = [ 358 "system", 359 "updater", 360 ] 361 } 362} 363