1e509ee18Sopenharmony_ci# Copyright (c) 2023 Huawei Device Co., Ltd.
2e509ee18Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
3e509ee18Sopenharmony_ci# you may not use this file except in compliance with the License.
4e509ee18Sopenharmony_ci# You may obtain a copy of the License at
5e509ee18Sopenharmony_ci#
6e509ee18Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
7e509ee18Sopenharmony_ci#
8e509ee18Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
9e509ee18Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
10e509ee18Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11e509ee18Sopenharmony_ci# See the License for the specific language governing permissions and
12e509ee18Sopenharmony_ci# limitations under the License.
13e509ee18Sopenharmony_ci
14e509ee18Sopenharmony_ciimport("$build_root/ark.gni")
15e509ee18Sopenharmony_ci
16e509ee18Sopenharmony_cicommon_source = [
17e509ee18Sopenharmony_ci  "//third_party/libuv/src/fs-poll.c",
18e509ee18Sopenharmony_ci  "//third_party/libuv/src/idna.c",
19e509ee18Sopenharmony_ci  "//third_party/libuv/src/inet.c",
20e509ee18Sopenharmony_ci  "//third_party/libuv/src/random.c",
21e509ee18Sopenharmony_ci  "//third_party/libuv/src/strscpy.c",
22e509ee18Sopenharmony_ci  "//third_party/libuv/src/threadpool.c",
23e509ee18Sopenharmony_ci  "//third_party/libuv/src/thread-common.c",
24e509ee18Sopenharmony_ci  "//third_party/libuv/src/timer.c",
25e509ee18Sopenharmony_ci  "//third_party/libuv/src/uv-common.c",
26e509ee18Sopenharmony_ci  "//third_party/libuv/src/uv-data-getter-setters.c",
27e509ee18Sopenharmony_ci  "//third_party/libuv/src/version.c",
28e509ee18Sopenharmony_ci  "//third_party/libuv/src/strtok.c",
29e509ee18Sopenharmony_ci]
30e509ee18Sopenharmony_ciif (!is_mingw && !is_win) {
31e509ee18Sopenharmony_ci  nonwin_srcs = [
32e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/async.c",
33e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/core.c",
34e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/dl.c",
35e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/fs.c",
36e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/getaddrinfo.c",
37e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/getnameinfo.c",
38e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/loop.c",
39e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/loop-watcher.c",
40e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/pipe.c",
41e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/poll.c",
42e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/process.c",
43e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/random-devurandom.c",
44e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/signal.c",
45e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/stream.c",
46e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/tcp.c",
47e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/thread.c",
48e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/tty.c",
49e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix/udp.c",
50e509ee18Sopenharmony_ci  ]
51e509ee18Sopenharmony_ci}
52e509ee18Sopenharmony_ci
53e509ee18Sopenharmony_ci# This is the configuration needed to use libuv.
54e509ee18Sopenharmony_ciconfig("libuv_config") {
55e509ee18Sopenharmony_ci  include_dirs = [
56e509ee18Sopenharmony_ci    "//third_party/libuv/include",
57e509ee18Sopenharmony_ci    "//third_party/libuv/src",
58e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix",
59e509ee18Sopenharmony_ci  ]
60e509ee18Sopenharmony_ci  defines = []
61e509ee18Sopenharmony_ci  cflags = [ "-Wno-unused-parameter" ]
62e509ee18Sopenharmony_ci  if (is_linux || is_ohos) {
63e509ee18Sopenharmony_ci    cflags += [
64e509ee18Sopenharmony_ci      "-Wno-incompatible-pointer-types",
65e509ee18Sopenharmony_ci      "-D_GNU_SOURCE",
66e509ee18Sopenharmony_ci      "-D_POSIX_C_SOURCE=200112",
67e509ee18Sopenharmony_ci    ]
68e509ee18Sopenharmony_ci
69e509ee18Sopenharmony_ci    # Adding NDEBUG macro manually to avoid compilation
70e509ee18Sopenharmony_ci    # error in debug version, FIX ME
71e509ee18Sopenharmony_ci    # https://gitee.com/openharmony/build/pulls/1206/files
72e509ee18Sopenharmony_ci    defines += [ "NDEBUG" ]
73e509ee18Sopenharmony_ci  } else if (is_mingw || is_win) {
74e509ee18Sopenharmony_ci    cflags += [
75e509ee18Sopenharmony_ci      "-Wno-missing-braces",
76e509ee18Sopenharmony_ci      "-Wno-implicit-function-declaration",
77e509ee18Sopenharmony_ci      "-Wno-error=return-type",
78e509ee18Sopenharmony_ci      "-Wno-error=sign-compare",
79e509ee18Sopenharmony_ci      "-Wno-error=unused-variable",
80e509ee18Sopenharmony_ci      "-Wno-error=unknown-pragmas",
81e509ee18Sopenharmony_ci      "-Wno-unused-variable",
82e509ee18Sopenharmony_ci    ]
83e509ee18Sopenharmony_ci    defines += [
84e509ee18Sopenharmony_ci      "WIN32_LEAN_AND_MEAN",
85e509ee18Sopenharmony_ci      "_WIN32_WINNT=0x0600",
86e509ee18Sopenharmony_ci    ]
87e509ee18Sopenharmony_ci
88e509ee18Sopenharmony_ci    # Adding NDEBUG macro manually to avoid compilation
89e509ee18Sopenharmony_ci    # error in debug version, FIX ME
90e509ee18Sopenharmony_ci    # https://gitee.com/openharmony/build/pulls/1206/files
91e509ee18Sopenharmony_ci    defines += [ "NDEBUG" ]
92e509ee18Sopenharmony_ci
93e509ee18Sopenharmony_ci    libs = [
94e509ee18Sopenharmony_ci      "psapi",
95e509ee18Sopenharmony_ci      "user32",
96e509ee18Sopenharmony_ci      "advapi32",
97e509ee18Sopenharmony_ci      "iphlpapi",
98e509ee18Sopenharmony_ci      "userenv",
99e509ee18Sopenharmony_ci      "ws2_32",
100e509ee18Sopenharmony_ci    ]
101e509ee18Sopenharmony_ci  } else if (is_android) {
102e509ee18Sopenharmony_ci    defines += [ "_GNU_SOURCE" ]
103e509ee18Sopenharmony_ci  }
104e509ee18Sopenharmony_ci}
105e509ee18Sopenharmony_ci
106e509ee18Sopenharmony_ci# This is the configuration used to build libuv itself.
107e509ee18Sopenharmony_ci# It should not be needed outside of this library.
108e509ee18Sopenharmony_ciconfig("libuv_private_config") {
109e509ee18Sopenharmony_ci  visibility = [ ":*" ]
110e509ee18Sopenharmony_ci  include_dirs = [
111e509ee18Sopenharmony_ci    "//third_party/libuv/include",
112e509ee18Sopenharmony_ci    "//third_party/libuv/src",
113e509ee18Sopenharmony_ci    "//third_party/libuv/src/unix",
114e509ee18Sopenharmony_ci  ]
115e509ee18Sopenharmony_ci
116e509ee18Sopenharmony_ci  # Adding NDEBUG macro manually to avoid compilation
117e509ee18Sopenharmony_ci  # error in debug version, FIX ME
118e509ee18Sopenharmony_ci  # https://gitee.com/openharmony/build/pulls/1206/files
119e509ee18Sopenharmony_ci  defines = [ "NDEBUG" ]
120e509ee18Sopenharmony_ci}
121e509ee18Sopenharmony_ci
122e509ee18Sopenharmony_ciohos_source_set("libuv_source") {
123e509ee18Sopenharmony_ci  stack_protector_ret = false
124e509ee18Sopenharmony_ci  configs = [ ":libuv_config" ]
125e509ee18Sopenharmony_ci  sources = common_source
126e509ee18Sopenharmony_ci  external_deps = []
127e509ee18Sopenharmony_ci  if (is_mac || (defined(is_ios) && is_ios)) {
128e509ee18Sopenharmony_ci    sources += nonwin_srcs + [
129e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/bsd-ifaddrs.c",
130e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/kqueue.c",
131e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/random-getentropy.c",
132e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/darwin-proctitle.c",
133e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/darwin.c",
134e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/fsevents.c",
135e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/os390-proctitle.c",
136e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/log_unix.c",
137e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/trace_unix.c",
138e509ee18Sopenharmony_ci               ]
139e509ee18Sopenharmony_ci  } else if (is_mingw || is_win) {
140e509ee18Sopenharmony_ci    sources += [
141e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/async.c",
142e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/core.c",
143e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/detect-wakeup.c",
144e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/dl.c",
145e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/error.c",
146e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/fs-event.c",
147e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/fs.c",
148e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/getaddrinfo.c",
149e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/getnameinfo.c",
150e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/handle.c",
151e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/log_win.c",
152e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/loop-watcher.c",
153e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/pipe.c",
154e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/poll.c",
155e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/process-stdio.c",
156e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/process.c",
157e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/signal.c",
158e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/snprintf.c",
159e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/stream.c",
160e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/tcp.c",
161e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/thread.c",
162e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/trace_win.c",
163e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/tty.c",
164e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/udp.c",
165e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/util.c",
166e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/winapi.c",
167e509ee18Sopenharmony_ci      "//third_party/libuv/src/win/winsock.c",
168e509ee18Sopenharmony_ci    ]
169e509ee18Sopenharmony_ci  } else if (is_ohos || (defined(is_android) && is_android)) {
170e509ee18Sopenharmony_ci    sources += nonwin_srcs + [
171e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/linux.c",
172e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/procfs-exepath.c",
173e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/random-getentropy.c",
174e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/random-getrandom.c",
175e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/random-sysctl-linux.c",
176e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/proctitle.c",
177e509ee18Sopenharmony_ci               ]
178e509ee18Sopenharmony_ci    sources += [
179e509ee18Sopenharmony_ci      "src/log_ohos.c",
180e509ee18Sopenharmony_ci      "src/trace_ohos.c",
181e509ee18Sopenharmony_ci    ]
182e509ee18Sopenharmony_ci  } else if (is_linux) {
183e509ee18Sopenharmony_ci    sources += nonwin_srcs + [
184e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/linux.c",
185e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/procfs-exepath.c",
186e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/random-getrandom.c",
187e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/random-sysctl-linux.c",
188e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/proctitle.c",
189e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/log_unix.c",
190e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/trace_unix.c",
191e509ee18Sopenharmony_ci               ]
192e509ee18Sopenharmony_ci  } else {
193e509ee18Sopenharmony_ci    sources += nonwin_srcs + [
194e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/linux.c",
195e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/procfs-exepath.c",
196e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/random-getrandom.c",
197e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/random-sysctl-linux.c",
198e509ee18Sopenharmony_ci                 "//third_party/libuv/src/unix/proctitle.c",
199e509ee18Sopenharmony_ci               ]
200e509ee18Sopenharmony_ci  }
201e509ee18Sopenharmony_ci  subsystem_name = "thirdparty"
202e509ee18Sopenharmony_ci  part_name = "libuv"
203e509ee18Sopenharmony_ci}
204e509ee18Sopenharmony_ci
205e509ee18Sopenharmony_ciohos_static_library("uv_static") {
206e509ee18Sopenharmony_ci  stack_protector_ret = false
207e509ee18Sopenharmony_ci  deps = [ ":libuv_source" ]
208e509ee18Sopenharmony_ci  public_configs = [ ":libuv_config" ]
209e509ee18Sopenharmony_ci  subsystem_name = "thirdparty"
210e509ee18Sopenharmony_ci  part_name = "libuv"
211e509ee18Sopenharmony_ci}
212e509ee18Sopenharmony_ci
213e509ee18Sopenharmony_ciohos_shared_library("uv") {
214e509ee18Sopenharmony_ci  stack_protector_ret = false
215e509ee18Sopenharmony_ci  deps = [ ":libuv_source" ]
216e509ee18Sopenharmony_ci  public_configs = [ ":libuv_config" ]
217e509ee18Sopenharmony_ci  subsystem_name = "thirdparty"
218e509ee18Sopenharmony_ci  part_name = "libuv"
219e509ee18Sopenharmony_ci  if (is_ohos) {
220e509ee18Sopenharmony_ci    output_extension = "so"
221e509ee18Sopenharmony_ci  }
222e509ee18Sopenharmony_ci  install_images = [
223e509ee18Sopenharmony_ci    "system",
224e509ee18Sopenharmony_ci    "updater",
225e509ee18Sopenharmony_ci  ]
226e509ee18Sopenharmony_ci}
227