Meet Swift Package plugins

RSS for tag

Discuss the WWDC22 Session Meet Swift Package plugins

Posts under wwdc2022-110359 tag

6 Posts

Post

Replies

Boosts

Views

Activity

plugin targets missing from swift-format dependency
So I've added swift-format as one of my dependencies to my own swift package so that I can use their lint swift package plugin. Here is my Package.swift: // swift-tools-version: 5.7 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "EssentialFeed", platforms: [ .iOS(.v16), .macOS(.v13), .macCatalyst(.v16), .tvOS(.v16), .watchOS(.v9) ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( name: "EssentialFeed", targets: ["EssentialFeed"]), .library( name: "EssentialFeedTestHelpers", targets: ["EssentialFeedTestHelpers"]), ], dependencies: [ .package(url: "https://github.com/apple/swift-format", .upToNextMajor(from: "0.50700.1")), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "EssentialFeed", dependencies: [], plugins: [ .plugin(name: "LintPlugin", package: "swift-format"), .plugin(name: "FormatPlugin", package: "swift-format"), ] ), .target( name: "EssentialFeedTestHelpers", dependencies: []), .testTarget( name: "EssentialFeedTests", dependencies: ["EssentialFeed", "EssentialFeedTestHelpers"]), .testTarget( name: "EssentialFeedAPIEndToEndTests", dependencies: ["EssentialFeed", "EssentialFeedTestHelpers"]), ] ) I get the following error when pulling this package: product 'LintPlugin' required by package 'essentialfeed' target 'EssentialFeed' not found in package 'swift-format'. But if you look at swift-format's Package.swift, you can see the plugins exist.
1
0
1.4k
Feb ’24
New File Creation using Command Plugin under project directory
Hi team,    I am working with CommandPlugin and with the help of command plugin I can able to create files inside my Package directory but I want to create a file in my project directory but whenever I try to create new file outside Package directory it is saying like there is no permission to create a file in this folder. Is this possible to create new file inside project directory using CommandPlugin ? Can you please help me for this ? I am struggling on this more than a week. Eagerly waiting for you kind support. Thank you so much. Scenario, 1.Able to Crete new file inside Package directory, 2.Facing permission issues - while creating new files inside project directory with the help of CommandPlugin Issue: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file file.txt in the folder ProjectFolder
0
0
756
Oct ’22
Can Build Plugin Commands Run in Parallel? - Xcode14 Beta
I am using a pre-build plugin with the Xcode 14 beta to verify cer files are in the correct format before every build. The code loops through the files the same way as this wwdc video: https://developer.apple.com/videos/play/wwdc2022/110401/ None of the commands have dependancies on each other so it should be running parallel if possible, but the build timeline shows the returned commands are all run serially. are there any changes I could make to parallelize them?     Here is a snippet of the code returning the commands as described! return try target.sourceFiles(withSuffix: "cer").map { file in           .prebuildCommand(             displayName: "Validate Cer is running",              executable: try context.tool(named: "verify-file").path,             arguments: [file.path],             outputFilesDirectory: verifOutputsDir           )       } Thanks for the help!
0
0
726
Aug ’22
XcodeBuildToolPlugin not available in XcodeProjectPlugin
For WWDC22 session "Meet Swift Package plugins " the following code snipped is shared in Apple's Developer application: In Xcode 14 Beta 1 I receive the compilation error Cannot find type 'XcodeBuildToolPlugin' in scope Is the given example valid and is a struct/type missing in the new library module XcodeProjectPlugin ? Or needs the example code to be adjusted (further then I bug I mentioned below in the comments)? import PackagePlugin @main struct MyPlugin: BuildToolPlugin {? /// This entry point is called when operating on a Swift package. func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] debugPrint(context) // BUG: needs to return an array !!!!!!!!!!!!!!!!!!!!!! } } #if canImport(XcodeProjectPlugin) import XcodeProjectPlugin extension MyPlugin: XcodeBuildToolPlugin { /// This entry point is called when operating on an Xcode project. func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] debugPrint(context) return [] } } #endif
2
0
2.3k
Jul ’22
plugin targets missing from swift-format dependency
So I've added swift-format as one of my dependencies to my own swift package so that I can use their lint swift package plugin. Here is my Package.swift: // swift-tools-version: 5.7 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "EssentialFeed", platforms: [ .iOS(.v16), .macOS(.v13), .macCatalyst(.v16), .tvOS(.v16), .watchOS(.v9) ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( name: "EssentialFeed", targets: ["EssentialFeed"]), .library( name: "EssentialFeedTestHelpers", targets: ["EssentialFeedTestHelpers"]), ], dependencies: [ .package(url: "https://github.com/apple/swift-format", .upToNextMajor(from: "0.50700.1")), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "EssentialFeed", dependencies: [], plugins: [ .plugin(name: "LintPlugin", package: "swift-format"), .plugin(name: "FormatPlugin", package: "swift-format"), ] ), .target( name: "EssentialFeedTestHelpers", dependencies: []), .testTarget( name: "EssentialFeedTests", dependencies: ["EssentialFeed", "EssentialFeedTestHelpers"]), .testTarget( name: "EssentialFeedAPIEndToEndTests", dependencies: ["EssentialFeed", "EssentialFeedTestHelpers"]), ] ) I get the following error when pulling this package: product 'LintPlugin' required by package 'essentialfeed' target 'EssentialFeed' not found in package 'swift-format'. But if you look at swift-format's Package.swift, you can see the plugins exist.
Replies
1
Boosts
0
Views
1.4k
Activity
Feb ’24
Provide input to SPM Plugin from Host App
Hi, Is there a way to provide input from a spm package plug-in, from the host app that integrates it ? I see there is no way to access the host target (although the plugin has access to the package target). Is that possible with the current status quo ?
Replies
0
Boosts
0
Views
713
Activity
Mar ’23
New File Creation using Command Plugin under project directory
Hi team,    I am working with CommandPlugin and with the help of command plugin I can able to create files inside my Package directory but I want to create a file in my project directory but whenever I try to create new file outside Package directory it is saying like there is no permission to create a file in this folder. Is this possible to create new file inside project directory using CommandPlugin ? Can you please help me for this ? I am struggling on this more than a week. Eagerly waiting for you kind support. Thank you so much. Scenario, 1.Able to Crete new file inside Package directory, 2.Facing permission issues - while creating new files inside project directory with the help of CommandPlugin Issue: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file file.txt in the folder ProjectFolder
Replies
0
Boosts
0
Views
756
Activity
Oct ’22
Can Build Plugin Commands Run in Parallel? - Xcode14 Beta
I am using a pre-build plugin with the Xcode 14 beta to verify cer files are in the correct format before every build. The code loops through the files the same way as this wwdc video: https://developer.apple.com/videos/play/wwdc2022/110401/ None of the commands have dependancies on each other so it should be running parallel if possible, but the build timeline shows the returned commands are all run serially. are there any changes I could make to parallelize them?     Here is a snippet of the code returning the commands as described! return try target.sourceFiles(withSuffix: "cer").map { file in           .prebuildCommand(             displayName: "Validate Cer is running",              executable: try context.tool(named: "verify-file").path,             arguments: [file.path],             outputFilesDirectory: verifOutputsDir           )       } Thanks for the help!
Replies
0
Boosts
0
Views
726
Activity
Aug ’22
XcodeBuildToolPlugin not available in XcodeProjectPlugin
For WWDC22 session "Meet Swift Package plugins " the following code snipped is shared in Apple's Developer application: In Xcode 14 Beta 1 I receive the compilation error Cannot find type 'XcodeBuildToolPlugin' in scope Is the given example valid and is a struct/type missing in the new library module XcodeProjectPlugin ? Or needs the example code to be adjusted (further then I bug I mentioned below in the comments)? import PackagePlugin @main struct MyPlugin: BuildToolPlugin {? /// This entry point is called when operating on a Swift package. func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] debugPrint(context) // BUG: needs to return an array !!!!!!!!!!!!!!!!!!!!!! } } #if canImport(XcodeProjectPlugin) import XcodeProjectPlugin extension MyPlugin: XcodeBuildToolPlugin { /// This entry point is called when operating on an Xcode project. func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] debugPrint(context) return [] } } #endif
Replies
2
Boosts
0
Views
2.3k
Activity
Jul ’22
Key Binding in Xcode to trigger command plugin?
Command Plugin(s), if available, can be triggered from "File" menu. Is it possible to define a key binding in Xcode to trigger a command plugin more conveniently? Same is possible for Xcode Extensions today.
Replies
1
Boosts
0
Views
1.7k
Activity
Jun ’22