-
Notifications
You must be signed in to change notification settings - Fork 39
feat: add ability to cache json responses in-repo #1696
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
base: main
Are you sure you want to change the base?
feat: add ability to cache json responses in-repo #1696
Conversation
@cgrindel @luispadron @jpsim I have to clean up some stuff, maybe add some tests, etc. but I want to get people's thoughts on this before I spend the time on that. We've been using this for a couple months in our Linux -> macOS RBE, and it's been nice. |
@@ -236,7 +269,7 @@ def _declare_pkg_from_dependency(dep, config_pkg, from_package, config_swift_pac | |||
dependencies_index = None, | |||
env = from_package.env, | |||
env_inherit = from_package.env_inherit, | |||
init_submodules = init_submodules, | |||
cached_json_directory = cached_json_directory, init_submodules = init_submodules, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
cached_json_directory = cached_json_directory, init_submodules = init_submodules, | |
cached_json_directory = cached_json_directory, | |
init_submodules = init_submodules, |
Out of curiosity, can you please share more about the performance implications? What is improved and by how much? |
That's actually the least important part. Whatever time is taken up by The important part is being able to force packages to be treated the same regardless of host OS. If you cache the packages on macOS, but build on Linux, they will now use the macOS resolutions. Without this you can run into build issues, like resource bundles missing (as they aren't supported on Linux). This doesn't make things perfect, since you might want to resolve things for Linux as well on Linux. But I think #1547 and possibly extending this caching itself to support multiple OSes would be the solution there. |
Thanks for the details! I don't use RBE for any of my projects, so I'm not directly impacted by the cross-platform caching aspect, so take this with a grain of salt, but wouldn't it be possible for some projects to actually prefer having the platform-specific implementations of I'm also happy if this is something that we just handle if the need arises for it in the future. So I'm ok with this change landing and will gladly take the perf improvements to swift package commands 👍 |
If you don't set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool idea. Should we add a utility to help a client cache their JSON?
@@ -197,7 +206,10 @@ _ALL_ATTRS = dicts.add( | |||
_GIT_ATTRS, | |||
repo_rules.env_attrs, | |||
repo_rules.swift_attrs, | |||
{"version": attr.string(doc = "The resolved version of the package.")}, | |||
{ | |||
"cached_json_directory": attr.string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a doc string.
if debug_json_path: | ||
tmp_path = debug_json_path | ||
else: | ||
tmp_path = paths.join(str(repository_ctx.path(".")), paths.basename(cached_json_path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line length.
if path.startswith("./"): | ||
path = path[2:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be path.removeprefix("./")
?
Besides a performance improvement, it allows cross-platform builds to work (e.g. Linux host building Apple code). Signed-off-by: Brentley Jones <github@brentleyjones.com>
69a9836
to
1f06272
Compare
Claude finished @brentleyjones's task —— View job PR Review: JSON Caching FeatureReviewing this pull request that adds JSON response caching for Swift package commands. This feature aims to improve performance and enable cross-platform builds. Todo List
Analysis Complete - Review Feedback✅ Overall AssessmentThis is a well-implemented feature that addresses a real need for cross-platform builds and performance optimization. The caching mechanism is opt-in, properly integrated across all repository rules, and follows Bazel best practices. 🔧 Bazel Rule Implementation & Best PracticesStrengths:
Areas for Improvement:
🚀 Swift Package Handling CorrectnessImplementation Analysis:
Path Handling in if path.startswith("./"):
path = path[2:] @cgrindel's suggestion to use 🏗️ Build File Generation LogicStrengths:
Potential Concerns:
⚡ Performance ConsiderationsBenefits:
Implementation Efficiency:
🔒 Security ConsiderationsFile System Access:
Cross-Platform Implications:
🧪 Test Coverage AnalysisCurrent State:
Recommended Test Coverage:
📚 Documentation NeedsMissing Documentation:
🔍 Code Quality IssuesHigh Priority:
Medium Priority:
🎯 Specific Recommendations
🏁 ConclusionThis is a valuable feature that addresses real cross-platform build challenges. The implementation is sound and follows Bazel best practices. While there are opportunities for improvement in documentation and testing, the core functionality is well-designed and should provide significant benefits for users requiring cross-platform Swift package builds. Recommendation: Approve with minor revisions - primarily documentation improvements and test coverage additions. |
Besides a performance improvement, it allows cross-platform builds to work (e.g. Linux host building Apple code).