• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/config/components/init/param/param_fixer.gni")
125  import("//build/ohos.gni")
126  import("//third_party/libuv/libuv.gni")
127
128  common_source = [
129    "src/fs-poll.c",
130    "src/idna.c",
131    "src/inet.c",
132    "src/random.c",
133    "src/strscpy.c",
134    "src/threadpool.c",
135    "src/thread-common.c",
136    "src/timer.c",
137    "src/uv-common.c",
138    "src/uv-data-getter-setters.c",
139    "src/version.c",
140    "src/strtok.c",
141  ]
142  if (!is_mingw && !is_win) {
143    nonwin_srcs = [
144      "src/unix/async.c",
145      "src/unix/core.c",
146      "src/unix/dl.c",
147      "src/unix/fs.c",
148      "src/unix/getaddrinfo.c",
149      "src/unix/getnameinfo.c",
150      "src/unix/loop.c",
151      "src/unix/loop-watcher.c",
152      "src/unix/pipe.c",
153      "src/unix/poll.c",
154      "src/unix/process.c",
155      "src/unix/random-devurandom.c",
156      "src/unix/signal.c",
157      "src/unix/stream.c",
158      "src/unix/tcp.c",
159      "src/unix/thread.c",
160      "src/unix/tty.c",
161      "src/unix/udp.c",
162    ]
163  }
164
165  # This is the configuration needed to use libuv.
166  config("libuv_config") {
167    include_dirs = [
168      "include",
169      "src",
170      "src/unix",
171    ]
172    cflags = [ "-Wno-unused-parameter" ]
173    if (is_linux || is_ohos) {
174      cflags += [
175        "-Wno-incompatible-pointer-types",
176        "-D_GNU_SOURCE",
177        "-D_POSIX_C_SOURCE=200112",
178      ]
179      defines = []
180      if (libuv_use_ffrt && is_ohos) {
181        defines += [ "USE_FFRT" ]
182      }
183
184      if (enable_async_stack && is_ohos) {
185        defines += [ "ASYNC_STACKTRACE" ]
186      }
187
188      if (enable_uv_statisic && is_ohos) {
189        defines += [ "UV_STATISTIC" ]
190        cflags +=
191            [ "-Wno-frame-address" ]  # for use of __builtin_return_address
192      }
193
194      if (use_ohos_dfx && is_ohos && !is_emulator) {
195        defines += [ "USE_OHOS_DFX" ]
196      }
197    } else if (is_mingw || is_win) {
198      cflags += [
199        "-Wno-missing-braces",
200        "-Wno-implicit-function-declaration",
201        "-Wno-error=return-type",
202        "-Wno-error=sign-compare",
203        "-Wno-error=unused-variable",
204        "-Wno-error=unknown-pragmas",
205        "-Wno-unused-variable",
206      ]
207      defines = [
208        "WIN32_LEAN_AND_MEAN",
209        "_WIN32_WINNT=0x0600",
210        "_CRT_DECLARE_NONSTDC_NAMES=0",
211      ]
212
213      libs = [
214        "psapi",
215        "user32",
216        "advapi32",
217        "iphlpapi",
218        "userenv",
219        "ws2_32",
220        "dbghelp",
221        "ole32",
222        "shell32",
223      ]
224    }
225  }
226
227  # This is the configuration used to build libuv itself.
228  # It should not be needed outside of this library.
229  config("libuv_private_config") {
230    visibility = [ ":*" ]
231    include_dirs = [
232      "include",
233      "src",
234      "src/unix",
235    ]
236  }
237
238  ohos_source_set("libuv_source") {
239    branch_protector_ret = "pac_ret"
240    configs = [ ":libuv_config" ]
241    cflags = [ "-fvisibility=hidden" ]
242    sources = common_source
243    external_deps = []
244    if (is_mac || (defined(is_ios) && is_ios)) {
245      sources += nonwin_srcs + [
246                   "src/unix/bsd-ifaddrs.c",
247                   "src/unix/darwin-proctitle.c",
248                   "src/unix/darwin.c",
249                   "src/unix/fsevents.c",
250                   "src/unix/kqueue.c",
251                   "src/unix/log_unix.c",
252                   "src/unix/os390-proctitle.c",
253                   "src/unix/random-getentropy.c",
254                   "src/unix/trace_unix.c",
255                 ]
256    } else if (is_mingw || is_win) {
257      sources += [
258        "src/win/async.c",
259        "src/win/core.c",
260        "src/win/detect-wakeup.c",
261        "src/win/dl.c",
262        "src/win/error.c",
263        "src/win/fs-event.c",
264        "src/win/fs.c",
265        "src/win/getaddrinfo.c",
266        "src/win/getnameinfo.c",
267        "src/win/handle.c",
268        "src/win/log_win.c",
269        "src/win/loop-watcher.c",
270        "src/win/pipe.c",
271        "src/win/poll.c",
272        "src/win/process-stdio.c",
273        "src/win/process.c",
274        "src/win/signal.c",
275        "src/win/snprintf.c",
276        "src/win/stream.c",
277        "src/win/tcp.c",
278        "src/win/thread.c",
279        "src/win/trace_win.c",
280        "src/win/tty.c",
281        "src/win/udp.c",
282        "src/win/util.c",
283        "src/win/winapi.c",
284        "src/win/winsock.c",
285      ]
286    } else if (is_ohos || (defined(is_android) && is_android)) {
287      sources += nonwin_srcs + [
288                   "src/unix/linux.c",
289                   "src/unix/procfs-exepath.c",
290                   "src/unix/proctitle.c",
291                   "src/unix/random-getentropy.c",
292                   "src/unix/random-getrandom.c",
293                   "src/unix/random-sysctl-linux.c",
294                 ]
295      if (libuv_use_ffrt) {
296        external_deps += [ "ffrt:libffrt" ]
297      }
298      if (is_ohos) {
299        sources += [ "src/unix/ohos/trace_ohos.c" ]
300        if (is_emulator) {
301          sources += [ "src/unix/ohos/log_ohos.c" ]
302        }
303        external_deps += [
304          "hilog:libhilog",
305          "hitrace:hitrace_meter",
306          "init:libbegetutil",
307        ]
308      }
309
310      if (is_ohos && enable_async_stack) {
311        sources += [ "src/dfx/async_stack/libuv_async_stack.c" ]
312      }
313
314      if (is_android) {
315        sources += [
316          "src/win/log_win.c",
317          "src/win/trace_win.c",
318        ]
319      }
320    } else if (is_linux) {
321      sources += nonwin_srcs + [
322                   "src/unix/linux.c",
323                   "src/unix/log_unix.c",
324                   "src/unix/procfs-exepath.c",
325                   "src/unix/proctitle.c",
326                   "src/unix/random-getrandom.c",
327                   "src/unix/random-sysctl-linux.c",
328                   "src/unix/trace_unix.c",
329                 ]
330    } else {
331      sources += nonwin_srcs + [
332                   "src/unix/linux.c",
333                   "src/unix/procfs-exepath.c",
334                   "src/unix/proctitle.c",
335                   "src/unix/random-getrandom.c",
336                   "src/unix/random-sysctl-linux.c",
337                 ]
338    }
339    subsystem_name = "thirdparty"
340    part_name = "libuv"
341  }
342
343  ohos_prebuilt_para("libuv.para") {
344    source = "libuv.para"
345    part_name = "libuv"
346    subsystem_name = "thirdparty"
347    module_install_dir = "etc/param"
348  }
349
350  ohos_prebuilt_para("libuv.para.dac") {
351    source = "libuv.para.dac"
352    part_name = "libuv"
353    subsystem_name = "thirdparty"
354    module_install_dir = "etc/param"
355  }
356
357  ohos_static_library("uv_static") {
358    deps = [
359      ":libuv.para",
360      ":libuv.para.dac",
361      ":libuv_source",
362    ]
363    public_configs = [ ":libuv_config" ]
364    subsystem_name = "thirdparty"
365    part_name = "libuv"
366  }
367  ohos_shared_library("uv") {
368    deps = [
369      ":libuv.para",
370      ":libuv.para.dac",
371      ":libuv_source",
372    ]
373    public_configs = [ ":libuv_config" ]
374    subsystem_name = "thirdparty"
375    innerapi_tags = [ "platformsdk" ]
376    part_name = "libuv"
377    if (is_ohos) {
378      output_extension = "so"
379      external_deps = [ "hilog:libhilog" ]
380    }
381    install_images = [
382      "system",
383      "updater",
384    ]
385  }
386}
387