Skip to content

Commit

Permalink
Merge pull request #7323 from osrf/use-libprotobuf
Browse files Browse the repository at this point in the history
Use the system protobuf.
  • Loading branch information
jwnimmer-tri authored Dec 18, 2017
2 parents 2b581ab + bf3bad0 commit f9baebd
Show file tree
Hide file tree
Showing 19 changed files with 653 additions and 252 deletions.
45 changes: 34 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ workspace(name = "drake")

load("//tools/workspace:bitbucket.bzl", "bitbucket_archive")
load("//tools/workspace:github.bzl", "github_archive")
load("//tools/workspace:which.bzl", "which")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

local_repository(
Expand Down Expand Up @@ -52,6 +53,24 @@ new_local_repository(
path = __workspace_dir__ + "/third_party/com_github_tcbrindle_cpp17_headers", # noqa
)

# This local repository imports the protobuf build rules for Bazel (based on
# the upstream protobuf.bzl build rules). The protobuf runtime is loaded
# into "libprotobuf" via pkg-config below.
local_repository(
name = "com_google_protobuf",
# TODO(clalancette) Per https://github.com/RobotLocomotion/drake/pull/7361
# this should use an absolute path (so this should be prepended by
# __workspace_dir__). However, in a clean build, this did not work. We
# should investigate that and fix it.
path = "third_party/com_github_google_protobuf",
)

new_local_repository(
name = "find_protobuf_cmake",
build_file = "tools/workspace/protobuf/find_protobuf_cmake.BUILD.bazel",
path = __workspace_dir__ + "/third_party/com_kitware_gitlab_cmake_cmake",
)

load("@kythe//tools/build_rules/config:pkg_config.bzl", "pkg_config_package")

pkg_config_package(
Expand All @@ -64,6 +83,19 @@ pkg_config_package(
modname = "gthread-2.0",
)

# Load in the paths and flags to the system version of the protobuf runtime;
# the Bazel build rules are loaded into "protobuf" via local_repository above.
pkg_config_package(
name = "libprotobuf",
modname = "protobuf",
)

# Find the protoc binary on $PATH.
which(
name = "protoc",
command = "protoc",
)

load("//tools/workspace/python:python.bzl", "python_repository")

python_repository(
Expand Down Expand Up @@ -335,15 +367,6 @@ bind(
actual = "@six_archive//:six",
)

# When updating the version of protobuf,
# update tools/install/protobuf/protobuf.cps
github_archive(
name = "com_google_protobuf",
repository = "google/protobuf",
commit = "v3.5.0",
sha256 = "0cc6607e2daa675101e9b7398a436f09167dffb8ca0489b0307ff7260498c13c", # noqa
)

pypi_archive(
name = "semantic_version",
version = "2.6.0",
Expand All @@ -355,8 +378,8 @@ pypi_archive(
github_archive(
name = "pycps",
repository = "mwoehlke/pycps",
commit = "a6110cf2e769e9ff262a98ed18506ad565a14e89",
sha256 = "62b5054705152ba971a6e9a358bfcc1359eca6f3ba8e5788befd82d606933d98", # noqa
commit = "544c1ded81b926a05b3dedb06504bd17bc8d0a95",
sha256 = "0b97cbaae107e5ddbe89073b6e42b679130f1eb81b913aa93da9e72e032a137b", # noqa
build_file = "tools/workspace/pycps/pycps.BUILD.bazel",
)

Expand Down
2 changes: 2 additions & 0 deletions bindings/pydrake/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ drake_py_test(
drake_py_test(
name = "common_install_test",
size = "medium",
# Increase the timeout so that debug builds are successful.
timeout = "long",
srcs = ["test/common_install_test.py"],
data = ["//:install"],
main = "test/common_install_test.py",
Expand Down
17 changes: 17 additions & 0 deletions matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ include(cmake/packages.cmake)

configure_file(addpath_drake.m.in addpath_drake.m @ONLY)

if(UNIX AND NOT APPLE)
# On Linux, force targets to use system Protobuf shared library instead of
# the shared library bundled with MATLAB. On macOS, the two shared libraries
# are correctly marked as ABI incompatible.

get_filename_component(MEX_LIBRARY_DIR "${Matlab_MEX_LIBRARY}" DIRECTORY)
get_filename_component(PROTOBUF_LIBRARY_DIR
"${Protobuf_LIBRARY_RELEASE}" DIRECTORY
)

set(CMAKE_INSTALL_RPATH
"$ORIGIN:$ORIGIN/../../../lib:${PROTOBUF_LIBRARY_DIR}:${MEX_LIBRARY_DIR}"
)

set(CMAKE_CXX_FLAGS "-Wl,-rpath,${PROTOBUF_LIBRARY_DIR} ${CMAKE_CXX_FLAGS}")
endif()

drake_matlab_add_mex(mex_util mex_util.cc mex_util.h)
target_link_libraries(mex_util drake::drake Eigen3::Eigen)

Expand Down
3 changes: 1 addition & 2 deletions matlab/cmake/packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ set(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY ON)

if(APPLE)
set(MINIMUM_MATLAB_VERSION 9.2)
# TODO(jamiesnape): Change from 3.1 to 3.5 when #7323 merges.
set(MINIMUM_PROTOBUF_VERSION 3.1)
set(MINIMUM_PROTOBUF_VERSION 3.5)
else()
# TODO(jamiesnape): Change from 9 to 9.2 when support for R2016a and R2016 is
# no longer needed.
Expand Down
1 change: 1 addition & 0 deletions setup/ubuntu/16.04/install_prereqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ lldb-4.0
make
mesa-common-dev
openjdk-8-jdk
patchelf
patchutils
pkg-config
protobuf-compiler
Expand Down
28 changes: 28 additions & 0 deletions third_party/com_github_google_protobuf/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- python -*-

package(
default_visibility = ["//visibility:public"],
)

exports_files(["protobuf.bzl"])

# The protobuf.bzl looks here to find which protoc to use.
# Drake uses the protoc found on $PATH (typically from the host OS).
filegroup(
name = "protoc",
srcs = ["@protoc"],
)

# The protobuf.bzl looks here to find which runtime to use.
# Drake uses the libprotobuf found by pkg-config (typically from the host OS).
alias(
name = "protobuf",
actual = "@libprotobuf",
)

# The protobuf.bzl looks here to find which python runtime to use.
# Drake uses the library already on $PYTHONPATH (typically from the host OS).
py_library(
name = "protobuf_python",
# No srcs here, so we'll use the system default.
)
42 changes: 42 additions & 0 deletions third_party/com_github_google_protobuf/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
This license applies to all parts of Protocol Buffers except the following:

- Atomicops support for generic gcc, located in
src/google/protobuf/stubs/atomicops_internals_generic_gcc.h.
This file is copyrighted by Red Hat Inc.

- Atomicops support for AIX/POWER, located in
src/google/protobuf/stubs/atomicops_internals_power.h.
This file is copyrighted by Bloomberg Finance LP.

Copyright 2014, Google Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Code generated by the Protocol Buffer compiler is owned by the owner
of the input file used when generating it. This code is not
standalone and requires a support library to be linked with it. This
support library is itself covered by the above license.
10 changes: 10 additions & 0 deletions third_party/com_github_google_protobuf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This directory holds vendored and modified copies of Bazel support code from
https://github.com/google/protobuf, originally downloaded from commit
4fc93044a5de018527ec027dbee6a882012e0d9d. The following lists which files are
copyrighted by whom:

BUILD.bazel - Drake project
LICENSE - Google, protobuf project
protobuf.bzl - Google, protobuf project
README.md - Drake project
WORKSPACE - Drake project
6 changes: 6 additions & 0 deletions third_party/com_github_google_protobuf/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- python -*-

# This file marks a workspace root for the Bazel build system. see
# http://bazel.io/ .

workspace(name = "com_google_protobuf")
Loading

0 comments on commit f9baebd

Please sign in to comment.