Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add layering_check support for macOS #22475

Closed
Closed
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
1 change: 0 additions & 1 deletion .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ tasks:
# To run any of the following test in presubmit, just comment out the corresponding line.
# TODO(pcloudy): Disable the android tests after enabling them on Apple Silicon platform.
- "-//src/test/shell/bazel:bazel_bootstrap_distfile_test"
- "-//src/test/shell/bazel:bazel_bootstrap_distfile_tar_test"
# - "-//src/test/shell/bazel/android:android_integration_test"
# - "-//src/test/shell/bazel/android:android_integration_test_with_head_android_tools"
- "-//src/test/shell/bazel:bazel_proto_library_test"
Expand Down
8 changes: 8 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ local_path_override(
path = "./third_party/googleapis",
)

single_version_override(
module_name = "grpc",
patch_strip = 1,
patches = [
"//third_party/grpc:00_disable_layering_check.patch",
],
)

# The following Bazel modules are not direct dependencies for building Bazel,
# but are required for visibility from DIST_ARCHIVE_REPOS in repositories.bzl
bazel_dep(name = "apple_support", version = "1.8.1")
Expand Down
67 changes: 37 additions & 30 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/test/shell/bazel/bazel_layering_check_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ EOF
}

function test_bazel_layering_check() {
if is_darwin; then
echo "This test doesn't run on Darwin. Skipping."
return
fi

local -r clang_tool=$(which clang)
if [[ ! -x ${clang_tool:-/usr/bin/clang_tool} ]]; then
echo "clang not installed. Skipping test."
Expand Down
19 changes: 14 additions & 5 deletions tools/cpp/generate_system_module_map.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# Copyright 2020 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,10 +17,19 @@ set -eu

echo 'module "crosstool" [system] {'

for dir in $@; do
find -L "${dir}" -type f 2>/dev/null | LANG=C sort | uniq | while read header; do
echo " textual header \"${header}\""
if [[ "$OSTYPE" == darwin* ]]; then
for dir in $@; do
find "$dir" -type f \( -name "*.h" -o -name "*.def" -o -path "*/c++/*" \) \
| LANG=C sort -u | while read -r header; do
echo " textual header \"${header}\""
done
done
done
else
for dir in $@; do
find -L "${dir}" -type f 2>/dev/null | LANG=C sort -u | while read -r header; do
echo " textual header \"${header}\""
done
done
fi

echo "}"
2 changes: 1 addition & 1 deletion tools/cpp/unix_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
["/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"],
)

generate_modulemap = is_clang and not darwin
generate_modulemap = is_clang
if generate_modulemap:
repository_ctx.file("module.modulemap", _generate_system_module_map(
repository_ctx,
Expand Down
12 changes: 7 additions & 5 deletions tools/cpp/unix_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _target_os_version(ctx):
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
return xcode_config.minimum_os_for_platform_type(platform_type)

def layering_check_features(compiler):
def layering_check_features(compiler, is_macos):
if compiler != "clang":
return []
return [
Expand All @@ -53,8 +53,10 @@ def layering_check_features(compiler):
],
flag_groups = [
flag_group(
flags = [
# macOS requires -Xclang because of a bug in Apple Clang
flags = (["-Xclang"] if is_macos else []) + [
"-fmodule-name=%{module_name}",
] + (["-Xclang"] if is_macos else []) + [
"-fmodule-map-file=%{module_map_file}",
],
),
Expand Down Expand Up @@ -86,7 +88,7 @@ def layering_check_features(compiler):
]),
flag_group(
iterate_over = "dependent_module_map_files",
flags = [
flags = (["-Xclang"] if is_macos else []) + [
"-fmodule-map-file=%{dependent_module_map_files}",
],
),
Expand Down Expand Up @@ -1487,7 +1489,7 @@ def _impl(ctx):
unfiltered_compile_flags_feature,
treat_warnings_as_errors_feature,
archive_param_file_feature,
] + layering_check_features(ctx.attr.compiler)
] + layering_check_features(ctx.attr.compiler, is_macos = False)
else:
# macOS artifact name patterns differ from the defaults only for dynamic
# libraries.
Expand Down Expand Up @@ -1528,7 +1530,7 @@ def _impl(ctx):
treat_warnings_as_errors_feature,
archive_param_file_feature,
generate_linkmap_feature,
]
] + layering_check_features(ctx.attr.compiler, is_macos = True)

parse_headers_action_configs, parse_headers_features = parse_headers_support(
parse_headers_tool_path = ctx.attr.tool_paths.get("parse_headers"),
Expand Down
Loading