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