Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / controller / python / BUILD.gn
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
15 import("//build_overrides/build.gni")
16 import("//build_overrides/chip.gni")
17 import("//build_overrides/pigweed.gni")
18
19 import("$dir_pw_build/python.gni")
20
21 import("${chip_root}/build/chip/tools.gni")
22 import("${chip_root}/src/platform/device.gni")
23 import("${dir_pw_unit_test}/test.gni")
24
25 if (current_os == "mac") {
26   import("${build_root}/config/mac/mac_sdk.gni")
27 }
28
29 config("controller_wno_deprecate") {
30   cflags = [ "-Wno-deprecated-declarations" ]
31 }
32
33 shared_library("ChipDeviceCtrl") {
34   output_name = "_ChipDeviceCtrl"
35   output_dir = "${target_out_dir}/chip"
36   include_dirs = [ "." ]
37
38   sources = [
39     "ChipDeviceController-ScriptBinding.cpp",
40     "ChipDeviceController-ScriptDeviceAddressUpdateDelegate.cpp",
41     "ChipDeviceController-ScriptDeviceAddressUpdateDelegate.h",
42     "ChipDeviceController-ScriptDevicePairingDelegate.cpp",
43     "ChipDeviceController-ScriptDevicePairingDelegate.h",
44     "ChipDeviceController-StorageDelegate.cpp",
45     "ChipDeviceController-StorageDelegate.h",
46     "chip/clusters/CHIPClusters.cpp",
47     "chip/internal/ChipThreadWork.cpp",
48     "chip/internal/ChipThreadWork.h",
49     "chip/internal/CommissionerImpl.cpp",
50     "chip/logging/LoggingRedirect.cpp",
51     "chip/native/StackInit.cpp",
52   ]
53
54   if (chip_enable_ble) {
55     if (current_os == "linux") {
56       sources += [ "chip/ble/LinuxImpl.cpp" ]
57     } else if (current_os == "mac") {
58       sources += [
59         "chip/ble/darwin/AdapterListing.mm",
60         "chip/ble/darwin/Scanning.mm",
61       ]
62     } else {
63       assert(false, "No BLE implementation available for the current OS.")
64     }
65   }
66
67   public_deps = [
68     "${chip_root}/src/app",
69     "${chip_root}/src/controller",
70     "${chip_root}/src/lib",
71     "${chip_root}/src/lib/core",
72     "${chip_root}/src/lib/support",
73     "${chip_root}/src/platform",
74     "${chip_root}/src/transport",
75   ]
76   allow_circular_includes_from = [ "${chip_root}/src/controller" ]
77   configs += [ ":controller_wno_deprecate" ]
78 }
79
80 pw_python_action("python") {
81   script = "build-chip-wheel.py"
82
83   _py_manifest_files = [
84     {
85       src_dir = "."
86       sources = [
87         "chip-device-ctrl.py",
88         "chip-repl.py",
89         "chip/ChipBleBase.py",
90         "chip/ChipBleUtility.py",
91         "chip/ChipBluezMgr.py",
92         "chip/ChipCoreBluetoothMgr.py",
93         "chip/ChipDeviceCtrl.py",
94         "chip/ChipStack.py",
95         "chip/ChipUtility.py",
96         "chip/__init__.py",
97         "chip/ble/__init__.py",
98         "chip/ble/commissioning/__init__.py",
99         "chip/ble/get_adapters.py",
100         "chip/ble/library_handle.py",
101         "chip/ble/scan_devices.py",
102         "chip/ble/types.py",
103         "chip/clusters/CHIPClusters.py",
104         "chip/clusters/__init__.py",
105         "chip/configuration/__init__.py",
106         "chip/exceptions/__init__.py",
107         "chip/internal/__init__.py",
108         "chip/internal/commissioner.py",
109         "chip/internal/thread.py",
110         "chip/internal/types.py",
111         "chip/logging/__init__.py",
112         "chip/logging/library_handle.py",
113         "chip/logging/types.py",
114         "chip/native/__init__.py",
115         "chip/tlv/__init__.py",
116       ]
117     },
118     {
119       src_dir = target_out_dir
120       sources = [ "${target_out_dir}/chip/_ChipDeviceCtrl.so" ]
121     },
122     {
123       src_dir = "//"
124       sources = [ "//LICENSE" ]
125     },
126   ]
127
128   _py_manifest_file = "${target_gen_dir}/${target_name}.py_manifest.json"
129
130   inputs = []
131   _py_manifest_files_rebased = []
132   foreach(_manifest_entry, _py_manifest_files) {
133     inputs += _manifest_entry.sources
134     _py_manifest_files_rebased += [
135       {
136         src_dir = rebase_path(_manifest_entry.src_dir,
137                               get_path_info(_py_manifest_file, "dir"))
138         sources = rebase_path(_manifest_entry.sources, _manifest_entry.src_dir)
139       },
140     ]
141   }
142
143   _py_manifest = {
144     files = _py_manifest_files_rebased
145   }
146
147   write_file(_py_manifest_file, _py_manifest, "json")
148
149   _dist_dir = "${root_out_dir}/controller/python"
150
151   if (current_cpu == "x64") {
152     cpu_tag = "x86_64"
153   } else if (current_cpu == "arm64") {
154     cpu_tag = "aarch64"
155   } else {
156     cpu_tag = current_cpu
157   }
158
159   if (current_os == "mac") {
160     platform_tag = "macosx_" + string_replace(mac_deployment_target, ".", "_")
161   } else {
162     platform_tag = current_os
163   }
164
165   platform_tag = platform_tag + "_" + cpu_tag
166
167   tags = "cp37-abi3-" + platform_tag
168
169   args = [
170     "--package_name",
171     "chip",
172     "--build_number",
173     "0.0",
174     "--build_dir",
175     rebase_path("${target_gen_dir}/${target_name}.py_build", root_build_dir),
176     "--dist_dir",
177     rebase_path(_dist_dir, root_build_dir),
178     "--manifest",
179     rebase_path(_py_manifest_file, root_build_dir),
180     "--plat-name",
181     platform_tag,
182   ]
183
184   public_deps = [ ":ChipDeviceCtrl" ]
185
186   output_name = "chip-0.0-${tags}.whl"
187   outputs = [ "${_dist_dir}/$output_name" ]
188 }