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 support for a prebuilt swift-syntax library for macros #8142

Merged
merged 25 commits into from
Jan 13, 2025

Conversation

dschaefer2
Copy link
Member

Following the pattern used for the early Traits work, added a workspace prebuilts manager to co-ordinate detecting when macros are using swift-syntax, downloading the zip file for the resolved swift-syntax version, and extracting it into the scratch directory. We add the necessary information about that to the workspace state. We then morph the Modules that use it to add build settings to find the necessary modules and libraries.

Following the pattern used for the early Traits work, added a
workspace prebuilts manager to co-ordinate detecting when macros
are using swift-syntax, downloading the zip file for the resolved
swift-syntax version, and extracting it into the scratch directory.
We add the necessary information about that to the workspace state.
We then morph the Modules that use it to add build settings to find
the necessary modules and libraries.
@dschaefer2
Copy link
Member Author

dschaefer2 commented Nov 27, 2024

Also, most inspiration comes from binary artifacts. Still signs of the clone in this PR :).

Still lots of clean up to do including taking advantage of the caching and checking checksums.

And, of course, tests.

dschaefer2 and others added 11 commits November 28, 2024 16:05
This resulted in some minor changes to the prebuilts manifest to
make it easier to build.
Also required renaming of the arm64 arches to aarch64 since that's
what they are called on Windows.
The -l argument translates into a .lib file where we are producing
.a libraries.
We weren't getting called if there was a Package.resolved file
which didn't allow us to refresh things if the user deleted the
scratch folder.
Added generating of the available Linux platforms using docker.
Need to find out why but FileManager couldn't detect tar.exe is
executable causing the AsyncProcess to fail. As a work around for
now, just use the absolute path since it's always in system32.
@dschaefer2 dschaefer2 removed the needs tests This change needs test coverage label Dec 16, 2024
@dschaefer2 dschaefer2 changed the title [WIP] Add support for prebuilt libraries, specifically swift-syntax Add support for prebuilt libraries, specifically swift-syntax Dec 16, 2024
@dschaefer2 dschaefer2 changed the title Add support for prebuilt libraries, specifically swift-syntax Add support for a prebuilt swift-syntax library for macros Dec 16, 2024
Sources/Basics/Archiver/ZipArchiver.swift Outdated Show resolved Hide resolved
Sources/swift-build-prebuilts/main.swift Outdated Show resolved Hide resolved
Sources/swift-build-prebuilts/main.swift Outdated Show resolved Hide resolved
Sources/swift-build-prebuilts/main.swift Outdated Show resolved Hide resolved
Sources/Workspace/ManagedPrebuilt.swift Outdated Show resolved Hide resolved
Sources/Workspace/Workspace+Prebuilts.swift Outdated Show resolved Hide resolved
Sources/Workspace/Workspace+Prebuilts.swift Outdated Show resolved Hide resolved
Sources/Workspace/Workspace+Prebuilts.swift Show resolved Hide resolved
Sources/swift-build-prebuilts/main.swift Outdated Show resolved Hide resolved
Sources/swift-build-prebuilts/main.swift Outdated Show resolved Hide resolved
Copy link
Contributor

@bkhouri bkhouri left a comment

Choose a reason for hiding this comment

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

Sorry for the plethora of comments. The one I think should be resolved have been marked "blocking" or "potentially blocking"

Sources/swift-build-prebuilts/main.swift Outdated Show resolved Hide resolved
Sources/swift-build-prebuilts/main.swift Outdated Show resolved Hide resolved
Sources/swift-build-prebuilts/main.swift Outdated Show resolved Hide resolved
Sources/Basics/Archiver/ZipArchiver.swift Outdated Show resolved Hide resolved
Sources/swift-build-prebuilts/main.swift Outdated Show resolved Hide resolved
Tests/WorkspaceTests/PrebuiltsTests.swift Outdated Show resolved Hide resolved
Tests/WorkspaceTests/PrebuiltsTests.swift Show resolved Hide resolved
Tests/WorkspaceTests/PrebuiltsTests.swift Show resolved Hide resolved
Tests/WorkspaceTests/PrebuiltsTests.swift Show resolved Hide resolved
@dschaefer2
Copy link
Member Author

OK, feels like it's done. Awaiting the tests.

@dschaefer2
Copy link
Member Author

BTW, there will be at least one more PR when I get back from holidays in January to complete the BuildPrebuilts script to add in more docker images and platforms as they come available, and of courses to fix any issues we find during testing, and then to enable this feature by default. I'll post to the forums on how to test with it once this PR finishes review.

@dschaefer2
Copy link
Member Author

All tests pass. Let me know if there's anything else @jakepetroules.

@@ -48,7 +70,9 @@ public struct ZipArchiver: Archiver, Cancellable {
}

#if os(Windows)
let process = AsyncProcess(arguments: ["tar.exe", "xf", archivePath.pathString, "-C", destinationPath.pathString])
// FileManager lost the ability to detect tar.exe as executable.
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if that's related to swiftlang/swift-foundation#860

#if os(Windows)
try await shell("tar -acf \(zipFile.pathString) \(contentDirs.joined(separator: " "))")
#else
try await shell("zip -r \(zipFile.pathString) \(contentDirs.joined(separator: " "))")
Copy link
Contributor

Choose a reason for hiding this comment

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

(non-blocking): Why not just use tar everywhere? I think it's more commonly installed by default than zip is.

Copy link
Contributor

@jakepetroules jakepetroules left a comment

Choose a reason for hiding this comment

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

Looks good, Doug! I don't have any further blocking feedback. Thanks for your patience on the review. :)

I had one last thing I'd like to understand a little better though, before we land this: #8142 (comment)

),
prebuiltsURL: URL(
string:
"https://github.com/dschaefer2/swift-syntax/releases/download"
Copy link
Contributor

Choose a reason for hiding this comment

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

Any thoughts on how we'd provide the ability to override this with eg. a user's own proxy or local path?

Copy link
Member Author

Choose a reason for hiding this comment

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

Something we can think about for testing. Of course we'll put the real URL there once we know what it is. I'll add that to the piece to look at next.

let manifest = manifests.allDependencyManifests[
prebuilt.packageRef.identity
],
let packageVersion = manifest.manifest.version,
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this version 🤔? I might be missing something, but aren't we replacing all swift-syntax dependencies with prebuilts, is version resolution even still happening for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the version we resolved swift-syntax to, e.g. 600.0.1. If there isn't a download for that version we leave things like they are and build from source.

@dschaefer2 dschaefer2 merged commit 99a6e97 into swiftlang:main Jan 13, 2025
5 checks passed
@dschaefer2 dschaefer2 deleted the prebuilts branch January 13, 2025 15:05
dschaefer2 added a commit to dschaefer2/swift-package-manager that referenced this pull request Jan 14, 2025
…#8142)

Following the pattern used for the early Traits work, added a workspace
prebuilts manager to co-ordinate detecting when macros are using
swift-syntax, downloading the zip file for the resolved swift-syntax
version, and extracting it into the scratch directory. We add the
necessary information about that to the workspace state. We then morph
the Modules that use it to add build settings to find the necessary
modules and libraries.

---------

Co-authored-by: Doug Schaefer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants