xref: /developtools/hdc/hdc_rust/BUILD.gn (revision cc290419)
1# Copyright (C) 2023 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")
15
16ohos_static_library("serialize_structs") {
17  sources = [
18    "src/cffi/bridge.cpp",
19    "src/cffi/cmd.cpp",
20    "src/cffi/getparameter.cpp",
21    "src/cffi/log.cpp",
22    "src/cffi/mount.cpp",
23    "src/cffi/mount_wrapper.cpp",
24    "src/cffi/oh_usb.cpp",
25    "src/cffi/sendmsg.cpp",
26    "src/cffi/serial_struct.cpp",
27    "src/cffi/sys_para.cpp",
28    "src/cffi/transfer.cpp",
29    "src/cffi/uart.cpp",
30    "src/cffi/uart_wrapper.cpp",
31    "src/cffi/usb_util.cpp",
32    "src/cffi/usb_wrapper.cpp",
33    "src/cffi/utils.cpp",
34  ]
35
36  external_deps = [
37    "bounds_checking_function:libsec_static",
38    "hilog:libhilog",
39    "init:libbegetutil",
40    "lz4:liblz4_static",
41  ]
42
43  defines = [ "HDC_HILOG" ]
44
45  if (is_mac) {
46    defines = [ "HOST_MAC" ]
47  }
48
49  if (build_selinux) {
50    external_deps += [ "selinux:libselinux" ]
51    defines += [ "SURPPORT_SELINUX" ]
52  }
53
54  subsystem_name = "developtools"
55  part_name = "hdc"
56}
57
58ohos_rust_executable("hdcd") {
59  sources = [ "src/daemon/main.rs" ]
60  deps = [
61    ":serialize_structs",
62    "//third_party/rust/crates/env_logger:lib",
63    "//third_party/rust/crates/humantime:lib",
64    "//third_party/rust/crates/libc:lib",
65    "//third_party/rust/crates/log:lib",
66    "//third_party/rust/crates/nix:lib",
67    "//third_party/rust/crates/rust-openssl/openssl:lib",
68  ]
69  external_deps = [
70    "hilog:hilog_rust",
71    "ylong_runtime:ylong_runtime",
72  ]
73
74  if (!defined(ohos_lite)) {
75    external_deps += [ "faultloggerd:panic_handler" ]
76  }
77
78  output_name = "hdcd"
79  install_enable = true
80  module_install_dir = "bin"
81  install_images = [ "system" ]
82  features = [ "daemon" ]
83  if (is_emulator) {
84    features += [ "emulator" ]
85  }
86  subsystem_name = "developtools"
87  part_name = "hdc"
88}
89
90# hdc_rust compile begin
91ohos_static_library("cffi_host") {
92  sources = [
93    "src/cffi/host/ctimer.cpp",
94    "src/cffi/host/host_usb.cpp",
95    "src/cffi/host/host_usb_wrapper.cpp",
96    "src/cffi/serial_struct.cpp",
97    "src/cffi/transfer.cpp",
98    "src/cffi/uart.cpp",
99    "src/cffi/uart_wrapper.cpp",
100    "src/cffi/usb_util.cpp",
101    "src/cffi/utils.cpp",
102  ]
103
104  if (!is_mingw) {
105    sources += [
106      "src/cffi/oh_usb.cpp",
107      "src/cffi/sendmsg.cpp",
108      "src/cffi/usb_wrapper.cpp",
109    ]
110  }
111
112  include_dirs = [
113    "//third_party/bounds_checking_function/include",
114    "//third_party/lz4/lib",
115    "src/cffi",
116  ]
117
118  external_deps = [
119    "bounds_checking_function:libsec_static",
120    "libusb:libusb",
121    "lz4:liblz4_static",
122  ]
123
124  defines = [ "HDC_HOST" ]
125  if (is_mingw) {
126    defines += [ "HOST_MINGW" ]
127  }
128
129  if (is_mac) {
130    defines = [ "HOST_MAC" ]
131  }
132
133  cflags = [ "-std=c++17" ]
134
135  subsystem_name = "developtools"
136  part_name = "hdc"
137}
138
139ohos_static_library("hdc_win_dep") {
140  sources = [ "src/cffi/win_dep.cpp" ]
141  include_dirs = [ "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32/include" ]
142
143  subsystem_name = "developtools"
144  part_name = "hdc"
145}
146
147ohos_rust_static_library("hdc_library_host") {
148  crate_name = "hdc"
149  crate_type = "rlib"
150  crate_root = "src/lib.rs"
151  sources = [ "src/lib.rs" ]
152
153  deps = [
154    ":cffi_host",
155    "//third_party/rust/crates/humantime:lib",
156    "//third_party/rust/crates/libc:lib",
157    "//third_party/rust/crates/log:lib",
158    "//third_party/rust/crates/rust-openssl/openssl:lib",
159  ]
160  external_deps = [ "ylong_runtime:ylong_runtime_static" ]
161
162  features = [ "host" ]
163
164  subsystem_name = "developtools"
165  part_name = "hdc"
166}
167
168ohos_rust_executable("hdc_rust") {
169  sources = [ "src/host/main.rs" ]
170  deps = [
171    ":cffi_host",
172    ":hdc_library_host",
173    "//third_party/rust/crates/humantime:lib",
174    "//third_party/rust/crates/lazy-static.rs:lib",
175    "//third_party/rust/crates/libc:lib",
176    "//third_party/rust/crates/log:lib",
177    "//third_party/rust/crates/rust-openssl/openssl:lib",
178  ]
179
180  if (is_mingw) {
181    deps += [ ":hdc_win_dep" ]
182  }
183
184  # config to link libc++.a
185  rust_static_link = true
186
187  external_deps = [ "ylong_runtime:ylong_runtime_static" ]
188
189  features = [ "host" ]
190  subsystem_name = "developtools"
191  part_name = "hdc"
192}
193