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 support for layering_check #246

Merged
merged 13 commits into from
Jan 19, 2024

Conversation

fmeum
Copy link
Member

@fmeum fmeum commented Jan 14, 2024

The general support for this feature is inherited from the Bazel-provided Unix C++ toolchain, except that a module map for the toolchain and sysroot headers has to be supplied to the cc_toolchain.

This requires updates of rules_go, abseil-cpp and openssl BUILD file changes to become compatible with the stricter checks. Also fixes CI issues caused by the release of Bazel 7.0.0.

Fixes #203

@fmeum
Copy link
Member Author

fmeum commented Jan 14, 2024

@jsharpe I saw that you were interested in this feature, any kind of testing would be highly appreciated.

@fmeum fmeum force-pushed the layering_check_impl branch 7 times, most recently from 8ce1411 to b1a44e4 Compare January 15, 2024 13:57
@fmeum fmeum marked this pull request as draft January 15, 2024 13:59
@fmeum fmeum force-pushed the layering_check_impl branch 4 times, most recently from 6e9188c to 455bf61 Compare January 16, 2024 07:20
The general support for this feature is inherited from the
Bazel-provided Unix C++ toolchain, except that a module map for the
toolchain and sysroot headers has to be supplied to the `cc_toolchain`.

Requires an update of abseil-cpp to make it compatible with
`layering_check`.
@jsharpe
Copy link
Member

jsharpe commented Jan 16, 2024

@jsharpe I saw that you were interested in this feature, any kind of testing would be highly appreciated.

Yep; I'll try this in the next few days hopefully!

@fmeum fmeum marked this pull request as ready for review January 16, 2024 09:43
`/tmp` is hermetic by default in Bazel 7.
@fmeum
Copy link
Member Author

fmeum commented Jan 17, 2024

@jsharpe The remaining failure appears to be unrelated to the changes in this PR. Have you tested rules_foreign_cc with Bazel 7 and its flip of --incompatible_sandbox_hermetic_tmp yet? It looks like some symlinks dangle with it.

Edit: I looked into this. With --incompatible_sandbox_hermetic_tmp, source files are mounted under a path in the sandbox that doesn't exist outside the sandbox. Since cmake install seems to preserve symlinks if it finds any, the INSTALLDIR will contain these symlinks that are dangling after the action succeeded. Ideally, absolute symlinks would be followed while relative symlinks (e.g. to implement versioned shared libs) would not.

@fmeum
Copy link
Member Author

fmeum commented Jan 17, 2024

@siddharthab After quite a bit of trial and error, this is ready for review now. Let me know if you want me to move the unrelated CI fixes required due to the Bazel 7 release out into a separate PR.

Copy link
Contributor

@siddharthab siddharthab left a comment

Choose a reason for hiding this comment

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

Overall looks good. Let me know if you have the bandwidth to do the changes I have suggested. If not, maybe I can push to your branch. I am going to give some time to the repo this weekend.

Also, thank you so much for working through the nits from Bazel 7 upgrade, and maybe other causes.

README.md Outdated Show resolved Hide resolved
tests/MODULE.bazel Outdated Show resolved Hide resolved
toolchain/cc_toolchain_config.bzl Outdated Show resolved Hide resolved
toolchain/internal/system_module_map.bzl Outdated Show resolved Hide resolved
toolchain/internal/generate_system_module_map.sh Outdated Show resolved Hide resolved
/*) ;;
*) header=${EXECROOT_PREFIX}"${header}" ;;
esac
echo " textual header \"${header}\""
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you really want to echo this line under all cases, i.e. even under the /* case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, added a comment.

toolchain/internal/system_module_map.bzl Outdated Show resolved Hide resolved
doc = """Generates a Clang module map for the toolchain and sysroot headers.""",
implementation = _system_module_map,
attrs = {
"toolchain": attr.label(mandatory = True),
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that it will be better if we renamed this cxx_builtin_include_filegroup or something like that, instead of calling it toolchain. It makes the code easier to read.

Likewise, we should create a separate filegroup target to pass here instead of all-files.

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 renamed the attribute (I chose a files suffix as it wouldn't strictly have to be a filegroup) and introduced a separate filegroup.

toolchain/cc_toolchain_config.bzl Outdated Show resolved Hide resolved
Co-authored-by: Siddhartha Bagaria <[email protected]>
toolchain/internal/generate_system_module_map.sh Outdated Show resolved Hide resolved
/*) ;;
*) header=${EXECROOT_PREFIX}"${header}" ;;
esac
echo " textual header \"${header}\""
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, added a comment.

doc = """Generates a Clang module map for the toolchain and sysroot headers.""",
implementation = _system_module_map,
attrs = {
"toolchain": attr.label(mandatory = True),
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 renamed the attribute (I chose a files suffix as it wouldn't strictly have to be a filegroup) and introduced a separate filegroup.

system_module_map(
name = "module-{suffix}",
cxx_builtin_include_files = ":include-components-{suffix}",
cxx_builtin_include_directories = cxx_builtin_include_directories,
Copy link
Member Author

Choose a reason for hiding this comment

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

@siddharthab Nvm, this is problematic: The builtin include directories are computed in the cc_toolchain_config rule and not available here. I could either extract this into a separate function and pass the result into cc_toolchain_config or have cc_toolchain_config return the information via a provider. That's why I went for the macro in the first place. Maybe you see a better way to pass around this information.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I was thinking that we would compute it outside of the macro (i.e. the BUILD file should already have that info) and pass it in.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@fmeum
Copy link
Member Author

fmeum commented Jan 19, 2024

I tried to use your pipefail suggestion, but that just caused the script to fail.

@siddharthab
Copy link
Contributor

Thank you for all the hard work. This looks very good. I might do some very minor cleanup for nitpicks later. Let's merge this!

@siddharthab siddharthab merged commit 05f0bc1 into bazel-contrib:master Jan 19, 2024
24 checks passed
@fmeum fmeum deleted the layering_check_impl branch January 19, 2024 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support layering_check feature
3 participants