Hello! I wanted to check in and see if there's been any implementation efforts or design discussion around the concept of "@package imports" recently. I'm asking because I've run some experiments leveraging the awesome new fast dependency scanner which seem promising, and I think explicit module builds could be a good path forward for this feature if there aren't already plans in place. Feel free to ignore all of the following if someone is already working on this though!
What I had in mind was:
-
The swift compiler frontend defines syntax for an
@package
attribute on imports. The contents of the attribute need to parse as a valid argument list, but otherwise no semantic validation occurs in the compiler to avoid baking in too much knowledge of the package description API. -
The fast dependency scanner is extended to collect the module name and
@package
attribute contents and output it alongside the other module dependencies. e.g.@package(url: "https://github.com/jpsim/Yams.git", .branch("releases/1.0")) import Foo
is reported as something like the following by the fast dependency scanner.
"packageDependencies": [
{
"module": "Foo",
"packageDependencyDescription": "(url: \"https://github.com/jpsim/Yams.git\", .branch(\"releases/1.0\"))",
"targetInfo": ...
}
]
-
swift-driver is extended to invoke SPM to build these package imports in a known location instead of managing the build directly. The driver passes on the dependency scanner output. This creates kind of a weird circular dependency between SPM and the driver, but it should be manageable.
-
SPM consumes the dependency scanner output and fetches & builds dependencies. I don't have a clear idea of how this should work yet, but it seems feasible and keeps SPM responsible for most of the details of the package API, etc. This is the point at which the contents of the attribute are semantically validated, possibly by pasting the argument list into SPM's
Package.Dependency
API or something similar. -
swift-driver includes the built package dependencies as explicit modules using the build paths it provided SPM.
I've put together an early proof-of-concept for points 1 & 2 at [Experiment/DNM] @package imports found via fast dependency scanning by owenv · Pull Request #32366 · apple/swift · GitHub which seems viable, but I'd be interested in hearing from SPM experts as to whether this is a good direction and, if so, how it might be implemented it in SPM. If there's interest, I'll look into putting together a production-ready version of the compiler PR to allow prototyping the driver and SPM components.
As always, feedback/comments/questions are welcome! This is just a tiny experiment inspired by some of the other explicit modules work that's been going on, so it might very well end up not being the greatest idea