mono0926 / LicensePlist

A license list generator of all your dependencies for iOS applications
https://www.slideshare.net/mono0926/licenseplist-a-license-list-generator-of-all-your-dependencies-for-ios-applications
MIT License
2.43k stars 146 forks source link

Add binary target to package definition #210

Closed vladvlasov256 closed 1 year ago

vladvlasov256 commented 1 year ago

Description

Nowadays Xcode can't use executable targets for Build Tool plugins. As a workaround, plugins may use binary targets.

The definition of a binary target is straightforward. But automatic uploads require some additional setup.

Also, Xcode needs an artifact with a valid checksum to resolve the package dependencies. Thus the first artifact should be uploaded to GitHub manually.

Solution

Target definition

.binaryTarget(
    name: "LicensePlistBinary",
    url: "https://github.com/mono0926/LicensePlist/releases/download/3.24.1/LicensePlistBinary-macos.artifactbundle.zip",
    checksum: "16ec69bf7d0515f8be3970201f13730d39ad55fffd40c7765f40193eedf54e83"
 )

LicensePlistBinary – the name of the target, the future plugins will use this name. url – direct URL to download bundle artifact. checksum – SHA-256 hash of the artifact.

The pushed URL and checksum are specified as an example. The artifact doesn't exist and it isn't uploaded.

Bundle content

The bundle artifact should be a zip archive. It includes:

Bundle artifact content in Finder app

The metadata includes the artifact name, path, and supported platforms.

{
    "schemaVersion": "1.0",
    "artifacts": {
        "license-plist": {
            "version": "3.24.1",
            "type": "executable",
            "variants": [
                {
                    "path": "license-plist-3.24.1-macos/bin/license-plist",
                    "supportedTriples": ["x86_64-apple-macosx", "arm64-apple-macosx"]
                }
            ]
        }
    }
}

Automatization

What should the release script do to upload bundle artifacts to GitHub?

  1. Build a release binary.
  2. Prepare metadata in info.json including the updated version.
  3. Copy the license file.
  4. Compress files from steps 1-3 to a zip archive.
  5. Update URL and checksum in Package.swift accordingly to a new release.
  6. Push Package.swift with updated information.
  7. Upload the archive.

Chicken or the egg problem

The pushed code can't be even built by Xcode because of the binary target with the missed artifact.

This could be solved by @mono0926. Unfortunately, the fix requires some manual work.

To upload the first bundle artifact the maintainer need:

  1. Comment binaryTarget(...) definition in Package.swift.
  2. Run make spm_artifactbundle_macos to create an archive.
  3. Next, I think the simplest way is to add it to files of the latest release.
  4. Calculate the checksum: shasum -a 256 LicensePlistBinary-macos.artifactbundle.zip.
  5. In this PR, either you or I need to update the checksum in the target definition.

Upcoming releases might upload bundle artifacts automatically.

Fixes

mono0926 commented 1 year ago

@vladvlasov256

Thanks, released 👍 https://github.com/mono0926/LicensePlist/releases/tag/3.24.2