• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
13
14import("//build/ohos.gni")
15HDC_PATH = "."
16import("//developtools/hdc/hdc.gni")
17
18py_out_dir = "$root_out_dir/gen/" + rebase_path(".", "//")
19
20declare_args() {
21  # suggestion: uv threads number from 16 - 256
22  hdcd_uv_thread_size = 4
23  hdc_uv_thread_size = 128
24}
25
26hdc_common_sources = [
27  "src/common/async_cmd.cpp",
28  "src/common/auth.cpp",
29  "src/common/base.cpp",
30  "src/common/channel.cpp",
31  "src/common/circle_buffer.cpp",
32  "src/common/compress.cpp",
33  "src/common/debug.cpp",
34  "src/common/decompress.cpp",
35  "src/common/entry.cpp",
36  "src/common/file.cpp",
37  "src/common/file_descriptor.cpp",
38  "src/common/forward.cpp",
39  "src/common/header.cpp",
40  "src/common/heartbeat.cpp",
41  "src/common/session.cpp",
42  "src/common/task.cpp",
43  "src/common/tcp.cpp",
44  "src/common/tlv.cpp",
45  "src/common/transfer.cpp",
46  "src/common/usb.cpp",
47]
48
49hash_sources = [
50  "scripts/hdc_hash_gen.py",
51  "src/common/base.cpp",
52  "src/common/channel.h",
53  "src/common/session.h",
54  "src/common/transfer.h",
55]
56
57if (hdc_support_uart) {
58  hdc_common_sources += [ "src/common/uart.cpp" ]
59}
60config("hdc_config") {
61  include_dirs = [
62    "src/common",
63    "${py_out_dir}",
64  ]
65  cflags_cc = [ "-std=c++17" ]
66  if (is_mingw) {
67    cflags_cc += [ "-Wno-inconsistent-dllimport" ]  # in mingw some sec api will
68                                                    # overwrite by utilsecurec
69  }
70}
71
72template("hdcd_source_set") {
73  forward_variables_from(invoker, "*")
74
75  ohos_source_set(target_name) {
76    use_exceptions = true
77    sources = [
78      "src/daemon/daemon.cpp",
79      "src/daemon/daemon_app.cpp",
80      "src/daemon/daemon_bridge.cpp",
81      "src/daemon/daemon_forward.cpp",
82      "src/daemon/daemon_tcp.cpp",
83      "src/daemon/daemon_unity.cpp",
84      "src/daemon/daemon_usb.cpp",
85      "src/daemon/jdwp.cpp",
86      "src/daemon/main.cpp",
87      "src/daemon/shell.cpp",
88      "src/daemon/system_depend.cpp",
89    ]
90    sources += hdc_common_sources
91
92    defines = [
93      "HARMONY_PROJECT",
94      "USE_CONFIG_UV_THREADS",
95      "SIZE_THREAD_POOL=$hdcd_uv_thread_size",
96      "HDC_HILOG",
97      "OPENSSL_SUPPRESS_DEPRECATED",
98    ]
99
100    if (hdc_debug) {
101      defines += [ "HDC_DEBUG" ]
102    }
103    if (hdc_support_uart) {
104      defines += [ "HDC_SUPPORT_UART" ]
105      sources += [ "src/daemon/daemon_uart.cpp" ]
106    }
107    if (js_jdwp_connect) {
108      defines += [ "JS_JDWP_CONNECT" ]
109    }
110    if (use_musl) {
111      if (musl_use_jemalloc && musl_use_jemalloc_dfx_intf) {
112        defines += [ "CONFIG_USE_JEMALLOC_DFX_INIF" ]
113      }
114    }
115    if (is_emulator) {
116      defines += [ "HDC_EMULATOR" ]
117    }
118    if (build_variant == "user") {
119      defines += [ "IS_RELEASE_VERSION" ]
120    }
121    configs = [ ":hdc_config" ]
122
123    deps = []
124
125    deps += [
126      ":hdc_hash_gen",
127      "src/daemon/etc:daemon_etc",
128    ]
129
130    if (hdc_jdwp_test) {
131      defines += [ "SIMULATE_JDWP" ]
132      deps += [ "src/test/jdwp:jdwp_test" ]
133    }
134
135    external_deps = [
136      "bounds_checking_function:libsec_shared",
137      "c_utils:utils",
138      "hilog:libhilog",
139      "init:libbegetutil",
140      "libuv:uv",
141      "lz4:liblz4_static",
142      "openssl:libcrypto_shared",
143    ]
144
145    if (build_selinux) {
146      external_deps += [ "selinux:libselinux" ]
147      defines += [ "SURPPORT_SELINUX" ]
148      if (image_name == "updater") {
149        defines += [ "UPDATER_MODE" ]
150      }
151      if (image_name == "system") {
152        defines += [ "HDC_TRACE" ]
153        external_deps += [ "hitrace:hitrace_meter" ]
154      }
155    }
156
157    if (hdc_version_check) {
158      defines += [ "HDC_VERSION_CHECK" ]
159    }
160
161    ldflags = [ "-rdynamic" ]
162
163    subsystem_name = "developtools"
164    part_name = "hdc"
165  }
166}
167
168if (product_name != "ohos-sdk") {
169  ohos_static_library("serialize_structs") {
170    sources = [
171      "hdc_rust/src/cffi/bridge.cpp",
172      "hdc_rust/src/cffi/cmd.cpp",
173      "hdc_rust/src/cffi/getparameter.cpp",
174      "hdc_rust/src/cffi/log.cpp",
175      "hdc_rust/src/cffi/mount.cpp",
176      "hdc_rust/src/cffi/mount_wrapper.cpp",
177      "hdc_rust/src/cffi/oh_usb.cpp",
178      "hdc_rust/src/cffi/sendmsg.cpp",
179      "hdc_rust/src/cffi/serial_struct.cpp",
180      "hdc_rust/src/cffi/sys_para.cpp",
181      "hdc_rust/src/cffi/transfer.cpp",
182      "hdc_rust/src/cffi/uart.cpp",
183      "hdc_rust/src/cffi/uart_wrapper.cpp",
184      "hdc_rust/src/cffi/usb_util.cpp",
185      "hdc_rust/src/cffi/usb_wrapper.cpp",
186      "hdc_rust/src/cffi/utils.cpp",
187    ]
188
189    external_deps = [
190      "bounds_checking_function:libsec_static",
191      "hilog:libhilog",
192      "init:libbegetutil",
193      "lz4:liblz4_static",
194    ]
195
196    defines = [ "HDC_HILOG" ]
197
198    if (is_mac) {
199      defines = [ "HOST_MAC" ]
200    }
201
202    if (build_selinux) {
203      external_deps += [ "selinux:libselinux" ]
204      defines += [ "SURPPORT_SELINUX" ]
205    }
206
207    subsystem_name = "developtools"
208    part_name = "hdc"
209  }
210
211  ohos_rust_static_library("lib") {
212    crate_name = "hdc"
213    crate_type = "rlib"
214    crate_root = "hdc_rust/src/lib.rs"
215    sources = [ "hdc_rust/src/lib.rs" ]
216
217    deps = [
218      ":serialize_structs",
219      "//third_party/rust/crates/humantime:lib",
220      "//third_party/rust/crates/libc:lib",
221      "//third_party/rust/crates/log:lib",
222    ]
223    if (is_emulator && product_name != "ohos-sdk") {
224      features = [ "emulator" ]
225    }
226    external_deps = [
227      "hilog:hilog_rust",
228      "rust_rust-openssl:lib",
229      "ylong_runtime:ylong_runtime",
230    ]
231    subsystem_name = "developtools"
232    part_name = "hdc"
233  }
234}
235
236template("build_hdc") {
237  forward_variables_from(invoker, "*")
238  image_name = target_name
239  hdcd_source_set("hdcd_${image_name}_source") {
240    if (build_selinux) {
241      image_name = image_name
242    }
243
244    subsystem_name = "developtools"
245    part_name = "hdc"
246  }
247
248  if (image_name == "system") {
249    if (product_name != "ohos-sdk" || is_emulator) {
250      ohos_executable("hdcd_${image_name}_exe") {
251        sanitize = {
252          cfi = true
253          cfi_cross_dso = true
254          cfi_vcall_icall_only = true
255          debug = false
256        }
257        deps = [ ":hdcd_${image_name}_source" ]
258        external_deps = [ "hilog:libhilog" ]
259        output_name = "hdcd_${image_name}"
260        install_enable = false
261        subsystem_name = "developtools"
262        part_name = "hdc"
263      }
264    } else {
265      ohos_rust_executable("hdcd_${image_name}_exe") {
266        sources = [ "hdc_rust/src/daemon/main.rs" ]
267        if (use_clang_coverage) {
268          rustflags = [
269            "-C",
270            "instrument-coverage",
271            "-Clink-arg=--coverage",
272          ]
273        }
274        rustflags = [ "-Cforce-frame-pointers=yes" ]
275        deps = [
276          "//third_party/rust/crates/env_logger:lib",
277          "//third_party/rust/crates/humantime:lib",
278          "//third_party/rust/crates/libc:lib",
279          "//third_party/rust/crates/log:lib",
280          "//third_party/rust/crates/nix:lib",
281        ]
282        external_deps = [
283          "hilog:hilog_rust",
284          "rust_rust-openssl:lib",
285        ]
286
287        if (product_name != "ohos-sdk") {
288          deps += [
289            ":lib",
290            ":serialize_structs",
291          ]
292          external_deps += [ "ylong_runtime:ylong_runtime" ]
293        }
294
295        if (!defined(ohos_lite)) {
296          external_deps += [ "faultloggerd:panic_handler" ]
297        }
298
299        output_name = "hdcd_${image_name}"
300        install_enable = false
301        features = [ "daemon" ]
302        if (is_emulator) {
303          features += [ "emulator" ]
304        }
305        rust_static_link = true
306        subsystem_name = "developtools"
307        part_name = "hdc"
308      }
309    }
310  } else {
311    ohos_executable("hdcd_${image_name}_exe") {
312      sanitize = {
313        cfi = true
314        cfi_cross_dso = true
315        cfi_vcall_icall_only = true
316        debug = false
317      }
318      deps = [ ":hdcd_${image_name}_source" ]
319      external_deps = [ "hilog:libhilog" ]
320      output_name = "hdcd_${image_name}"
321      install_enable = false
322      subsystem_name = "developtools"
323      part_name = "hdc"
324    }
325  }
326
327  ohos_prebuilt_executable("hdcd_${image_name}") {
328    deps = [ ":hdcd_${image_name}_exe" ]
329    output = "${image_name}/hdcd"
330    install_enable = true
331    subsystem_name = "developtools"
332    part_name = "hdc"
333    source = "${root_out_dir}/${subsystem_name}/${part_name}/hdcd_${image_name}"
334    module_install_dir = "bin"
335    install_images = []
336    if (image_name == "updater") {
337      install_images = [ "updater" ]
338    } else {
339      install_images = [ "system" ]
340    }
341  }
342}
343
344build_hdc("system") {
345}
346
347build_hdc("updater") {
348}
349
350ohos_executable("hdc") {
351  use_exceptions = true
352  ldflags = []
353  libs = []
354  configs = [ ":hdc_config" ]
355  defines = [
356    "HDC_HOST",
357    "HARMONY_PROJECT",
358    "USE_CONFIG_UV_THREADS",
359    "SIZE_THREAD_POOL=$hdc_uv_thread_size",
360    "OPENSSL_SUPPRESS_DEPRECATED",
361  ]
362  if (is_mac) {
363    defines += [ "HOST_MAC" ]
364  }
365  if (hdc_debug) {
366    defines += [ "HDC_DEBUG" ]
367  }
368  sources = [
369    "src/host/client.cpp",
370    "src/host/ext_client.cpp",
371    "src/host/host_app.cpp",
372    "src/host/host_forward.cpp",
373    "src/host/host_shell_option.cpp",
374    "src/host/host_tcp.cpp",
375    "src/host/host_unity.cpp",
376    "src/host/host_updater.cpp",
377    "src/host/host_usb.cpp",
378    "src/host/main.cpp",
379    "src/host/server.cpp",
380    "src/host/server_for_client.cpp",
381    "src/host/translate.cpp",
382  ]
383  sources += hdc_common_sources
384  if (hdc_support_uart) {
385    defines += [ "HDC_SUPPORT_UART" ]
386    sources += [ "src/host/host_uart.cpp" ]
387  }
388
389  deps = []
390
391  external_deps = [
392    "bounds_checking_function:libsec_static",
393    "libusb:libusb",
394    "libuv:uv_static",
395    "lz4:liblz4_static",
396    "openssl:libcrypto_static",
397  ]
398
399  deps += [ ":hdc_hash_gen" ]
400
401  if (!(is_mingw || is_mac) && build_selinux) {
402    external_deps += [ "selinux:libselinux" ]
403    defines += [ "SURPPORT_SELINUX" ]
404  }
405
406  if (hdc_version_check) {
407    defines += [ "HDC_VERSION_CHECK" ]
408  }
409
410  if (is_mingw) {
411    static_link = false
412
413    # we should use something we define , not just _WIN32 (this will defined in some windows header)
414    defines += [ "HOST_MINGW" ]  # we define this for mingw
415    defines += [ "WIN32_LEAN_AND_MEAN" ]
416    libs += [ "setupapi" ]
417    ldflags += [
418      "-Wl,--whole-archive",
419      "-lpthread",
420      "-Wl,--no-whole-archive",
421    ]
422  }
423
424  if (is_linux) {
425    static_link = false
426    defines += [ "HOST_LINUX" ]
427    ldflags += [
428      "-Wl,--whole-archive",
429      "-lpthread",
430      "-latomic",
431      "-ldl",
432      "-lrt",
433      "-Wl,--no-whole-archive",
434    ]
435  }
436
437  subsystem_name = "developtools"
438  part_name = "hdc"
439}
440
441group("hdc_target") {
442  deps = [
443    ":hdc",
444    ":hdc_register",
445    ":hdcd_system",
446    ":hdcd_updater",
447  ]
448}
449
450group("hdc_target_all") {
451  deps = [ ":hdc_target" ]
452}
453
454group("hdc_all") {
455  testonly = true
456  deps = [ ":hdc_target_all" ]
457}
458
459group("hdc_test_target") {
460  testonly = true
461  deps = [ "test:hdc_fuzztest" ]
462}
463
464action("hdc_hash_gen") {
465  script = "scripts/hdc_hash_gen.py"
466  sources = hash_sources
467  outputs = [ "$py_out_dir" ]
468  args = [
469    "-f",
470    "hdc_hash_gen.h",
471    "-i",
472    rebase_path(".", root_build_dir),
473    "-o",
474    rebase_path("$py_out_dir" + "/", root_build_dir),
475  ]
476  public_configs = [ ":hdc_config" ]
477}
478
479config("hdc_register_config") {
480  cflags_cc = [
481    "-fexceptions",
482    "-fno-complete-member-pointers",
483    "-Wno-implicit-fallthrough",
484    "-fvisibility=default",
485    "-frtti",
486    "-std=c++17",
487  ]
488}
489
490ohos_shared_library("hdc_register") {
491  deps = []
492  defines = [
493    "JS_JDWP_CONNECT",
494    "HDC_HILOG",
495  ]
496
497  external_deps = [
498    "bounds_checking_function:libsec_shared",
499    "c_utils:utils",
500    "hilog:libhilog",
501    "init:libbeget_proxy",
502    "init:libbegetutil",
503    "libuv:uv",
504  ]
505
506  sources = [
507    "src/register/hdc_connect.cpp",
508    "src/register/hdc_jdwp.cpp",
509  ]
510
511  configs = [ ":hdc_register_config" ]
512
513  innerapi_tags = [ "platformsdk" ]
514  subsystem_name = "developtools"
515  part_name = "hdc"
516}
517
518config("hdc_updater_config") {
519  include_dirs = [
520    "src/common",
521    "src/daemon",
522  ]
523}
524
525ohos_static_library("hdc_updater") {
526  sources = []
527  deps = []
528  defines = []
529
530  public_configs = [ ":hdc_updater_config" ]
531  subsystem_name = "developtools"
532  part_name = "hdc"
533}
534