When building any cc_test target or cc_binary target with coverage instrumentation on macOS, bazel coverage fails with an error like this:
>>>>>>>>> # //:hello_lib [action 'Linking libhello_lib.so']
(cd /private/var/tmp/_bazel_jayconrod/dc23ec2471431a08def1a3ea88cf8238/execroot/__main__ && \
exec env - \
APPLE_SDK_PLATFORM='' \
APPLE_SDK_VERSION_OVERRIDE='' \
XCODE_VERSION_OVERRIDE=8.3.3 \
external/local_config_cc/cc_wrapper.sh -fobjc-link-runtime -Wl,-S -shared -o bazel-out/darwin-fastbuild/bin/libhello_lib.so bazel-out/darwin-fastbuild/bin/_objs/hello_lib/hello.o -lgcov -headerpad_max_install_names -lc++ -no-canonical-prefixes -undefined dynamic_lookup)
ERROR: /Users/jayconrod/go/src/example.com/repo/BUILD.bazel:6:1: Linking of rule '//:hello_lib' failed (Exit 1).
ld: library not found for -lgcov
clang: error: linker command failed with exit code 1 (use -v to see invocation)
// hello.c
int main() {return 0;}
# BUILD.bazel
cc_test(
name = "hello",
deps = [":hello_lib"],
)
cc_library(
name = "hello_lib",
srcs = ["hello.c"],
)
$ bazel coverage //:hello
macOS High Sierra 10.13.4
bazel info release?release 0.13.0
It looks like -lgcov is being passed on the command line to the linker. macOS doesn't seem to have this library. Maybe passing --coverage would be better? That works for me in small examples on both macOS and Linux, both gcc and clang.
-lgcov was replaced with --coverage in d6f706d334046601df9d0a58b993b705e9e371a0, so this should be fixed with the next release. There are a few more places that use -lgcov which should be changed as well.
Looks like it is still broken in 0.14.1:
$ bazel info release
release 0.14.1-homebrew
$ bazel coverage -s ...
ERROR: /private/var/tmp/_bazel_zaytsev/031680ef6cb503622683e0f635fcc447/external/com_google_grpc/BUILD:1089:1: Linking of rule '@com_google_grpc//:grpc_server_load_reporting' failed (Exit 1)
ld: library not found for -lgcov
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Target //cli/cmds:go_default_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.737s, Critical Path: 0.39s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
Can someone verify if this is still happening with the latest Bazel release?
This is still happening in 0.15.2, but I can't reproduce anymore in 0.16.0-rc3. Thanks for fixing it!
Thanks for checking!
Most helpful comment
-lgcovwas replaced with--coveragein d6f706d334046601df9d0a58b993b705e9e371a0, so this should be fixed with the next release. There are a few more places that use-lgcovwhich should be changed as well.