diff --git a/build_defs/c.build_defs b/build_defs/c.build_defs index 91e1f31..9583909 100644 --- a/build_defs/c.build_defs +++ b/build_defs/c.build_defs @@ -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( diff --git a/build_defs/cc.build_defs b/build_defs/cc.build_defs index 2e99014..ec41ea0 100644 --- a/build_defs/cc.build_defs +++ b/build_defs/cc.build_defs @@ -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: diff --git a/test/BUILD b/test/BUILD index e663307..8282d4d 100644 --- a/test/BUILD +++ b/test/BUILD @@ -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", }, )