@@ -110,6 +110,20 @@ BASE_COPTS = select({
110
110
("//conditions:default" , []),
111
111
]))
112
112
113
+ # The _base_linkopts() are used for all drake_cc_{binary,library,test} rules.
114
+ def _base_linkopts ():
115
+ is_debug = select ({
116
+ "//tools/cc_toolchain:debug" : True ,
117
+ "//conditions:default" : False ,
118
+ })
119
+ is_linux = select ({
120
+ "@drake//tools/skylark:linux" : True ,
121
+ "//conditions:default" : False ,
122
+ })
123
+ if is_linux and is_debug :
124
+ return ["-fuse-ld=mold" ]
125
+ return []
126
+
113
127
def _platform_copts (rule_copts , rule_gcc_copts , rule_clang_copts , cc_test = 0 ):
114
128
"""Returns the concatenation of Drake's platform-specific BASE_COPTS,
115
129
plus the passed-in rule_copts, plus the passed-in rule_{cc}_copts iff
@@ -596,6 +610,7 @@ def drake_cc_library(
596
610
copts = [],
597
611
clang_copts = [],
598
612
gcc_copts = [],
613
+ linkopts = [],
599
614
linkstatic = 1 ,
600
615
internal = False ,
601
616
compile_once_per_scalar = False ,
@@ -649,6 +664,7 @@ def drake_cc_library(
649
664
should be surrounded with `#if DRAKE_ONCE_PER_SCALAR_PHASE == 0`.
650
665
"""
651
666
new_copts = _platform_copts (copts , gcc_copts , clang_copts )
667
+ new_linkopts = _base_linkopts () + linkopts
652
668
new_tags = kwargs .pop ("tags" , None ) or []
653
669
if internal :
654
670
if install_hdrs_exclude != []:
@@ -690,6 +706,7 @@ def drake_cc_library(
690
706
deps = deps + add_deps ,
691
707
implementation_deps = implementation_deps ,
692
708
copts = new_copts ,
709
+ linkopts = new_linkopts ,
693
710
linkstatic = linkstatic ,
694
711
declare_installed_headers = declare_installed_headers ,
695
712
install_hdrs_exclude = install_hdrs_exclude ,
@@ -783,6 +800,7 @@ def drake_cc_binary(
783
800
defaults using test_rule_args=["-f", "--bar=42"] or test_rule_size="baz".
784
801
"""
785
802
new_copts = _platform_copts (copts , gcc_copts , clang_copts )
803
+ new_linkopts = _base_linkopts () + linkopts
786
804
new_srcs , add_deps = _maybe_add_pruned_private_hdrs_dep (
787
805
base_name = name ,
788
806
srcs = srcs ,
@@ -801,7 +819,7 @@ def drake_cc_binary(
801
819
testonly = testonly ,
802
820
linkshared = linkshared ,
803
821
linkstatic = linkstatic ,
804
- linkopts = linkopts ,
822
+ linkopts = new_linkopts ,
805
823
features = [
806
824
# We should deduplicate symbols while linking (for a ~6% reduction
807
825
# in disk use), to conserve space in CI; see #18545 for details.
@@ -839,6 +857,7 @@ def drake_cc_test(
839
857
copts = [],
840
858
gcc_copts = [],
841
859
clang_copts = [],
860
+ linkopts = [],
842
861
allow_network = None ,
843
862
display = False ,
844
863
num_threads = None ,
@@ -868,6 +887,7 @@ def drake_cc_test(
868
887
kwargs = incorporate_display (kwargs , display = display )
869
888
kwargs = incorporate_num_threads (kwargs , num_threads = num_threads )
870
889
new_copts = _platform_copts (copts , gcc_copts , clang_copts , cc_test = 1 )
890
+ new_linkopts = _base_linkopts () + linkopts
871
891
new_srcs , add_deps = _maybe_add_pruned_private_hdrs_dep (
872
892
base_name = name ,
873
893
srcs = srcs ,
@@ -882,6 +902,7 @@ def drake_cc_test(
882
902
args = args ,
883
903
deps = deps + add_deps ,
884
904
copts = new_copts ,
905
+ linkopts = new_linkopts ,
885
906
features = [
886
907
# We should deduplicate symbols while linking (for a ~6% reduction
887
908
# in disk use), to conserve space in CI; see #18545 for details.
0 commit comments