forked from google-coral/libedgetpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibedgetpu_cc_rules.bzl
114 lines (104 loc) · 2.91 KB
/
libedgetpu_cc_rules.bzl
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
"""
This module defines rules to set copts and linkopts for
libraries and modules in the libedgetpu project.
"""
# This allows the dependencies to work correctly
# if we are included as a submodule.
def clean_dep(dep):
return str(Label(dep))
WINDOWS_COPTS = [
"/DSTRIP_LOG=1",
"/DABSL_FLAGS_STRIP_NAMES",
"/D_HAS_DEPRECATED_RESULT_OF",
"/D_HAS_DEPRECATED_ADAPTOR_TYPEDEFS",
"/GR-",
"/DWIN32_LEAN_AND_MEAN",
"/D_WINSOCKAPI_",
]
WINDOWS_LINKOPTS = []
WINDOWS_OPT_LINKOPTS = []
DARWIN_COPTS = [
"-fvisibility=hidden",
]
DARWIN_LINKOPTS = [
"-L/opt/local/lib",
"-lusb-1.0",
]
DARWIN_OPT_LINKOPTS = []
LINUX_COPTS = []
LINUX_LINKOPTS = [
"-l:libusb-1.0.so",
]
LINUX_OPT_LINKOPTS = [
"-Wl,--strip-all",
]
COMMON_COPTS = [
"-DSTRIP_LOG=1",
"-fno-rtti",
"-fno-exceptions",
'-D__FILE__=\\"\\"',
]
COMMON_LINKOPTS = []
COMMON_OPT_LINKOPTS = []
def libedgetpu_copts():
return select({
clean_dep("//:windows"): WINDOWS_COPTS,
clean_dep("//:darwin"): DARWIN_COPTS + COMMON_COPTS,
"//conditions:default": LINUX_COPTS + COMMON_COPTS,
})
def libedgetpu_linkopts():
return select({
clean_dep("//:windows"): WINDOWS_LINKOPTS,
clean_dep("//:darwin"): DARWIN_LINKOPTS + COMMON_LINKOPTS,
"//conditions:default": LINUX_LINKOPTS + COMMON_LINKOPTS,
})
def libedgetpu_opt_linkopts():
return select({
clean_dep("//:windows"): WINDOWS_OPT_LINKOPTS,
clean_dep("//:darwin"): DARWIN_OPT_LINKOPTS + COMMON_OPT_LINKOPTS,
"//conditions:default": LINUX_OPT_LINKOPTS + COMMON_OPT_LINKOPTS,
})
def libedgetpu_cc_library(name, copts = [], **attrs):
native.cc_library(
name = name + "_opt",
copts = copts + libedgetpu_copts(),
**attrs
)
native.cc_library(
name = name + "_default",
copts = copts + libedgetpu_copts(),
**attrs
)
native.cc_library(
name = name,
deps = select({
clean_dep("//:opt"): [name + "_opt"],
"//conditions:default": [name + "_default"],
}),
)
def libedgetpu_cc_binary(name, copts = [], linkopts = [], deps = [], additional_linker_inputs = [], linkshared = 0, **attrs):
native.cc_library(
name = name + "_opt",
copts = copts + libedgetpu_copts(),
linkopts = libedgetpu_linkopts() + libedgetpu_opt_linkopts(),
deps = deps,
**attrs
)
native.cc_library(
name = name + "_default",
copts = copts + libedgetpu_copts(),
linkopts = libedgetpu_linkopts(),
deps = deps,
**attrs
)
native.cc_binary(
name = name,
deps = select({
clean_dep("//:opt"): [name + "_opt"],
"//conditions:default": [name + "_default"],
}) + deps,
linkopts = linkopts,
additional_linker_inputs = additional_linker_inputs,
linkshared = linkshared,
**attrs
)