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