@@ -77,6 +77,12 @@ def _common_cxx_opts(exceptions = False, rtti = False, standard = None):
7777def _construct_local_includes (local_includes ):
7878 return [construct_local_include (path ) for path in local_includes ]
7979
80+ def _link_static (linkstatic ):
81+ return select ({
82+ Label ("//cc:_enable_shared" ): True ,
83+ "//conditions:default" : linkstatic ,
84+ })
85+
8086# Disable building when --//:disable_tests=true or when building on windows
8187def _test_compatible_with ():
8288 return select ({
@@ -220,7 +226,7 @@ def swift_c_library(**kwargs):
220226
221227 kwargs ["tags" ] = [LIBRARY ] + kwargs .get ("tags" , [])
222228
223- kwargs ["linkstatic" ] = kwargs .get ("linkstatic" , True )
229+ kwargs ["linkstatic" ] = _link_static ( kwargs .get ("linkstatic" , True ) )
224230
225231 native .cc_library (** kwargs )
226232
@@ -273,7 +279,7 @@ def swift_cc_library(**kwargs):
273279
274280 kwargs ["tags" ] = [LIBRARY ] + kwargs .get ("tags" , [])
275281
276- kwargs ["linkstatic" ] = kwargs .get ("linkstatic" , True )
282+ kwargs ["linkstatic" ] = _link_static ( kwargs .get ("linkstatic" , True ) )
277283
278284 native .cc_library (** kwargs )
279285
@@ -317,7 +323,7 @@ def swift_c_tool_library(**kwargs):
317323
318324 kwargs ["copts" ] = copts + c_standard + kwargs .get ("copts" , [])
319325
320- kwargs ["linkstatic" ] = kwargs .get ("linkstatic" , True )
326+ kwargs ["linkstatic" ] = _link_static ( kwargs .get ("linkstatic" , True ) )
321327
322328 native .cc_library (** kwargs )
323329
@@ -364,7 +370,7 @@ def swift_cc_tool_library(**kwargs):
364370
365371 kwargs ["copts" ] = copts + cxxopts + kwargs .get ("copts" , [])
366372
367- kwargs ["linkstatic" ] = kwargs .get ("linkstatic" , True )
373+ kwargs ["linkstatic" ] = _link_static ( kwargs .get ("linkstatic" , True ) )
368374
369375 native .cc_library (** kwargs )
370376
@@ -412,7 +418,7 @@ def swift_c_binary(**kwargs):
412418
413419 kwargs ["tags" ] = [BINARY ] + kwargs .get ("tags" , [])
414420
415- kwargs ["linkstatic" ] = kwargs .get ("linkstatic" , True )
421+ kwargs ["linkstatic" ] = _link_static ( kwargs .get ("linkstatic" , True ) )
416422
417423 native .cc_binary (** kwargs )
418424
@@ -578,7 +584,7 @@ def swift_cc_test_library(**kwargs):
578584
579585 kwargs ["target_compatible_with" ] = kwargs .get ("target_compatible_with" , []) + _test_compatible_with ()
580586
581- kwargs ["linkstatic" ] = kwargs .get ("linkstatic" , True )
587+ kwargs ["linkstatic" ] = _link_static ( kwargs .get ("linkstatic" , True ) )
582588
583589 native .cc_library (** kwargs )
584590
@@ -627,7 +633,8 @@ def swift_cc_test(name, type, **kwargs):
627633 kwargs ["copts" ] = local_includes + kwargs .get ("copts" , [])
628634 kwargs ["data" ] = kwargs .get ("data" , []) + _symbolizer_data ()
629635 kwargs ["env" ] = _symbolizer_env (kwargs .get ("env" , {}))
630- kwargs ["linkstatic" ] = kwargs .get ("linkstatic" , True )
636+ # should we just always build test binaries statically?
637+ kwargs ["linkstatic" ] = _link_static (kwargs .get ("linkstatic" , True ))
631638 kwargs ["name" ] = name
632639 kwargs ["tags" ] = [TEST , type ] + kwargs .get ("tags" , [])
633640 kwargs ["target_compatible_with" ] = kwargs .get ("target_compatible_with" , []) + _test_compatible_with ()
0 commit comments