Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Comments

Close side panel

Produce an artifactbundle when making releases #67

Merged
liamnichols merged 4 commits intomainCreateAPI/CreateAPI:mainfrom
ln/artifactbundleCreateAPI/CreateAPI:ln/artifactbundleCopy head branch name to clipboard
Jul 30, 2022
Merged

Produce an artifactbundle when making releases #67
liamnichols merged 4 commits intomainCreateAPI/CreateAPI:mainfrom
ln/artifactbundleCreateAPI/CreateAPI:ln/artifactbundleCopy head branch name to clipboard

Conversation

@liamnichols
Copy link
Member

Related Links

Background

When creating and using Swift Package plugins, there are a couple of ways that you can approach it:

  1. The vendor (or even the consumer) can use the executable's package as a dependency
  2. The consume can add their own .binaryTarget dependency

The second option is great when you don't want to have to concern yourself with potentially complex build pipelines for the build tools given that usually we work with precompiled binaries.

To do this, the vendor needs to provide an artifactbundle as described in [SE-0305](https://github.com/apple/swift-evolution/blob/main/proposals/0305-swiftpm-binary-target-improvements.md).

Changes

In this Pull Request, I do a few things to introduce the bundle:

  1. Update make build so that it produces a universal binary that works on Intel or Apple Silicon Macs
  2. Add a new artifactbundle.sh script that takes a version number and binary path and zips the correctly structured bundle
  3. Add a new make artifactbundle version={VERSION} step
  4. Add a new release workflow that automatically builds and uploads the artifactbundle on every release
  5. Switch to Xcode 13.4.1 (bump up from 13.4) on CI

There is still one last manual step, which is to look for the .zip file SHA in the build log and add it to the release notes, but since writing the release notes remains manual still (I like GitHub's generated contents), I will keep this manual for the time being.


For reference, this enables users of CreateAPI start writing Package.swift files like this:

Package.swift

// swift-tools-version: 5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MyAPIKit",
    products: [
        .library(
            name: "MyAPIKit",
            targets: ["MyAPIKit"]
        )
    ],
    targets: [
        .target(
            name: "MyAPIKit",
            dependencies: [
                .target(name: "CreateAPI")
            ]
        ),
        .binaryTarget(
            name: "create-api",
            url: "https://github.com/liamnichols/CreateAPI/releases/download/0.0.7/create-api.artifactbundle.zip",
            checksum: "9d06c3c737c1a11b073984a4f250a8de0347a3b1d5403b095529f3d93b433e63"
        ),
        .plugin(
            name: "CreateAPI",
            capability: .buildTool(),
            dependencies: [
                .target(name: "create-api")
            ]
        )
    ]
)

And then adding their own plugin like so

Plugins/CreateAPI/Plugin.swift

import Foundation
import PackagePlugin

@main
struct Plugin: BuildToolPlugin {
    func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
        let schema = context.package.directory.appending("schema.yml")
        let config = context.package.directory.appending("create-api.yml")

        return [
            .buildCommand(
                displayName: "Generating OpenAPI",
                executable: try context.tool(named: "create-api").path,
                arguments: [
                    "generate",
                    "--module", target.name,
                    "--config", config,
                    "--output", context.pluginWorkDirectory,
                    schema
                ],
                inputFiles: [
                    schema,
                    config
                ],
                outputFiles: [
                    context.pluginWorkDirectory.appending("Paths.swift"),
                    context.pluginWorkDirectory.appending("Entities.swift")
                ]
            )
        ]
    }
}

Before documenting this, I want to try it out for myself a bit and work out where we need to improve things and what works best since there are a few different approaches that can be used when writing plugins. After merging this and getting a release out though, I'll certainly share some instructions back in the linked ticket.

@liamnichols liamnichols self-assigned this Jul 30, 2022
@liamnichols liamnichols merged commit 9823342 into main Jul 30, 2022
@liamnichols liamnichols deleted the ln/artifactbundle branch July 30, 2022 20:58
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.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.