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 #22259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

keith
Copy link
Member

@keith keith commented May 6, 2024

There were 2 things with the previous implementation that needed to be improved here:

  1. Apple Clang has a bug where it doesn't pass module compiler flags to the underlying -cc1 invocation, so we have to manually pass them directly to that invocation with -Xclang
  2. The previous search script was too aggressive and slow for macOS. The macOS SDK has tons of files that aren't headers, and tons of symlinks pointing to other files within the SDK. This adds a fork in the script to run a version that works with Apple SDKs. The time difference on my machine is 41s->6s. 6s is still pretty long so if desired we can put this behavior behind an env var for users to opt in with.

I've added a hermetic version of this to the apple_support toolchain, but similar to the Linux setup here the modulemap file includes absolute paths.

@keith keith requested a review from fmeum May 6, 2024 20:11
@github-actions github-actions bot added team-Rules-CPP Issues for C++ rules awaiting-review PR is awaiting review from an assigned reviewer labels May 6, 2024
Copy link
Collaborator

@fmeum fmeum left a comment

Choose a reason for hiding this comment

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

You need to run this target to update the lockfile:

name = "update_default_lock_file",

Looks good! The faster find wouldn't work on Linux, so the amount of "fork"ing looks just right.

@keith keith force-pushed the ks/add-layering_check-support-for-macos branch 6 times, most recently from 67c225a to d0cdc1d Compare May 6, 2024 22:07
@keith keith force-pushed the ks/add-layering_check-support-for-macos branch from d0cdc1d to e59f370 Compare May 14, 2024 20:03
@keith
Copy link
Member Author

keith commented May 14, 2024

@pzembrod could you take a look? 🙏🏻

@pzembrod
Copy link
Contributor

@keith I left a few comments on your push, because apparently GitHub's UI succeeded in confusing me. ;-)

@comius
Copy link
Contributor

comius commented May 15, 2024

@keith I left a few comments on your push, because apparently GitHub's UI succeeded in confusing me. ;-)

I can't find the comments, but I'm ok if @keith can.

@comius comius added awaiting-user-response Awaiting a response from the author and removed awaiting-review PR is awaiting review from an assigned reviewer labels May 15, 2024
@brentleyjones
Copy link
Contributor

@comius here: e59f370

tools/cpp/unix_cc_toolchain_config.bzl Outdated Show resolved Hide resolved
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

This was disabled before on MacOS because it was too slow?

Copy link
Member Author

Choose a reason for hiding this comment

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

correct

tools/cpp/generate_system_module_map.sh Outdated Show resolved Hide resolved
@@ -144,11 +144,6 @@ EOF
}

function test_bazel_layering_check() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking: the related test/feature test_bazel_layering_check_header_only() still doesn't work on MacOS?

Copy link
Member Author

Choose a reason for hiding this comment

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

i didn't want to change it in this PR too since it's unrelated, but I think we can enable it afterwards #22370

Copy link
Contributor

Choose a reason for hiding this comment

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

sgtm

@pzembrod
Copy link
Contributor

I moved my comments over to the PR

There were 2 things with the previous implementation that needed to be
improved here:

1. Apple Clang has a bug where it doesn't pass module compiler flags to
   the underlying -cc1 invocation, so we have to manually pass them
   directly to that invocation with -Xclang
2. The previous search script was too aggressive and slow for macOS. The
   macOS SDK has tons of files that aren't headers, and tons of symlinks
   pointing to other files within the SDK. This adds a fork in the
   script to run a version that works with Apple SDKs. The time
   difference on my machine is 41s->6s. 6s is still pretty long so if
   desired we can put this behavior behind an env var for users to opt
   in with.

I've added a hermetic version of this to the apple_support toolchain,
but similar to the Linux setup here the modulemap file includes absolute
paths.
@keith keith force-pushed the ks/add-layering_check-support-for-macos branch from e59f370 to 0286a53 Compare May 15, 2024 19:24
@keith keith requested a review from pzembrod May 15, 2024 19:24
@@ -144,11 +144,6 @@ EOF
}

function test_bazel_layering_check() {
Copy link
Contributor

Choose a reason for hiding this comment

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

sgtm

@pzembrod pzembrod added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-user-response Awaiting a response from the author labels May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally team-Rules-CPP Issues for C++ rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants