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 feature to produce indexstore files for CC builds #17984

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

Conversation

BalestraPatrick
Copy link
Member

@BalestraPatrick BalestraPatrick commented Apr 5, 2023

Using the indexstore_files feature will add the -index-store-path flag to C/C++/Objective-C/Objective-C++ compiles, causing a .indexstore tree artifact output to be produced.

Users of this feature might also consider passing -noindex-ignore-system-symbols in order to greatly reduce the size of the indexstore and ignore system symbols.

This is heavily inspired by #15403. I tested this locally in a sample project and it worked fine.

I also prepared a change for the Apple toolchain in apple_support to support this feature: bazelbuild/apple_support@master...BalestraPatrick:apple_support:add-indexstore-files-feature-to-toolchain

This feature is required in order to improve the rules_xcodeproj IDE integration and consume these files for indexing purposes.

Closes #15983.

@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label Apr 5, 2023
@sgowroji sgowroji added team-Rules-CPP Issues for C++ rules team-Rules-ObjC Issues for Objective-C maintainers labels Apr 5, 2023
@lberki lberki requested review from susinmotion and removed request for lberki April 5, 2023 11:27
@lberki
Copy link
Contributor

lberki commented Apr 5, 2023

Susan, mind routing this?

@brentleyjones
Copy link
Contributor

@susinmotion friendly ping

@susinmotion
Copy link
Contributor

@googlewalt is this something in your team's purview?

@buildbreaker2021
Copy link
Contributor

cc @oquenchil

@@ -1497,12 +1497,19 @@ private Artifact createCompileActionTemplate(
CppHelper.getDiagnosticsOutputTreeArtifact(
actionConstructionContext, label, sourceArtifact, outputName, usePic);
}
SpecialArtifact indexstoreTreeArtifact = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would be against having another SpecialArtifact introduced for cc related stuff. Because this is basically un-Starlarkifiable. @oquenchil WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that this should not go in. We shouldn't have any more special casing in native. Someone would need to contribute to move #17237 forward, then this PR should be based on that or some other generic mechanism that doesn't introduce more native code.

No more SpecialArtifacts should be accepted. #17237 and Starlark tree artifacts should provide the necessary APIs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you perhaps know if aspect with shadow actions can support a use case like this? What I mean is, can you copy CcCompileAction in an aspect and add an output to it, that you can collect?

Copy link
Contributor

Choose a reason for hiding this comment

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

That would mean compiling twice, right? (since we can't have our action be depended on by the original compilation?), where just adding the flag and output only causes a small increase in original compilation time.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you use outputs from both actions, then yes, you compile/cache twice. If you need the outputs for IDE only, then you’d compile once. But the regular compile the users probably do/need couldn’t reuse that.

Replacing outputs in CcInfo might be possible within an extended rule if shadow actions were supported there.

I’m a bit conflicted with the idea that you need to have a complete set of new rules to support IDEs. Or even special toolchains.

If only you could split compilation actions away from parsing+index generation for IDEs that would be ideal solution. That is because I’m assuming parsing is an order faster and because those actions can then run in parallel. You redo some work, but the data for IDEs is ready much sooner.

Copy link
Contributor

@brentleyjones brentleyjones Sep 13, 2023

Choose a reason for hiding this comment

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

Not reflected in this PR yet, but @yongjincho92 took the rules_swift implementation of a "global index store" and implemented it for this. That makes it (more) efficient. We also plan on changing it to produce a .tar file instead of a tree artifact, similar to the comment from @DavidGoldman: #15983 (comment) (because that helps with some remote cache performance).

Copy link
Contributor

Choose a reason for hiding this comment

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

"global index store" link seems like it's using a worker. Using a worker makes much more sense, because if I'm not mistaken, you can use a global cache directory for the entire build, that behaves just like expected by clang. It can even read from it. And they are more lax on the hermeticity/sandboxing constraints.

This PR/implementation is touching C++ action that don't have a worker. Bazel has much higher expectations for actions like this. They are executed in a sandbox. I don't see a relation to a worker with this PR. If you implemented a worker, you wouldn't need to pass anything additional parameters to it. Just set an env variable to the path to that directory, or in the toolchain configuration and parse it from IDEs.

Maybe some details are missing? I don't know if it's currently even possible to insert a worker into C++ toolchain.

Choose a reason for hiding this comment

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

I have a pr in apple_support that does adopt how rules_swift did global index store.

Choose a reason for hiding this comment

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

With the change above, I still observed a huge spike in remote cache fetching, so I implemented another change that tars the generated .indexstore directory here

Copy link
Contributor

@brentleyjones brentleyjones Sep 13, 2023

Choose a reason for hiding this comment

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

So after those changes, we just need the ability in Bazel to declare new outputs (like this PR does), though ideally new arguments as well. The outputs need to be declared in order to be cached properly.

Comment on lines +5270 to +5271
ACTION_NAMES.assemble,
ACTION_NAMES.preprocess_assemble,

Choose a reason for hiding this comment

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

@BalestraPatrick
My local clang invocation shows that although clang generates .o files for assemble files (.s and .S), it doesn't generate indexstore files. It just doesn't generate the indexstore files silently. Is assembly file compilation supposed to generate the indexstore file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review PR is awaiting review from an assigned reviewer platform: apple team-Rules-CPP Issues for C++ rules team-Rules-ObjC Issues for Objective-C maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR: Add ability to generate clang indexstore files for CC builds
10 participants