-
Notifications
You must be signed in to change notification settings - Fork 1
/
workspace.armv6.bzl
177 lines (153 loc) · 5.33 KB
/
workspace.armv6.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
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
"""
This module contains workspace definitions for building and using libedgetpu.
"""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
# TF release 2.16.1 as of Mar 8, 2024
#
# TENSORFLOW_SHA256=$(curl -fSL "https://github.com/tensorflow/tensorflow/archive/${TENSORFLOW_COMMIT}.tar.gz" | sha256sum)
TENSORFLOW_COMMIT = "5bc9d26649cca274750ad3625bd93422617eed4b"
TENSORFLOW_SHA256 = "fe592915c85d1a89c20f3dd89db0772ee22a0fbda78e39aa46a778d638a96abc"
CORAL_CROSSTOOL_COMMIT = "6bcc2261d9fc60dff386b557428d98917f0af491"
CORAL_CROSSTOOL_SHA256 = "38cb4da13009d07ebc2fed4a9d055b0f914191b344dd2d1ca5803096343958b4"
def libedgetpu_dependencies(
tensorflow_commit = TENSORFLOW_COMMIT,
tensorflow_sha256 = TENSORFLOW_SHA256,
coral_crosstool_commit = CORAL_CROSSTOOL_COMMIT,
coral_crosstool_sha256 = CORAL_CROSSTOOL_SHA256):
"""Sets up libedgetpu dependencies.
Args:
tensorflow_commit: https://github.com/tensorflow/tensorflow commit ID
tensorflow_sha256: corresponding sha256 of the source archive
coral_crosstool_commit: https://github.com/cocoa-xu/crosstool commit ID
coral_crosstool_sha256: corresponding sha256 of the source archive
"""
maybe(
http_archive,
name = "org_tensorflow",
urls = [
"https://github.com/tensorflow/tensorflow/archive/" + tensorflow_commit + ".tar.gz",
],
sha256 = tensorflow_sha256,
strip_prefix = "tensorflow-" + tensorflow_commit,
)
maybe(
http_archive,
name = "coral_crosstool",
urls = [
"https://github.com/google-coral/crosstool/archive/" + coral_crosstool_commit + ".tar.gz",
],
sha256 = coral_crosstool_sha256,
strip_prefix = "crosstool-" + coral_crosstool_commit,
)
maybe(
libusb_repository,
name = "libusb",
)
# Use bazel to query values defined here, e.g.:
# bazel query "@libedgetpu_properties//..." | grep tensorflow_commit | cut -d\# -f2
_properties_repository(
name = "libedgetpu_properties",
properties = {
"tensorflow_commit": tensorflow_commit,
"coral_crosstool_commit": coral_crosstool_commit,
},
)
def _brew_libusb_path(ctx):
res = ctx.execute(["/bin/bash", "-c", "command -v brew"])
if res.return_code != 0:
return None
brew = ctx.path(res.stdout.strip())
res = ctx.execute([brew, "ls", "--versions", "libusb"])
if res.return_code != 0:
return None
res = ctx.execute([brew, "--prefix", "libusb"])
if res.return_code != 0:
return None
return res.stdout.strip()
def _port_libusb_path(ctx):
res = ctx.execute(["/bin/bash", "-c", "command -v port"])
if res.return_code != 0:
return None
port = ctx.path(res.stdout.strip())
res = ctx.execute([port, "info", "libusb"])
if res.return_code != 0:
return None
return port.dirname.dirname
def _pkg_config_libusb_path(ctx):
res = ctx.execute(["/bin/bash", "-c", "which pkg-config"])
if res.return_code != 0:
return None
pkg_config = ctx.path(res.stdout.strip())
res = ctx.execute([pkg_config, "--cflags-only-I", "libusb-1.0"])
if res.return_code != 0:
return None
return res.stdout.strip()[2:-19]
def _libusb_impl(ctx):
lower_name = ctx.os.name.lower()
if lower_name.startswith("linux"):
path = _pkg_config_libusb_path(ctx)
build_file_content = """
cc_library(
name = "headers",
srcs = ["root/lib/libusb-1.0.so"],
visibility = ["//visibility:public"],
includes = ["root/include"],
hdrs = ["root/include/libusb-1.0/libusb.h"],
)
"""
elif lower_name.startswith("windows"):
path = str(ctx.path(Label("@//:WORKSPACE"))) + "/../../libusb"
build_file_content = """
cc_library(
name = "headers",
includes = ["root/include"],
hdrs = ["root/include/libusb-1.0/libusb.h"],
visibility = ["//visibility:public"],
)
cc_import(
name = "shared",
interface_library = "root/VS2019/MS64/dll/libusb-1.0.lib",
shared_library = "root/VS2019/MS64/dll/libusb-1.0.dll",
visibility = ["//visibility:public"],
)
"""
elif lower_name.startswith("mac os x"):
path = _brew_libusb_path(ctx)
if not path:
path = _port_libusb_path(ctx)
if not path:
fail("Install libusb using MacPorts or Homebrew.")
build_file_content = """
cc_library(
name = "headers",
includes = ["root/include"],
hdrs = ["root/include/libusb-1.0/libusb.h"],
linkopts = ["-framework", "IOKit", "-framework", "Security"],
srcs = ["root/lib/libusb-1.0.a"],
visibility = ["//visibility:public"],
)
"""
else:
fail("Unsupported operating system.")
if path:
ctx.symlink(path, "root")
ctx.file(
"BUILD",
content = build_file_content,
executable = False,
)
libusb_repository = repository_rule(
implementation = _libusb_impl,
)
def _properties_impl(ctx):
content = ""
for name, value in ctx.attr.properties.items():
content += "filegroup(name='" + name + "#" + value + "')\n"
ctx.file("BUILD", content = content, executable = False)
_properties_repository = repository_rule(
implementation = _properties_impl,
attrs = {
"properties": attr.string_dict(),
},
)