Skip to content

Commit a221761

Browse files
committed
add shared linking option
1 parent 4a7d8ea commit a221761

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

cc/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ config_setting(
5555
visibility = ["//visibility:public"],
5656
)
5757

58+
bool_flag(
59+
name = "enable_shared",
60+
build_setting_default = False,
61+
visibility = ["//visibility:public"],
62+
)
63+
64+
config_setting(
65+
name = "_enable_shared",
66+
build_setting_default = False,
67+
visibility = ["//visibility:public"],
68+
)
69+
5870
# Disable warnings as errors with --@rules_swiftnav//cc:warnings_as_errors=false
5971
bool_flag(
6072
name = "warnings_as_errors",

cc/defs.bzl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def _common_cxx_opts(exceptions = False, rtti = False, standard = None):
7777
def _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
8187
def _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

Comments
 (0)