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

Declare exported headers to Bazel to fix bazel build --incompatible_no_implicit_file_export #13982

Merged
merged 2 commits into from
Jun 9, 2023

Conversation

PatriosTheGreat
Copy link
Contributor

@PatriosTheGreat PatriosTheGreat commented Jun 7, 2023

Files exported to other Bazel packages need to be explictly declared with exports_files. This was currently relying on the legacy behavior of implict exporting of inputs to other rules, so this was failing to build with the stricter behavior enabled by --incompatible_no_implicit_file_export.

@ScottTodd ScottTodd requested a review from bjacob June 7, 2023 17:02
Comment on lines 17 to 19
# iree_bitcode_library generates targets on the other package
# we need to expose files used by it.
exports_files(glob(["*.h"]))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you clarify what this fixes? (e.g. share some logs of what failed to build)

I thought some of this code might need to move files around or export files, but I'm wondering why our Bazel CI is happy with what we have if you evidently ran into some issues... maybe a difference between Bazel and Blaze?

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know about exports_files, but reading the documentation now,
https://bazel.build/reference/be/functions#exports_files
it makes sense and the implicit-exporting behavior that we were relying on here is indeed the kind of thing that Bazel would frown upon as sloppy.

The above doc link mentions that --incompatible_no_implicit_file_export gives stricter behavior. I'm trying now locally to check that it does cause Bazel to reject the current code and that this PR fixes that, and I'll report back.

Copy link
Contributor

Choose a reason for hiding this comment

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

Confirmed that --incompatible_no_implicit_file_export exposes the preexisting issue, and that this PR overcomes it - though even with this PR, I can't quite get a successful build with --incompatible_no_implicit_file_export due to a similar issue in the LLVM Bazel build.

Error log with --incompatible_no_implicit_file_export without this PR:

benoitjacob@cloud:~/iree$ bazel build --incompatible_no_implicit_file_export //runtime/src/iree/builtins/ukernel/...
INFO: Invocation ID: 52cac289-252b-476c-b020-314d661dd622
ERROR: /usr/local/google/home/benoitjacob/iree/runtime/src/iree/builtins/ukernel/BUILD.bazel:112:10: in filegroup rule //runtime/src/iree/builtins/ukernel:bitcode_internal_headers: target '//runtime/src/iree/schemas:cpu_data.h' is not visible from target '//runtime/src/iree/builtins/ukernel:bitcode_internal_headers'. Check the visibility declaration of the former target if you think the dependency is legitimate. To set the visibility of that source file target, use the exports_files() function
ERROR: /usr/local/google/home/benoitjacob/iree/runtime/src/iree/builtins/ukernel/BUILD.bazel:112:10: in filegroup rule //runtime/src/iree/builtins/ukernel:bitcode_internal_headers: target '//runtime/src/iree/schemas:cpu_feature_bits.inl' is not visible from target '//runtime/src/iree/builtins/ukernel:bitcode_internal_headers'. Check the visibility declaration of the former target if you think the dependency is legitimate. To set the visibility of that source file target, use the exports_files() function
ERROR: /usr/local/google/home/benoitjacob/iree/runtime/src/iree/builtins/ukernel/BUILD.bazel:112:10: Analysis of target '//runtime/src/iree/builtins/ukernel:bitcode_internal_headers' failed

Error log with --incompatible_no_implicit_file_export with this PR exposing the LLVM issue:

ERROR: /usr/local/google/home/benoitjacob/.cache/bazel/_bazel_benoitjacob/eaaf182bb48fe049228a18968abf1f5f/external/llvm-project/clang/BUILD.bazel:2171:16: in expand_template rule @llvm-project//clang:clang_main: target '@llvm-project//llvm:cmake/modules/llvm-driver-template.cpp.in' is not visible from target '@llvm-project//clang:clang_main'. Check the visibility declaration of the former target if you think the dependency is legitimate. To set the visibility of that source file target, use the exports_files() function
ERROR: /usr/local/google/home/benoitjacob/.cache/bazel/_bazel_benoitjacob/eaaf182bb48fe049228a18968abf1f5f/external/llvm-project/clang/BUILD.bazel:2171:16: Analysis of target '@llvm-project//clang:clang_main' failed

Let's merge this PR and separately address the remaining LLVM issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah let's turn on --incompatible_no_implicit_file_export upstream and here

