BUILD.gn 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. # Copyright (c) 2020 Project CHIP Authors
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import("//build_overrides/build.gni")
  15. import("//build_overrides/chip.gni")
  16. import("//build_overrides/pigweed.gni")
  17. import("$dir_pw_build/python.gni")
  18. import("${chip_root}/build/chip/tools.gni")
  19. import("${chip_root}/src/platform/python.gni")
  20. import("${dir_pw_unit_test}/test.gni")
  21. if (current_os == "mac") {
  22. import("${build_root}/config/mac/mac_sdk.gni")
  23. }
  24. config("controller_wno_deprecate") {
  25. cflags = [ "-Wno-deprecated-declarations" ]
  26. }
  27. declare_args() {
  28. chip_python_version = "0.0"
  29. chip_python_package_prefix = "chip"
  30. }
  31. shared_library("ChipDeviceCtrl") {
  32. if (chip_controller) {
  33. output_name = "_ChipDeviceCtrl"
  34. } else {
  35. output_name = "_ChipServer"
  36. }
  37. output_dir = "${target_out_dir}/chip"
  38. include_dirs = [ "." ]
  39. sources = [
  40. "chip/setup_payload/Generator.cpp",
  41. "chip/setup_payload/Parser.cpp",
  42. ]
  43. sources += [ "chip/native/CommonStackInit.cpp" ]
  44. defines = []
  45. if (chip_controller) {
  46. sources += [
  47. "ChipCommissionableNodeController-ScriptBinding.cpp",
  48. "ChipDeviceController-Discovery.cpp",
  49. "ChipDeviceController-IssueNocChain.cpp",
  50. "ChipDeviceController-ScriptBinding.cpp",
  51. "ChipDeviceController-ScriptDevicePairingDelegate.cpp",
  52. "ChipDeviceController-ScriptDevicePairingDelegate.h",
  53. "ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.cpp",
  54. "ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.h",
  55. "ChipDeviceController-StorageDelegate.cpp",
  56. "ChipDeviceController-StorageDelegate.h",
  57. "OpCredsBinding.cpp",
  58. "chip/clusters/attribute.cpp",
  59. "chip/clusters/command.cpp",
  60. "chip/credentials/cert.cpp",
  61. "chip/crypto/p256keypair.cpp",
  62. "chip/discovery/NodeResolution.cpp",
  63. "chip/interaction_model/Delegate.cpp",
  64. "chip/interaction_model/Delegate.h",
  65. "chip/internal/ChipThreadWork.cpp",
  66. "chip/internal/ChipThreadWork.h",
  67. "chip/internal/CommissionerImpl.cpp",
  68. "chip/logging/LoggingRedirect.cpp",
  69. "chip/native/PyChipError.cpp",
  70. "chip/utils/DeviceProxyUtils.cpp",
  71. ]
  72. defines += [ "CHIP_CONFIG_MAX_GROUPS_PER_FABRIC=50" ]
  73. defines += [ "CHIP_CONFIG_MAX_GROUP_KEYS_PER_FABRIC=50" ]
  74. } else {
  75. sources += [
  76. "chip/server/Options.cpp",
  77. "chip/server/ServerInit.cpp",
  78. ]
  79. }
  80. if (chip_enable_ble) {
  81. if (current_os == "linux") {
  82. sources += [ "chip/ble/LinuxImpl.cpp" ]
  83. } else if (current_os == "mac") {
  84. sources += [
  85. "chip/ble/darwin/AdapterListing.mm",
  86. "chip/ble/darwin/Scanning.mm",
  87. ]
  88. cflags = [ "-fobjc-arc" ]
  89. } else {
  90. assert(false, "No BLE implementation available for the current OS.")
  91. }
  92. }
  93. public_deps = [
  94. "${chip_root}/src/app",
  95. "${chip_root}/src/app/server",
  96. "${chip_root}/src/credentials:default_attestation_verifier",
  97. "${chip_root}/src/lib",
  98. "${chip_root}/src/lib/core",
  99. "${chip_root}/src/lib/dnssd",
  100. "${chip_root}/src/lib/support",
  101. "${chip_root}/src/platform",
  102. "${chip_root}/src/setup_payload",
  103. "${chip_root}/src/transport",
  104. ]
  105. if (chip_controller) {
  106. public_deps += [
  107. "${chip_root}/src/controller/data_model",
  108. "${chip_root}/src/credentials:file_attestation_trust_store",
  109. "${chip_root}/third_party/jsoncpp",
  110. ]
  111. } else {
  112. public_deps += [ "$chip_data_model" ]
  113. }
  114. configs += [ ":controller_wno_deprecate" ]
  115. }
  116. template("chip_python_wheel_action") {
  117. _dist_dir = "${root_out_dir}/controller/python"
  118. _py_manifest_file = "${target_gen_dir}/${target_name}.py_manifest.json"
  119. pw_python_action(target_name) {
  120. script = "build-chip-wheel.py"
  121. forward_variables_from(invoker, "*")
  122. _py_manifest_files_rebased = []
  123. foreach(_manifest_entry, py_manifest_files) {
  124. inputs += _manifest_entry.sources
  125. _py_manifest_files_rebased += [
  126. {
  127. src_dir = rebase_path(_manifest_entry.src_dir,
  128. get_path_info(_py_manifest_file, "dir"))
  129. sources =
  130. rebase_path(_manifest_entry.sources, _manifest_entry.src_dir)
  131. },
  132. ]
  133. }
  134. if (defined(invoker.py_scripts)) {
  135. _py_scripts = invoker.py_scripts
  136. } else {
  137. _py_scripts = []
  138. }
  139. _py_manifest = {
  140. files = _py_manifest_files_rebased
  141. packages = py_packages
  142. scripts = _py_scripts
  143. package_reqs = py_package_reqs
  144. }
  145. write_file(_py_manifest_file, _py_manifest, "json")
  146. args = [
  147. "--package_name",
  148. py_package_name,
  149. "--build_number",
  150. chip_python_version,
  151. "--build_dir",
  152. rebase_path("${target_gen_dir}/${target_name}.py_build", root_build_dir),
  153. "--dist_dir",
  154. rebase_path(_dist_dir, root_build_dir),
  155. "--manifest",
  156. rebase_path(_py_manifest_file, root_build_dir),
  157. "--plat-name",
  158. py_platform_tag,
  159. ]
  160. if (defined(invoker.lib_name)) {
  161. args += [
  162. "--lib-name",
  163. lib_name,
  164. ]
  165. }
  166. outputs = [ "${_dist_dir}/$output_name" ]
  167. }
  168. }
  169. chip_python_wheel_action("chip-core") {
  170. py_manifest_files = [
  171. {
  172. src_dir = "."
  173. sources = [
  174. "chip/CertificateAuthority.py",
  175. "chip/ChipBleBase.py",
  176. "chip/ChipBleUtility.py",
  177. "chip/ChipBluezMgr.py",
  178. "chip/ChipCommissionableNodeCtrl.py",
  179. "chip/ChipStack.py",
  180. "chip/FabricAdmin.py",
  181. "chip/__init__.py",
  182. "chip/ble/__init__.py",
  183. "chip/ble/commissioning/__init__.py",
  184. "chip/ble/get_adapters.py",
  185. "chip/ble/library_handle.py",
  186. "chip/ble/scan_devices.py",
  187. "chip/ble/types.py",
  188. "chip/clusters/Attribute.py",
  189. "chip/clusters/Command.py",
  190. "chip/clusters/__init__.py",
  191. "chip/commissioning/__init__.py",
  192. "chip/commissioning/commissioning_flow_blocks.py",
  193. "chip/commissioning/pase.py",
  194. "chip/configuration/__init__.py",
  195. "chip/credentials/cert.py",
  196. "chip/crypto/fabric.py",
  197. "chip/crypto/p256keypair.py",
  198. "chip/discovery/__init__.py",
  199. "chip/discovery/library_handle.py",
  200. "chip/discovery/types.py",
  201. "chip/exceptions/__init__.py",
  202. "chip/interaction_model/__init__.py",
  203. "chip/interaction_model/delegate.py",
  204. "chip/internal/__init__.py",
  205. "chip/internal/commissioner.py",
  206. "chip/internal/thread.py",
  207. "chip/internal/types.py",
  208. "chip/logging/__init__.py",
  209. "chip/logging/library_handle.py",
  210. "chip/logging/types.py",
  211. "chip/native/__init__.py",
  212. "chip/setup_payload/__init__.py",
  213. "chip/setup_payload/setup_payload.py",
  214. "chip/storage/__init__.py",
  215. "chip/utils/CommissioningBuildingBlocks.py",
  216. "chip/utils/__init__.py",
  217. "chip/yaml/__init__.py",
  218. "chip/yaml/data_model_lookup.py",
  219. "chip/yaml/errors.py",
  220. "chip/yaml/format_converter.py",
  221. "chip/yaml/runner.py",
  222. ]
  223. if (chip_controller) {
  224. sources += [ "chip/ChipDeviceCtrl.py" ]
  225. } else {
  226. sources += [
  227. "chip/server/__init__.py",
  228. "chip/server/types.py",
  229. ]
  230. }
  231. },
  232. {
  233. src_dir = target_out_dir
  234. if (chip_controller) {
  235. sources = [ "${target_out_dir}/chip/_ChipDeviceCtrl.so" ]
  236. } else {
  237. sources = [ "${target_out_dir}/chip/_ChipServer.so" ]
  238. }
  239. },
  240. {
  241. src_dir = "//"
  242. sources = [ "//LICENSE" ]
  243. },
  244. ]
  245. inputs = []
  246. py_packages = [
  247. "chip",
  248. "chip.ble",
  249. "chip.ble.commissioning",
  250. "chip.configuration",
  251. "chip.commissioning",
  252. "chip.clusters",
  253. "chip.credentials",
  254. "chip.crypto",
  255. "chip.utils",
  256. "chip.discovery",
  257. "chip.exceptions",
  258. "chip.internal",
  259. "chip.interaction_model",
  260. "chip.logging",
  261. "chip.yaml",
  262. "chip.native",
  263. "chip.clusters",
  264. "chip.setup_payload",
  265. "chip.storage",
  266. ]
  267. if (!chip_controller) {
  268. py_packages += [ "chip.server" ]
  269. }
  270. py_package_reqs = [
  271. "coloredlogs",
  272. "construct",
  273. "dacite",
  274. "rich",
  275. "pyyaml",
  276. "ipdb",
  277. "deprecation",
  278. "cryptography",
  279. "ecdsa",
  280. ]
  281. if (current_cpu == "x64") {
  282. cpu_tag = "x86_64"
  283. } else if (current_cpu == "arm64" && current_os == "linux") {
  284. cpu_tag = "aarch64"
  285. } else if (current_cpu == "arm" && current_os == "linux") {
  286. cpu_tag = "armv7l"
  287. } else {
  288. cpu_tag = current_cpu
  289. }
  290. if (current_os == "mac") {
  291. py_platform_tag = string_replace(
  292. string_replace(mac_deployment_target, "macos", "macosx."),
  293. ".",
  294. "_")
  295. } else {
  296. py_platform_tag = current_os
  297. }
  298. py_platform_tag = py_platform_tag + "_" + cpu_tag
  299. tags = "cp37-abi3-" + py_platform_tag
  300. if (chip_controller) {
  301. lib_name = "_ChipDeviceCtrl.so"
  302. } else {
  303. lib_name = "_ChipServer.so"
  304. }
  305. py_package_name = "${chip_python_package_prefix}-core"
  306. py_package_output = string_replace(py_package_name, "-", "_")
  307. public_deps = [ ":ChipDeviceCtrl" ]
  308. output_name = "${py_package_output}-${chip_python_version}-${tags}.whl"
  309. }
  310. chip_python_wheel_action("chip-clusters") {
  311. py_manifest_files = [
  312. {
  313. src_dir = "."
  314. sources = [
  315. "chip/ChipUtility.py",
  316. "chip/clusters/CHIPClusters.py",
  317. "chip/clusters/ClusterObjects.py",
  318. "chip/clusters/Objects.py",
  319. "chip/clusters/TestObjects.py",
  320. "chip/clusters/Types.py",
  321. "chip/clusters/enum.py",
  322. "chip/tlv/__init__.py",
  323. ]
  324. },
  325. {
  326. src_dir = "//"
  327. sources = [ "//LICENSE" ]
  328. },
  329. ]
  330. inputs = []
  331. py_packages = [
  332. "chip",
  333. "chip.clusters",
  334. "chip.tlv",
  335. ]
  336. py_package_reqs = [
  337. "dacite",
  338. "aenum",
  339. ]
  340. py_package_name = "${chip_python_package_prefix}-clusters"
  341. py_package_output = string_replace(py_package_name, "-", "_")
  342. py_platform_tag = "any"
  343. output_name = "${py_package_output}-${chip_python_version}-py3-none-any.whl"
  344. }
  345. chip_python_wheel_action("chip-repl") {
  346. py_scripts = [
  347. "chip-device-ctrl.py",
  348. "chip-repl.py",
  349. ]
  350. py_manifest_files = [
  351. {
  352. src_dir = "."
  353. sources = [
  354. "chip/ChipBluezMgr.py",
  355. "chip/ChipCoreBluetoothMgr.py",
  356. "chip/ChipReplStartup.py",
  357. ]
  358. sources += py_scripts
  359. },
  360. {
  361. src_dir = "//"
  362. sources = [ "//LICENSE" ]
  363. },
  364. ]
  365. inputs = []
  366. py_packages = [ "chip" ]
  367. py_package_reqs = [
  368. "coloredlogs",
  369. #
  370. # IPython 7.30.0 has a bug which results in the use of await ... failing on some platforms (see https://github.com/ipython/ipython/pull/13269)
  371. # For now, let's just avoid that version.
  372. #
  373. # IPython 8.1.0 has a bug which causes issues: https://github.com/ipython/ipython/issues/13554
  374. #
  375. #
  376. "ipython!=8.1.0",
  377. "rich",
  378. "ipykernel",
  379. ]
  380. if (current_os == "mac") {
  381. py_package_reqs += [ "pyobjc-framework-corebluetooth" ]
  382. } else if (current_os == "linux") {
  383. py_package_reqs += [
  384. "dbus-python==1.2.18",
  385. "pygobject",
  386. ]
  387. }
  388. py_package_name = "${chip_python_package_prefix}-repl"
  389. py_package_output = string_replace(py_package_name, "-", "_")
  390. py_platform_tag = "any"
  391. data_deps = [
  392. ":chip-clusters",
  393. ":chip-core",
  394. ]
  395. output_name = "${py_package_output}-${chip_python_version}-py3-none-any.whl"
  396. }