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

Add binary target to package definition #210

Merged
merged 10 commits into from
Mar 9, 2023

Conversation

vladvlasov256
Copy link
Contributor

@vladvlasov256 vladvlasov256 commented Feb 24, 2023

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:

  • info.json with metadata,
  • license,
  • fat binary for x86 and arm64.

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

  • binary target added to Package.swift definition,
  • added spm_artifactbundle_macos task to Makefile,
  • TEMPORARY_FOLDER folder path changed to a more general one,
  • build and build_portable depend on clean,
  • clean removes the temporary folder,
  • added get-version script to determine the package version inside make command,
  • added bundle artifact metadata template,
  • added update-artifact-bundle.sh to automatically update URL and checksum,
  • in release.sh added commands to make and upload bundle artifacts, and to push updated Package.swift file.

@vladvlasov256 vladvlasov256 marked this pull request as ready for review February 24, 2023 21:46
@mono0926 mono0926 merged commit 61bc2d3 into mono0926:main Mar 9, 2023
@mono0926
Copy link
Owner

mono0926 commented Mar 9, 2023

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.

2 participants