Skip to content
Merged
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
3 changes: 2 additions & 1 deletion build_defs/c.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ def c_binary(name:str, srcs:list=[], hdrs:list=[], private_hdrs:list=[], compile
Alternatively can be a dict of name -> value to define, in which case
values are surrounded by quotes.
test_only (bool): If True, this rule can only be used by tests.
static (bool): If True, the binary will be linked statically.
static (bool): If True, the binary will be linked statically. Statically-linked binaries are
not supported on macOS, so this is a no-op when generating a Mach-O binary.
optional_outs (list): Name of optional outputs.
"""
return cc_binary(
Expand Down
6 changes: 5 additions & 1 deletion build_defs/cc.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,16 @@ def cc_binary(name:str, srcs:list=[], hdrs:list=[], private_hdrs:list=[],
Alternatively can be a dict of name -> value to define, in which case
values are surrounded by quotes.
test_only (bool): If True, this rule can only be used by tests.
static (bool): If True, the binary will be linked statically.
static (bool): If True, the binary will be linked statically. Statically-linked binaries are
not supported on macOS, so this is a no-op when generating a Mach-O binary.
linkstatic (bool): Only provided for Bazel compatibility. Has no actual effect since we always
link roughly equivalently to their "mostly-static" mode.
labels (list): Labels to attach to this rule.
optional_outs (list): Name of optional outputs.
"""
if CONFIG.TARGET_OS == "darwin" and static:
log.warning("%s: statically-linked binaries are unsupported on Darwin; ignoring value of 'static' parameter" % canonicalise(f":{name}"))
static = False
if CONFIG.BAZEL_COMPATIBILITY:
linker_flags = ['-lpthread' if l == '-pthread' else l for l in linker_flags]
if CONFIG.CC.DEFAULT_LDFLAGS:
Expand Down
4 changes: 3 additions & 1 deletion test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ plugin_e2e_test(
"file $(plz query outputs //:static) > file",
],
expect_output_contains = {
"file": "statically linked",
# Statically-linked executables can't be generated for Darwin, but //:static should at least
# output a functioning dynamically-linked executable.
"file": "executable" if CONFIG.TARGET_OS == "darwin" else "statically linked",
},
)