Copy link
Contributor

Choose a reason for hiding this comment

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

Filed #14020 about that.

@bjacob bjacob changed the title Fix iree_runtime_cc_library used modules visibility. Declare exported headers to Bazel to fix bazel build --incompatible_no_implicit_file_export Jun 7, 2023
@@ -10,6 +10,7 @@

iree_add_all_subdirs()

file(GLOB _GLOB_X_H LIST_DIRECTORIES false RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} CONFIGURE_DEPENDS *.h)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note @ScottTodd , I was initially confused by this line, which creates a _GLOB_X_H variable that's just unused. But it is created by bazel_to_cmake in the lowering of glob, and then it goes unused because exports_files is implemented as pass.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if Python has a concept of macros that could be used instead of functions for the empty-implementation entry points which are currently functions doing pass, so that they could skip evaluating their arguments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think @GMNGeoffrey added that file glob stuff :P

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyway. I say we merge this now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed I did. I kind of think that the entire implementation of bazel->cmake should be constructing objects and then only writing at the end rather than concatenating strings. Then this sort of thing wouldn't happen. This particular behavior is not awesome because CMake globs are not awesome (which is why we have enforce_glob). Although since implementing that I think I concluded that CMake glob was not as bad as everyone made it out to be as long as you use ninja, which supports CONFIGURE_DEPENDS. Ben was seeing some slowness that he attributed to the globbing, but I think it may have been a red herring. Or maybe it was just a matter of scale.

But long aside aside, these globs appear to mostly be globbing like one file. I think we can just list that explicitly or use enforce_glob if we're worried about it falling out of sync.

It's also usually better to use filegroup rather than exports_files. In the case of schemas, for instance, the only place those files are included, they are included together into another filegroup. Should we just make this one a filegroup?

https://github.com/openxla/iree/blob/main/runtime/src/iree/builtins/ukernel/BUILD.bazel#L118

Copy link
Contributor

Choose a reason for hiding this comment

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

oh right, that is the right way. working on it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright, I just pushed a change to this PR, implementing this.

And I've also sent a LLVM diff to address a similar issue in the LLVM overlay,
https://reviews.llvm.org/D152491

So, putting this together, this command actually succeeds:

bazel build --incompatible_no_implicit_file_export //runtime/src/iree/builtins/ukernel/...

@bjacob bjacob merged commit 860026f into iree-org:main Jun 9, 2023
48 checks passed
bjacob added a commit to llvm/llvm-project that referenced this pull request Jun 14, 2023
The Bazel build was relying, for the two files enumerated in this diff, on the legacy implicit-export semantics described here:
https://bazel.build/reference/be/functions#exports_files

This documentation page encourages migrating away from this legacy behavior, and indeed we have a user who reported a Bazel build error and it appears that they were already using the new, stricter behavior:
iree-org/iree#13982
and while examining fixes on our side and trying to get a clean Bazel build, I ran into this similar issue in the LLVM overlay.

It would arguably be cleaner (in the sense of more structured) to rely on `filegroup` to export this, but I am insufficiently familiar with the Clang build (the dependent targets seem to be below Clang) to do this myself. The present `exports_files` solution has the merit of being localized in these few lines here.

Differential Revision: https://reviews.llvm.org/D152491
NatashaKnk pushed a commit to NatashaKnk/iree that referenced this pull request Jul 6, 2023
…no_implicit_file_export` (iree-org#13982)

Files exported to other Bazel packages need to be explictly declared
with
[`exports_files`](https://bazel.build/reference/be/functions#exports_files).
This was currently relying on the legacy behavior of implict exporting
of inputs to other rules, so this was failing to build with the stricter
behavior enabled by `--incompatible_no_implicit_file_export`.

---------

Co-authored-by: Benoit Jacob <benoitjacob@google.com>
nhasabni pushed a commit to plaidml/iree that referenced this pull request Aug 24, 2023
…no_implicit_file_export` (iree-org#13982)

Files exported to other Bazel packages need to be explictly declared
with
[`exports_files`](https://bazel.build/reference/be/functions#exports_files).
This was currently relying on the legacy behavior of implict exporting
of inputs to other rules, so this was failing to build with the stricter
behavior enabled by `--incompatible_no_implicit_file_export`.

---------

Co-authored-by: Benoit Jacob <benoitjacob@google.com>
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.

None yet

4 participants