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

feat(singlejar): Add Log4j plugins cache combiner #22581

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

stevebarrau
Copy link
Contributor

@stevebarrau stevebarrau commented May 29, 2024

In singlejar, add support for combining Log4j2 plugins cache file.

Log4j2 plugins are Java annotations collected by a compiler plugin into .dat files for Log4j2 runtime to find them fast. With correct dependency on a java_plugin, Bazel already runs the java plugin compiler correctly. The behavior is correct on bazel run JAR, but not on _deploy.jar fat jars.

The silent clobbering of files in general, and the example of these Log4j2 .dat files in particular, is discussed in #7330.

I tested this fix in my project using Bazel 7.0.2, compiling //src:java_tools_prebuilt.zip, and overriding @remote_java_tools_darwin_arm64 and @remote_java_tools_linux.

@stevebarrau stevebarrau changed the title feat(singlejar): Add Log4j2Plugins combiner feat(singlejar): Add Log4j plugins cache combiner May 29, 2024
@github-actions github-actions bot added team-Rules-Java Issues for Java rules awaiting-review PR is awaiting review from an assigned reviewer labels May 29, 2024
@sgowroji sgowroji added awaiting-user-response Awaiting a response from the author and removed awaiting-review PR is awaiting review from an assigned reviewer labels May 29, 2024
@stevebarrau
Copy link
Contributor Author

@sgowroji what question do I need to answer for "awaiting-user-response" to get removed?

@softprops @jwilliams-ocient from #7330; does this help the issue for you?

@sgowroji
Copy link
Member

@stevebarrau Could you please take a look at the failing checks?

@stevebarrau stevebarrau force-pushed the singlejar-add-log4j-plugin-cache-combiner branch from 659623f to d8130cb Compare May 30, 2024 09:06
@stevebarrau
Copy link
Contributor Author

@sgowroji PTAL.

@sgowroji sgowroji added awaiting-review PR is awaiting review from an assigned reviewer and removed awaiting-user-response Awaiting a response from the author labels May 30, 2024
@hvadehra
Copy link
Member

cc @cushon

@stevebarrau
Copy link
Contributor Author

Ping @cushon

@meteorcloudy
Copy link
Member

@cushon Can you please take a look?

@cushon
Copy link
Contributor

cushon commented Aug 20, 2024

@hvadehra @meteorcloudy for Blaze we don't need to support log4j, so supporting this isn't a priority for me. I also don't want to stand in the way of progress if you want to support this in Bazel. I left a note in #7330 about the idea of trying to make this kind of thing more pluggable, but there may not be great alternatives to doing it directly in singlejar. If that's something you want to pursue, perhaps the new 'combiner' here could be factored into a separate file and only wired up for Bazel.

return nullptr;
}

void *outputEntryFromBuffer(const std::string filename,
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of extracting this helper, would it be possible to share implementation with Concatenator with composition, similar to what ManifestCombiner does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Composed in e416b51

@@ -284,3 +295,152 @@ void *ManifestCombiner::OutputEntry(bool compress) {
concatenator_->Append("\r\n");
return concatenator_->OutputEntry(compress);
}

template<typename T>
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to move Log4J2PluginDatCombiner into a separate file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted in 8e901f0

@stevebarrau
Copy link
Contributor Author

@cushon I would prefer to author this in Java to reuse the log4j merger logic from existing implementation. Ideally I agree with you if we could provide a set of custom combiners as configuration instead of having to add complexity/features in singlejar this would be very nice.

Where could we start to pry open singlejar and allow external combiners to be configured?

In the short term, if I address the comments, is this something that could live in singlejar until we rollout a configurability mechanism?

@stevebarrau
Copy link
Contributor Author

@shs96c if this ends up being authorable in Java, would https://github.com/bazel-contrib/rules_jvm be a good home for this log4j jar combiner extension?

@shs96c
Copy link
Contributor

shs96c commented Aug 21, 2024

contrib_rules_jvm is too high a level. You might want this in rules_jvm_external so maven artifacts we create are correct, but the only way for this to work with a deploy jar is to have this in rules_Java or wherever singlejar lives.

@stevebarrau stevebarrau force-pushed the singlejar-add-log4j-plugin-cache-combiner branch from 58e985f to 8e901f0 Compare October 1, 2024 08:38
@stevebarrau stevebarrau force-pushed the singlejar-add-log4j-plugin-cache-combiner branch from 3a95585 to 6ae3fb8 Compare October 1, 2024 13:19
@stevebarrau
Copy link
Contributor Author

@cushon PTAL.

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 team-Rules-Java Issues for Java rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants