Proposal: SPM License Information
Hi, I propose to add license information to Package.swift
and expose that information to packages/projects which depend on the Package.
Most Swift packages already have license information available in their GitHub repo. For application development, it‘s often necessary/a good thing to somehow display the license information to the end-user inside the application.
For this to happen, the developer has to copy the license information (often repetitive text) inside their code and display it in the App.
With my proposal, you can add license information to your swift package.
// swift-tools-version:5.5
import PackageDescription
let package = Package(
name: "dealer",
products: [
.library(name: "Dealer", targets: ["Dealer"]),
],
dependencies: [
.package(url: "https://github.com/apple/example-package-deckofplayingcards.git", from: "3.0.0"),
],
targets: [
.target(
name: "Dealer",
dependencies: ["DeckOfPlayingCards"]),
],
license: .MIT(maintainers: [„flexlixrup“, „swiftlang“])
)
As this information alone isn’t really helpful to the developer, we would also need a way to access the information in code dependent on this package. E.g. Dealer.Metadata.license
could return a preformatted String with the license information already built (or a license struct, whatever the community prefers).
I suppose that would mean that we need to start to expose the Package.swift
information to the dependant of the package. This is currently not the case. IMO this would mean that it is necessary to use macros for this, to create the necessary information at build time, but I’m happy to hear other implementation ideas.
If we develop a way to expose this information, that would open a large amount of new metadata, that can be added to the Package.swift
file and be accessible during compile time, like package versions, etc. I think this could be a good baseline to bring SPM forward. Looking forward to hearing your opinions on this pitch.