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

[Suggestion] Add support for the new SPM build plugins #1023

Closed
BrentMifsud opened this issue Feb 4, 2022 · 16 comments
Closed

[Suggestion] Add support for the new SPM build plugins #1023

BrentMifsud opened this issue Feb 4, 2022 · 16 comments

Comments

@BrentMifsud
Copy link

Apple just announced that the new SPM build commands is going to be available in the next version of xcode. Its currently in beta, but adding support for this feature would be an awesome addition to Sourcery

Swift Package Manager
New Features
Swift Packages now support build tool plugins, as defined in [SE-0303](https://github.com/apple/swift-evolution/blob/main/proposals/0303-swiftpm-extensible-build-tools.md) and [SE-0325](https://github.com/apple/swift-evolution/blob/main/proposals/0325-swiftpm-additional-plugin-apis.md). This allows packages to define plugins that can specify tools that should run during a build operation, for example to generate source code. This is supported in both swift package and in Xcode’s support for packages. (79876749)

The swift package command now supports command plugins, as defined in [SE-0332](https://github.com/apple/swift-evolution/blob/main/proposals/0332-swiftpm-command-plugins.md). This allows Packages to define commands that can be invoked using the swift package command line to perform custom actions on the package. (82895553)
@BrentMifsud BrentMifsud changed the title [Suggestion] Add support for the new SPM build tooling [Suggestion] Add support for the new SPM build plugins Feb 4, 2022
@krzysztofzablocki
Copy link
Owner

krzysztofzablocki commented Feb 7, 2022

@BrentMifsud until they support r-Path rewrites you can't build Sourcery properly with SPM only

@pchmelar
Copy link
Contributor

Is this possible now (after changes in #1037) ? 🤔

@krzysztofzablocki
Copy link
Owner

yeah it should be possible now, anyone wants to contribute that integration? 😉
I'm pretty low on having personal time between work and conferences

@cal-os
Copy link

cal-os commented Jun 25, 2022

+1 would love to see this as a feature with apple's new plugin build tool system

@doozMen
Copy link

doozMen commented Jul 7, 2022

I would love to work on this and might be very interesting in my project at work. It would be my first time contributing. Any tips before I start?

@krzysztofzablocki
Copy link
Owner

@doozMen 🙇 shouldn't require anything special given Sourcery now builds purely with SPM. The 2 WWDC sessions about plugins cover everything I think, but if you run into issues you can report here and I can get Apple folks to look at it if we can't figure it out ourselves

@cal-os
Copy link

cal-os commented Jul 7, 2022

I got this working locally in my own package by wrapping the sourcery-1.8.1-macos executable inside the new(ish) swift artifact bundles for both build commands and command tools (https://theswiftdev.com/introduction-to-spm-artifact-bundles/). @doozMen would happily switch over to plugins provided by the sourcery package instead, or if you want, I can take a shot at it unless you want to first!

@pkurzok
Copy link

pkurzok commented Jul 11, 2022

I was trying out building a Command Plugin using Sourcery as a dependency. But I get the following error when the Packages are resolved:

error: multiple targets named 'lib_InternalSwiftSyntaxParser' in: 'sourcery', 'swiftlint'

My Package File looks like this:

let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/krzysztofzablocki/Sourcery", branch: "master")
    ],
    targets: [
      ...
        .plugin(name: "MockGeneratorPlugin",
                ...
                dependencies: [
                    .product(name: "sourcery", package: "Sourcery")
                ])
    ])

Any ideas what could be the issue and how to fix it?

@krzysztofzablocki
Copy link
Owner

I see SwiftLint also uses static swift syntax release workaround, but not sure how the 2 are related, we don't need SwiftLint in this project, I wonder if it's any related dependency, are you brining in SwiftLint in that project @pkurzok ?

@pkurzok
Copy link

pkurzok commented Jul 11, 2022

In the Plugin I'm building Sourcery is literaly the only dependency I'm using. In the project where I'm using the plugin, there is also no direct SwiftLint dependency also dont see it in the package list. I'm wondering where it comes from.

Although I have it installed on my machine. But that shouldn't make any difference, does it?

@krzysztofzablocki
Copy link
Owner

@pkurzok it shouldn't, I wonder if any of the dependencies of Sourcery has SwiftLint added to it's package

@pkurzok
Copy link

pkurzok commented Jul 11, 2022

Found it: stencilswiftkit depends on komondor and they depend on swiftlint.

Nice tool for that: https://swift-dependency-graph.opticalaberration.com

@doozMen
Copy link

doozMen commented Jul 14, 2022

I will follow up on this later cool you guys picked this up already. Will have more time end of July.

@doozMen
Copy link

doozMen commented Jul 20, 2022

I have found a workable solution for using swiftgen which uses sourcery too I guess. It relies on providing a build artifact. This is very nice explained in SwiftGen/SwiftGen#926. Making sourcery available in a simular way would be a good way to do it.

The problem happens when you do not expose it as a build artefact that if you apply it to a target for iOS, which a lot will do, then it will try to build sourcery for a simulator target 🥴 which you do not want.

I do not have the time now to make sourcery build into a build artifact nor do I know if somebody did already attempt this kind of thing?

@krzysztofzablocki
Copy link
Owner

yeah so @pol-piella is taking this over, and this is superseded by #1090

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

No branches or pull requests

7 participants