Skip to content

Cache lld binaries to avoid redundant rebuilds #35

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

Merged
merged 19 commits into from
Nov 3, 2023
Merged

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Oct 31, 2023

Depends on #34.

This proceeds with converting more of the generation steps to a query-based architecture. Now lld doesn't need to be rebuilt if its source directory and build options don't change. This is implemented with a new CMakeBuildQuery, which takes source directory, and build options as arguments, and returns a freshly-built binary that can be cached by the generator engine.

Also renamed DownloadQuery to DownloadArtifactQuery and moved it to a separate file.

In subsequent PRs I'd like to introduce a SQLite-backed cache for storing hashes of generated artifacts. That will help us in avoiding redundant work and will make generator significantly quicker for re-runs that change only a few arguments.
This proceeds with converting more of the generation steps to a query-based architecture. Now `lld` doesn't need to be rebuilt if its source directory and build options don't change.

Also renamed `DownloadQuery` to `DownloadArtifactQuery` and moved it to a separate file.
@MaxDesiatov MaxDesiatov added the enhancement New feature or request label Oct 31, 2023
@MaxDesiatov MaxDesiatov requested a review from euanh October 31, 2023 17:25
let buildDirectory = self.sourcesDirectory.appending("build")
try await Shell.run("ninja", currentDirectory: buildDirectory)

return self.outputBinarySubpath.reduce(into: buildDirectory) { $0.append($1) }
Copy link
Contributor

@euanh euanh Nov 1, 2023

Choose a reason for hiding this comment

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

This seems to me to read more easily and produces the same result, but maybe I'm missing something subtle
.

Suggested change
return self.outputBinarySubpath.reduce(into: buildDirectory) { $0.append($1) }
return buildDirectory.appending(outputBinarySubpath.components)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was mostly about making it explicit that the query takes relative paths as arguments and not absolute ones.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I was reading the docs for FilePath just now and I wondered if that was what you were intending to do, to make sure components such as bin/lld aren't mixed up with full paths.

Copy link
Contributor Author

@MaxDesiatov MaxDesiatov Nov 1, 2023

Choose a reason for hiding this comment

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

I've added a doc comment on that CMakeBuildQuery property explicitly mentioning relative paths, which I hope clarifies things a bit.

@MaxDesiatov MaxDesiatov self-assigned this Nov 1, 2023
let buildDirectory = self.sourcesDirectory.appending("build")
try await Shell.run("ninja", currentDirectory: buildDirectory)

return self.outputBinarySubpath.reduce(into: buildDirectory) { $0.append($1) }
Copy link
Contributor

Choose a reason for hiding this comment

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

The thing that originally drew my attention here was that I found the reduce(into:) hard to read.

The following still seems clearer to me, and it seems to be be able to append [FilePath.Component] - presumably using appending<C>(_ components: C)
https://developer.apple.com/documentation/system/filepath/appending(_:)-60fwk

However it's just a style suggestion, and I think it's fine to merge this now so the generator branch doesn't accumulate too many PRs.

Suggested change
return self.outputBinarySubpath.reduce(into: buildDirectory) { $0.append($1) }
return buildDirectory.appending(self.outputBinarySubpath)

Copy link
Contributor Author

@MaxDesiatov MaxDesiatov Nov 2, 2023

Choose a reason for hiding this comment

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

Great, thanks, I'll update this to make it more readable! I'd be happy to merge after that, but prefer to merge PRs separately, so I need a review on the engine PR at the start of this PR chain: #31

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I wondered if you were going to merge them all back down into max/engine and keep that branch going for a while, but I see you have now addressed Johannes's comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I prefer merging PRs from a stack separately, especially as I stick to "Squash and merge" that allows to preserve history of each PR in separate commits.

Base automatically changed from maxd/engine-downloads to main November 3, 2023 14:09
…/cache-lld

# Conflicts:
#	Package.resolved
#	Package.swift
#	Sources/GeneratorEngine/Cache/CacheKeyProtocol.swift
#	Sources/GeneratorEngine/Cache/FileCacheRecord.swift
#	Sources/GeneratorEngine/Cache/SQLite.swift
#	Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Download.swift
#	Tests/GeneratorEngineTests/EngineTests.swift
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov MaxDesiatov enabled auto-merge (squash) November 3, 2023 14:38
@MaxDesiatov MaxDesiatov merged commit f8a807e into main Nov 3, 2023
@MaxDesiatov MaxDesiatov deleted the maxd/cache-lld branch November 3, 2023 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants