Skip to content
Open
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
17 changes: 16 additions & 1 deletion .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ test_targets_bazel_6: &test_targets_bazel_6
- "-//tests/strip_include_prefix:test_include_textual" # Not supported in bazel <9.

common_coverage_flags: &common_coverage_flags
# Test failures are not collected under `coverage` invocations.
# https://github.com/bazelbuild/continuous-integration/issues/1838
- "--test_output=errors"

windows_coverage_flags: &windows_coverage_flags
# Starting in Bazel 9 coverage collection causes some tests to fail.
# https://github.com/bazelbuild/rules_cc/issues/613
- "--test_env=IGNORE_COVERAGE_COLLECTION_FAILURES=1"
Expand All @@ -45,6 +50,11 @@ common_coverage_flags: &common_coverage_flags
- "--test_output=errors"

coverage_flags_bazel_less_than_9: &coverage_flags_bazel_less_than_9
# See above
- "--test_output=errors"
- "--deleted_packages=//tests/local_includes"

windows_coverage_flags_bazel_less_than_9: &windows_coverage_flags_bazel_less_than_9
# See above
- "--test_env=IGNORE_COVERAGE_COLLECTION_FAILURES=1"
- "--test_output=errors"
Expand Down Expand Up @@ -127,6 +137,8 @@ tasks:
platform: windows
build_targets: *build_targets
test_targets: *test_targets
coverage_flags: *windows_coverage_flags
coverage_targets: *test_targets

# Bazel 7
ubuntu2004_bazel_7:
Expand Down Expand Up @@ -207,6 +219,8 @@ tasks:
test_targets: *test_targets_bazel_6
build_flags: *flags_bazel_less_than_9
test_flags: *flags_bazel_less_than_9
coverage_flags: *windows_coverage_flags_bazel_less_than_9
coverage_targets: *test_targets_bazel_6

# Bazel 9
ubuntu2004:
Expand Down Expand Up @@ -238,6 +252,8 @@ tasks:
bazel: 9.x
build_targets: *build_targets
test_targets: *test_targets
coverage_flags: *windows_coverage_flags
coverage_targets: *test_targets
ubuntu_bzlmod:
name: Ubuntu 20.04 (Bazel 9, bzlmod)
bazel: 9.x
Expand All @@ -250,7 +266,6 @@ tasks:
ubuntu_rule_based_toolchains_bazel_7:
name: Ubuntu rule-based toolchains (Bazel 7)
bazel: 7.2.1
name: Ubuntu rule-based toolchains
platform: ubuntu1804
working_directory: examples/rule_based_toolchain
build_flags:
Expand Down
10 changes: 10 additions & 0 deletions cc/private/coverage/collect_cc_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,17 @@ function main() {
# format by LcovMerger.
# TODO(#5881): Convert profdata reports to lcov.
if uses_llvm; then
if [[ -z "${LLVM_PROFDATA:-}" ]]; then
echo "LLVM_PROFDATA is not set. The toolchain must provide llvm-profdata" \
"in tool_paths to support coverage with clang." >&2
exit 1
fi
if [[ "${GENERATE_LLVM_LCOV}" == "1" ]]; then
if [[ -z "${LLVM_COV:-}" ]]; then
echo "LLVM_COV is not set. The toolchain must provide llvm-cov" \
"in tool_paths to support lcov coverage with clang." >&2
exit 1
fi
BAZEL_CC_COVERAGE_TOOL="LLVM_LCOV"
else
BAZEL_CC_COVERAGE_TOOL="PROFDATA"
Expand Down
7 changes: 7 additions & 0 deletions cc/private/toolchain/unix_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overridden_tools):
if darwin:
overridden_tools["gcc"] = "cc_wrapper.sh"
overridden_tools["ar"] = _find_generic(repository_ctx, "libtool", "LIBTOOL", overridden_tools)
xcrun = repository_ctx.which("xcrun")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keith curious if this is the recommended way to do this. I'd love to avoid invoking xcrun but this toolchain is already unique to the host so feels like it's aligned with the spirit of the toolchain.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the hermetic way to do it would be to make the tools shell scripts that run xcrun llvm-cov and then put the xcode env vars / execution_info on the actions, then the absolute path to xcode would be entirely separated.

as is i think this would make the toolchain sensitive to that path which probably isn't desirable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, definitely not desirable and I can make shell scripts. What do you mean "xcode env vars / execution info" does that currently exist (is that a fragment already)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if xcrun:
for tool_name in ["llvm-cov", "llvm-profdata"]:
if overridden_tools.get(tool_name) == None:
xcrun_result = repository_ctx.execute([xcrun, "--find", tool_name])
if xcrun_result.return_code == 0:
overridden_tools[tool_name] = xcrun_result.stdout.strip()

auto_configure_warning_maybe(repository_ctx, "CC used: " + str(cc))
tool_paths = _get_tool_paths(repository_ctx, overridden_tools)
Expand Down
12 changes: 12 additions & 0 deletions cc/private/toolchain/unix_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ def _impl(ctx):
)
action_configs.append(llvm_cov_action)

llvm_profdata = ctx.attr.tool_paths.get("llvm-profdata")
if llvm_profdata:
llvm_profdata_action = action_config(
action_name = ACTION_NAMES.llvm_profdata,
tools = [
tool(
path = llvm_profdata,
),
],
)
action_configs.append(llvm_profdata_action)

objcopy = ctx.attr.tool_paths.get("objcopy")
if objcopy:
objcopy_action = action_config(
Expand Down