-
Notifications
You must be signed in to change notification settings - Fork 251
Expand file tree
/
Copy pathcommon_settings.bzl
More file actions
267 lines (256 loc) · 9.08 KB
/
common_settings.bzl
File metadata and controls
267 lines (256 loc) · 9.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#
# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###############################
# bazel config settings
###############################
#To build without mediapipe use flags - bazel build --config=linux --define MEDIAPIPE_DISABLE=1 --cxxopt=-DMEDIAPIPE_DISABLE=1 //src:ovms
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@mediapipe//mediapipe/framework:more_selects.bzl", "more_selects")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("//:distro.bzl", "distro_flag")
# cc_library rule wrapper that will accept the same arguments but if user will not provide
# copts, linkopts, local_defines it will set them to the defaults
# COMMON_STATIC_LIBS_COPTS & COMMON_STATIC_LIBS_LINKOPTS
def ovms_cc_library(**kwargs):
"""
Wrapper for cc_library that sets default copts and linkopts if not provided.
"""
if "copts" not in kwargs:
kwargs["copts"] = COMMON_STATIC_LIBS_COPTS + select({
"//conditions:default": [],
"//:fuzzer_build": COMMON_FUZZER_COPTS,
})
if "linkopts" not in kwargs:
kwargs["linkopts"] = COMMON_STATIC_LIBS_LINKOPTS + select({
"//conditions:default": [],
"//:fuzzer_build": COMMON_FUZZER_LINKOPTS,
})
if "local_defines" not in kwargs:
kwargs["local_defines"] = COMMON_LOCAL_DEFINES
if "additional_copts" in kwargs:
kwargs["copts"] += kwargs.pop("additional_copts")
if "additional_linkopts" in kwargs:
kwargs["linkopts"] += kwargs.pop("additional_linkopts")
native.cc_library(
**kwargs
)
def create_config_settings():
distro_flag()
native.config_setting(
name = "disable_mediapipe",
define_values = {
"MEDIAPIPE_DISABLE": "1",
},
visibility = ["//visibility:public"],
)
more_selects.config_setting_negation(
name = "not_disable_mediapipe",
negate = ":disable_mediapipe",
)
native.config_setting(
name = "enable_drogon",
define_values = {
"USE_DROGON": "1",
},
visibility = ["//visibility:public"],
)
more_selects.config_setting_negation(
name = "enable_net_http",
negate = ":enable_drogon",
)
native.config_setting(
name = "disable_cloud",
define_values = {
"CLOUD_DISABLE": "1",
},
visibility = ["//visibility:public"],
)
more_selects.config_setting_negation(
name = "not_disable_cloud",
negate = ":disable_cloud",
)
#To build without python use flags - bazel build --config=linux --define PYTHON_DISABLE=1 //src:ovms
native.config_setting(
name = "disable_python",
define_values = {
"PYTHON_DISABLE": "1",
},
visibility = ["//visibility:public"],
)
more_selects.config_setting_negation(
name = "not_disable_python",
negate = ":disable_python",
)
native.config_setting(
name = "disable_ov_trace",
define_values = {
"OV_TRACE": "0",
},
visibility = ["//visibility:public"],
)
more_selects.config_setting_negation(
name = "not_disable_ov_trace",
negate = ":disable_ov_trace",
)
native.config_setting(
name = "fuzzer_build",
define_values = {
"FUZZER_BUILD": "1",
},
visibility = ["//visibility:public"],
)
more_selects.config_setting_negation(
name = "not_fuzzer_build",
negate = ":fuzzer_build",
)
# is windows or mediapipe is disabled (no_http dependency)
selects.config_setting_group(
name = "is_windows_or_mediapipe_is_disabled_no_http",
match_any = ["//src:windows", "//:disable_mediapipe"]
)
# is windows or python is disabled"(no llm dependency)
selects.config_setting_group(
name = "is_windows_or_python_is_disabled_no_llm",
match_any = ["//src:windows", "//:disable_python"]
)
# is windows and python is enabled"
selects.config_setting_group(
name = "is_windows_and_python_is_enabled",
match_all = ["//src:windows", "//:not_disable_python"]
)
###############################
# compilation settings
###############################
LINUX_COMMON_STATIC_LIBS_COPTS = [
"-Wall",
# "-Wextra", Requires more cleanup in code
# TODO: was in ovms bin "-Wconversion",
"-Wno-unknown-pragmas",
"-Wno-sign-compare",
"-fvisibility=hidden", # Needed for pybind targets
"-Werror",
# ov::Tensor::data method call results in deprecated warning and we use it in multiple places
"-Wno-deprecated-declarations",
"-Werror",
"-Wimplicit-fallthrough",
"-fcf-protection=full",
"-Wformat",
"-Wformat-security",
"-Werror=format-security",
"-Wl,-z,noexecstack",
"-fPIC",
#"-D_GLIBCXX_ASSERTIONS", - causes errors on gpu
"-Wl,-z,relro,-z,now",
"-Wl,-z,nodlopen",
"-fstack-protector-strong",
]
WINDOWS_COMMON_STATIC_LIBS_COPTS = [
"/guard:cf",
"/W4",
"/WX",
"/external:anglebrackets",
"/external:W0",
"/sdl",
"/analyze",
"/Gy",
"/GS",
"/DYNAMICBASE",
"/Qspectre",
"/wd4305", # abseil after switch to build tools 22
"/wd4324", # genai after switch to build tools 22
"/wd4068",
"/wd4458",
"/wd4100",
"/wd4389",
"/wd4127",
"/wd4673",
"/wd4670",
"/wd4244",
"/wd4297",
"/wd4702",
"/wd4267",
"/wd4996",
"/wd6240",
"/wd6326",
"/wd6385",
"/wd6294",
"/guard:cf",
"/utf-8",
]
COMMON_STATIC_LIBS_COPTS = select({
"//conditions:default": LINUX_COMMON_STATIC_LIBS_COPTS,
"//src:windows" : WINDOWS_COMMON_STATIC_LIBS_COPTS,
})
COMMON_STATIC_TEST_COPTS = select({
"//conditions:default": [
"-Wall",
"-Wno-unknown-pragmas",
"-Werror",
# ov::Tensor::data method call results in deprecated warning and we use it in multiple places
"-Wno-deprecated-declarations",
"-Isrc",
"-fconcepts", # for gmock related utils
"-fvisibility=hidden",# Needed for pybind targets
],
"//src:windows" : [
"-W0",
"-Isrc",
"/wd4996",
"/utf-8",
],
})
COMMON_STATIC_LIBS_LINKOPTS = select({
"//conditions:default": [
"-lxml2",
"-luuid",
"-lstdc++fs",
"-lssl",
"-lcrypto",
# "-lovms_shared", # Use for dynamic linking when necessary
],
"//src:windows" : [
"/NXCOMPAT",
"/LTCG",
],
})
COPTS_PYTHON = select({
"//conditions:default": ["-DPYTHON_DISABLE=1"],
"//:not_disable_python" : ["-DPYTHON_DISABLE=0"],
})
COPTS_MEDIAPIPE = select({
"//conditions:default": ["-DMEDIAPIPE_DISABLE=1"],
"//:not_disable_mediapipe" : ["-DMEDIAPIPE_DISABLE=0"],
})
COPTS_DROGON = select({
"//conditions:default": ["-DUSE_DROGON=0"],
"//:enable_drogon" : ["-DUSE_DROGON=1"],
})
COMMON_FUZZER_COPTS = [
"-fsanitize=address",
"-fprofile-generate",
"-ftest-coverage",
]
COMMON_FUZZER_LINKOPTS = [
"-fprofile-generate",
"-fsanitize=address",
"-fsanitize-coverage=trace-pc",
"-static-libasan",
]
COMMON_LOCAL_DEFINES = ["SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE"]
PYBIND_DEPS = [
"//third_party:python3",
"@pybind11//:pybind11_embed",
]