-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Allow TreeArtifacts with any name in Starlark C++ API #8269
Allow TreeArtifacts with any name in Starlark C++ API #8269
Conversation
I found a potential issue with this pull request, although I'm not sure how to resolve it. When compiling C++ source from a TreeArtifact, arguments passed as cxxopts on the command line are not passed to the underlying compile command (although options passed as copts are). I've created a repo here that reproduces the issue. The way the repo works is it tries to pass Using cxxopt:
Using copt:
Note that compiling a single file or renaming the directory to have a ".cpp" extension still passes the correct options.
Please let me know what the best way to address this is. |
@oquenchil friendly bump. |
Hi Kevin, Thank you for the pull request. As you state the API should definitely allow tree artifacts. The problem is that we cannot separate the sources from the headers inside the tree artifact during analysis. I need to look at this more carefully. I will be OOO for a week and a half. The earliest I can take a look at this is on Friday next week. |
Thanks for the response. Yes, that makes sense. I'm not familiar with the Bazel internals, but my understanding is that different actions will be generated for each file in a TreeArtifact, dependent on it's filetype (e.g in generateActionForInputArtifacts). In that case, is there a need to separate the source and headers? |
That was introduced for J2ObjcAspect.java. I'm not sure how well it works for C++ rules and even there if I understand correctly each tree artifact will contain either only headers or only sources. This was introduced because outputs were not predictable. Have you tried using tree artifacts as you propose here with srcs and hdrs in the cc_library rule? If it doesn't work there then it won't work for the C++ Starlark API. If we start supporting this properly it won't be a simple change. We will have to take a lot more into consideration than what the code you linked to does. |
At least for my usecase it worked well enough. The restriction to only headers/source files is annoying, but IMO reasonable.
Haven't tested with HEAD, but at least at one point it did work with cc_library (although using TreeArtifacts with cc_library is broken for me in other ways.) It also worked in pervious versions of the Starlark C++ API.
That's disappointing, but if that's the case I understand. What other things need to be taken into consideration? |
Tree artifacts were added for a specific use case. Of course they are useful for normal C++ rules but they were only an afterthought, so some things weren't taken into account:
That's if we allow tree artifacts in the API where there would be a separate tree artifact for sources and headers. If we allow a tree artifact with mixed files then we get into other problems. As the code is right now I believe we have no other choice but to pass the All in all, tree artifact support for C++ needs be revisited carefully because as they are right now they are supported poorly. I don't want to open the gates in the C++ Starlark API to another source of problems for something that is not properly supported. Be sure that we will work on this in the future though. Meanwhile, I don't encourage you to use it but there is a workaround for your specific use case that my colleague describes here: You could have a separate rule that writes out 2 tree artifacts, each with the extensions |
I'm a bit confused. Currently, there is de facto support for TreeArtifacts in the both the cc_* rules and the Starlark API in the sense that I can pass a TreeArtifact and it works; this pull request isn't intending to change anything other than what names are allowed. It sounds like you're saying that there's a broader problem of some features not supporting TreeArtifacts, in which case either those features should be fixed, or there should be somewhere in the Bazel documentation that explicitly says what isn't supported.
Headers/source files are commonly generated together, so there will have to be a filtering step at some point. As I pointed out in my original request, having this be a separate action is cumbersome and largely unnecessary. It's also already supported by the builtin cc_* rules.
I am aware of this workaround. In fact, I specifically call it out as the thing I was trying to address in my pull request ("the user is required to filter out the sources/headers into their own separately named directories".) Anyways, it sounds like this is being tied up in a larger question of C++ and TreeArtifacts support generally. If you want to deny this pull request on the grounds that extending the current support is a bad idea since it's going to be revisited, that's fine, but I do think additional documentation needs to be added to clearly delineate what is and isn't supported. |
Yes, that's right, they are supported. They started being supported by accident but indeed they do work now with the naming workaround. You are right that we don't want to extend the support without the proper consideration and design that this feature should have had from the very beginning. As I mentioned tree artifacts are buggy and do not work properly with include scanning, modules and header parsing. I hear you and understand that the lack of proper support is a pain. Rest assured we will revisit this eventually. |
What's the status here? |
@oquenchil has there been any progress in support for TreeArtifacts? |
@kkiningh can you rebase please to resolve the conflicts, we will try to merge then |
@sventiffe should be done. Let me know if you need anything else to merge this. |
Sven if you are going to merge this, I think this PR should at least come with an extensive list of tests, including:
And any other test checking ways in which this might introduce bugs. |
I wonder if this MR is abandoned or there still is a chance to have it merged? |
Looks like this was more or less added in 596653d |
Ah-h, great to know! Thank you! |
Oh, I see... Let me try to ask for it. Who knows... |
@kkiningh Do I get it right that with 596653d TreeArtifacts are supported for sources and headers in cc_common.compile but still do not supported in cc_common.link? compilation_outputs returned by cc_common.compile is also a TreeArtifact and when it is fed to cc_common.link it does not understand it. How it supposed to be used then? |
Friendly ping to author and reviewers. |
Since ac5aafa no more validation of header extensions is done. |
In the Starlark C++ API, artifacts are checked for an extension that matches their use (e.g. C++ source files must have a ".cpp" extension or something similar). However, the typical use case for TreeArtifacts results in multiple types of files inside a single directory (e.g. generated C++ source and headers being placed in a single directory.) Since, the current check means a single directory can only be used as either source (with a ".cpp" extension) or header (with a ".h" extension), the user is required to filter out the sources/headers into their own separately named directories, which seems cumbersome.
In practice, I don't know of a good reason why there needs to be a restriction on TreeArtifact filenames in the first place (really the restriction should be on the files contained by the TreeArtifact), so I eliminated the check in that case. This is just a proposed solution though; if there's a better fix (or you think this isn't an issue in the first place) let me know.