Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pybind11: Ensure all modules are compiled with hidden symbols #8435

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions tools/skylark/drake_cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ load(
# building with any compiler.
CXX_FLAGS = [
"-Werror=all",
"-Werror=attributes",
"-Werror=deprecated",
"-Werror=deprecated-declarations",
"-Werror=ignored-qualifiers",
Expand Down Expand Up @@ -48,9 +49,9 @@ GCC_CC_TEST_FLAGS = [
"-Wno-unused-parameter",
]

def _platform_copts(rule_copts, rule_gcc_copts, cc_test = 0):
"""Returns both the rule_copts (plus rule_gcc_copts iff under GCC), and
platform-specific copts.
def _platform_copts(rule_copts, rule_gcc_copts, rule_clang_copts, cc_test = 0):
"""Returns both the rule_copts (plus rule_{cc}_copts iff under the
specified compiler), and platform-specific copts.

When cc_test=1, the GCC_CC_TEST_FLAGS will be added. It should only be set
to 1 from cc_test rules or rules that are boil down to cc_test rules.
Expand All @@ -59,8 +60,10 @@ def _platform_copts(rule_copts, rule_gcc_copts, cc_test = 0):
if cc_test:
extra_gcc_flags = GCC_CC_TEST_FLAGS
return select({
"//tools/cc_toolchain:apple": CLANG_FLAGS + rule_copts,
"//tools/cc_toolchain:clang4.0-linux": CLANG_FLAGS + rule_copts,
"//tools/cc_toolchain:apple":
CLANG_FLAGS + rule_copts + rule_clang_copts,
"//tools/cc_toolchain:clang4.0-linux":
CLANG_FLAGS + rule_copts + rule_clang_copts,
"//tools/cc_toolchain:gcc5-linux":
GCC_FLAGS + extra_gcc_flags + rule_copts + rule_gcc_copts,
"//tools/cc_toolchain:gcc6-linux":
Expand Down Expand Up @@ -309,6 +312,7 @@ def drake_cc_library(
srcs = [],
deps = [],
copts = [],
clang_copts = [],
gcc_copts = [],
linkstatic = 1,
install_hdrs_exclude = [],
Expand All @@ -324,7 +328,7 @@ def drake_cc_library(
of Drake). In other words, all of Drake's C++ libraries must be declared
using the drake_cc_library macro.
"""
new_copts = _platform_copts(copts, gcc_copts)
new_copts = _platform_copts(copts, gcc_copts, clang_copts)
# We install private_hdrs by default, because Bazel's visibility denotes
# whether headers can be *directly* included when using cc_library; it does
# not precisely relate to which headers should appear in the install tree.
Expand Down Expand Up @@ -357,6 +361,7 @@ def drake_cc_binary(
copts = [],
linkopts = [],
gcc_copts = [],
clang_copts = [],
linkshared = 0,
linkstatic = 1,
testonly = 0,
Expand All @@ -379,7 +384,7 @@ def drake_cc_binary(
"""
data = adjust_labels_for_drake_hoist(data)
deps = adjust_labels_for_drake_hoist(deps)
new_copts = _platform_copts(copts, gcc_copts)
new_copts = _platform_copts(copts, gcc_copts, clang_copts)
new_srcs, new_deps = _maybe_add_pruned_private_hdrs_dep(
base_name = name,
srcs = srcs,
Expand Down Expand Up @@ -453,6 +458,7 @@ def drake_cc_test(
deps = [],
copts = [],
gcc_copts = [],
clang_copts = [],
disable_in_compilation_mode_dbg = False,
**kwargs):
"""Creates a rule to declare a C++ unit test. Note that for almost all
Expand All @@ -473,7 +479,7 @@ def drake_cc_test(
if not srcs:
srcs = ["test/%s.cc" % name]
kwargs['testonly'] = 1
new_copts = _platform_copts(copts, gcc_copts, cc_test = 1)
new_copts = _platform_copts(copts, gcc_copts, clang_copts, cc_test = 1)
new_srcs, new_deps = _maybe_add_pruned_private_hdrs_dep(
base_name = name,
srcs = srcs,
Expand Down
9 changes: 6 additions & 3 deletions tools/skylark/pybind.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ def _drake_pybind_cc_binary(
name = name,
# This is how you tell Bazel to link in a shared library.
srcs = srcs + ["//tools/install/libdrake:libdrake.so"],
# These copts are per pybind11 deficiencies.
copts = [
"-Wno-#warnings",
"-fvisibility=hidden",
# The following copts are per pybind11 deficiencies.
"-Wno-cpp",
"-Wno-unknown-warning-option",
] + copts,
clang_copts = [
"-Wno-#warnings",
"-Wno-unknown-warning-option",
],
# This is how you tell Bazel to create a shared library.
linkshared = 1,
linkstatic = 1,
Expand Down