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

[tools] Add always_optimize option for drake_cc_library #22380

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions geometry/proximity/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ drake_cc_library(
"aabb.h",
"obb.h",
],
always_optimize = True,
deps = [
":boxes_overlap",
":posed_half_space",
Expand Down
11 changes: 11 additions & 0 deletions tools/skylark/drake_cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ def drake_cc_library(
clang_copts = [],
gcc_copts = [],
linkstatic = 1,
always_optimize = True,
internal = False,
compile_once_per_scalar = False,
declare_installed_headers = 1,
Expand Down Expand Up @@ -595,6 +596,11 @@ def drake_cc_library(
part of Drake). In other words, all of Drake's C++ libraries must be
declared using the drake_cc_library macro.

Setting `always_optimize = True` builds the library with optimizations
enabled even in Debug builds. This can be used (sparingly) for low-level
libraries whose performance without optimizations is so bad as to make
the whole project suffer.

Setting `internal = True` is convenient sugar to flag code that is never
used by Drake's installed headers. This is especially helpful when the
header_lint tool is complaining about third-party dependency pollution.
Expand All @@ -618,6 +624,11 @@ def drake_cc_library(
should be surrounded with `#if DRAKE_ONCE_PER_SCALAR_PHASE == 0`.
"""
new_copts = _platform_copts(copts, gcc_copts, clang_copts)
if always_optimize:
new_copts = new_copts + [
"-O2",
"-DNDEBUG",
]
new_tags = kwargs.pop("tags", None) or []
if internal:
if install_hdrs_exclude != []:
Expand Down