-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrakefile
210 lines (201 loc) · 6.49 KB
/
drakefile
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
import drake
import drake.cmake
import drake.cxx
import os.path
import sys
cxx_config = None
cxx_config_lib = None
protoc = None
protobuf_headers = None
protobuf_lib = None
grpc_cpp_plugin = None
grpc_python_plugin = None
libgrpcxx = None
sources = None
def configure(
cxx_toolkit,
in_cxx_config,
cmake_vars = {}
):
global protoc, grpc_cpp_plugin, grpc_python_plugin, libgrpcxx, sources
zlib_git = drake.git.Git('third_party/zlib')
windows = cxx_toolkit.os == drake.os.windows
EXE = '.exe' if windows else ''
protoc = drake.Node('third_party/protobuf/protoc' + EXE)
# protobuf lib.
libtype = drake.cxx.StaticLib if windows else drake.cxx.DynLib
global protobuf_headers, protobuf_lib
protobuf_lib = libtype('third_party/protobuf/protobuf',
tk = cxx_toolkit, cfg = in_cxx_config)
protoc_lib = libtype('third_party/protobuf/protoc',
tk = cxx_toolkit, cfg = in_cxx_config)
# Garbage files the cmake build generates in the source tree
garbage = drake.nodes('third_party/zlib/zconf.h.included')
# Files the cmake build removes from the source tree.
nuked = ['zconf.h']
protobuf_headers = drake.nodes(*['third_party/protobuf/src/google/protobuf/{}'.format(f)
for f in [
'any.h',
'any.pb.h',
'api.pb.h',
'arena.h',
'arena_test_util.h',
'arenastring.h',
'descriptor.h',
'descriptor.pb.h',
'descriptor_database.h',
'duration.pb.h',
'dynamic_message.h',
'empty.pb.h',
'extension_set.h',
'field_mask.pb.h',
'generated_enum_reflection.h',
'generated_enum_util.h',
'generated_message_reflection.h',
'generated_message_util.h',
'has_bits.h',
'map.h',
'map_entry.h',
'map_entry_lite.h',
'map_field.h',
'map_field_inl.h',
'map_field_lite.h',
'map_lite_test_util.h',
'map_test_util.h',
'map_test_util_impl.h',
'map_type_handler.h',
'message.h',
'message_lite.h',
'metadata.h',
'package_info.h',
'reflection.h',
'reflection_internal.h',
'reflection_ops.h',
'repeated_field.h',
'service.h',
'source_context.pb.h',
'struct.pb.h',
'test_util.h',
'test_util_lite.h',
'text_format.h',
'timestamp.pb.h',
'type.pb.h',
'unknown_field_set.h',
'wire_format.h',
'wire_format_lite.h',
'wire_format_lite_inl.h',
'wrappers.pb.h',
]])
grpc_cpp_plugin = drake.node('grpc_cpp_plugin' + EXE)
grpc_python_plugin = drake.node('grpc_python_plugin' + EXE)
libgrpcxx = drake.path_build('libgrpc++.a')
srcs = drake.nodes(
'CMakeLists.txt',
)
sources = drake.nodes(
'libgrpc++.a',
'libgrpc.a',
'libgpr.a',
'third_party/boringssl/ssl/libssl.a',
'third_party/boringssl/crypto/libcrypto.a',
'third_party/zlib/libz{}.a'.format('libstatic' if windows else ''),
)
dsts = sources + [
grpc_cpp_plugin,
grpc_python_plugin,
protoc,
protoc_lib,
protobuf_lib,
]
# make targets. Do not build everything.
targets = [
'grpc',
'grpc++',
'grpc_cpp_plugin',
'grpc_python_plugin',
('third_party/protobuf', 'protoc') # (workdir, target)
]
if drake.path_source().absolute():
cmake_source = drake.path_source() / drake.Drake.current.prefix
else:
cmake_source = drake.node('CMakeLists.txt').path().dirname()
cmake_source = cmake_source.without_prefix(drake.Drake.current.prefix)
cmake_vars.update({
'protobuf_BUILD_SHARED_LIBS': 'OFF' if windows else 'ON',
'protobuf_BUILD_TESTS': 'OFF',
# FIXME: We don't seem to be using the Zlib features.
'protobuf_WITH_ZLIB': 'OFF',
'CMAKE_CXX_FLAGS': '-w ' + ('-stdlib=libc++' if cxx_toolkit.os == drake.os.macos else ''),
'CMAKE_EXE_LINKER_FLAGS': '-static' if windows else '',
})
class GRPCBuilder(drake.cmake.CMakeBuilder):
def execute(self):
if super().execute():
# Let libprotobuf use our libraries, including libc++ on Darwin.
drake.cxx.set_lib_id(protobuf_lib.path())
drake.cxx.set_lib_id(protoc_lib.path())
# Be sure not to keep an absolute rpath, that's disastrous
# with our build-env cache, as we would finish by having
# pieces of protobuf in one build look for other pieces in
# another build (which might no longer exist).
for libs, path in [
([protoc, protoc_lib], '.'),
([grpc_cpp_plugin, grpc_python_plugin],
'third_party/protobuf')
]:
for l in libs:
self.cmd('Fix rpath for {}'.format(l),
cxx_toolkit.rpath_set_command(l, path))
# This is quite some code duplication with
# drake/cxx/__init__.py's PatchAndInstall. We need something
# more reusable.
if sys.platform == 'darwin':
for l in [grpc_cpp_plugin, grpc_python_plugin, protoc, protoc_lib]:
path = l.path()
import subprocess
out = subprocess.check_output(['otool', '-L', str(path)])
lines = out.decode('utf-8').strip().split('\n')
deps = [
x.replace('\t', '').split(' ')[0]
for x in lines[1:] if 'libstdc++' in x or 'libgcc_s' in x
]
for d in deps:
drake.command([
'install_name_tool',
'-change', d, '@rpath/%s' % (os.path.basename(d)),
str(path)
])
# The zlib builds pollutes the build tree, fix it back.
for g in garbage:
try:
os.remove(str(g.path()))
except FileNotFoundError:
pass
for n in nuked:
zlib_git.run(['checkout', 'HEAD', n])
return True
else:
return False
def hash(self):
# Salt with a version number of this builder.
return (super().hash(), 8)
cmake = GRPCBuilder(cxx_toolkit, srcs, dsts,
vars = cmake_vars, targets = targets,
path_to_cmake_source = cmake_source)
global cxx_config, cxx_config_lib
cxx_config = in_cxx_config
if windows:
cxx_config.define('_WIN32_WINNT', '0x600')
protobuf_include = 'third_party/protobuf/src'
cxx_config.protobuf_include_dir = \
drake.path_root() / drake.path_source(protobuf_include)
cxx_config.add_system_include_path(protobuf_include)
cxx_config.add_system_include_path('include')
cxx_config_lib = drake.cxx.Config(cxx_config)
cxx_config_lib.use_whole_archive()
if windows:
cxx_config_lib.lib('ws2_32')
cxx_config_lib.lib('kernel32')
# Local Variables:
# mode: python
# End: