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

Adds Swift version support #4

Merged
merged 5 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Example/Packages/Example/Example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
".iOS(.v15)",
".macOS(.v13)"
],
"swiftLanguageVersions": [
{
"version": "5.10",
"isToolsVersion": true
},
{
"version": "6.0"
}
],
"products": [
{
"productType": "library",
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ Packages should be contained in respective folders inside a packages folder and
```json
{
"name": "Example",
"swiftLanguageVersions": [
{
"version": "5.10",
"isToolsVersion": true
},
{
"version": "6.0"
}
],
"products": [
{
"name": "Example",
Expand Down
3 changes: 2 additions & 1 deletion Sources/Core/SpecGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ final class SpecGenerator {
products: partialSpec.products,
targets: partialSpec.targets,
localBinaryTargets: partialSpec.localBinaryTargets,
remoteBinaryTargets: partialSpec.remoteBinaryTargets)
remoteBinaryTargets: partialSpec.remoteBinaryTargets,
swiftLanguageVersions: partialSpec.swiftLanguageVersions)
}

private func specURL(for packageName: PackageName) -> URL {
Expand Down
13 changes: 11 additions & 2 deletions Sources/Models/Spec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct Spec: Decodable {
let targets: [Target]
let localBinaryTargets: [LocalBinaryTarget]?
let remoteBinaryTargets: [RemoteBinaryTarget]?
let swiftLanguageVersions: [SwiftLanguageVersion]?

init(name: PackageName,
platforms: [String]?,
Expand All @@ -21,7 +22,8 @@ struct Spec: Decodable {
products: [Product],
targets: [Target],
localBinaryTargets: [LocalBinaryTarget]? = nil,
remoteBinaryTargets: [RemoteBinaryTarget]? = nil) {
remoteBinaryTargets: [RemoteBinaryTarget]? = nil,
swiftLanguageVersions: [SwiftLanguageVersion]? = nil) {
self.name = name
self.platforms = platforms
self.localDependencies = localDependencies
Expand All @@ -30,6 +32,7 @@ struct Spec: Decodable {
self.targets = targets
self.localBinaryTargets = localBinaryTargets
self.remoteBinaryTargets = remoteBinaryTargets
self.swiftLanguageVersions = swiftLanguageVersions
}
}

Expand All @@ -43,7 +46,8 @@ extension Spec {
"products": products,
"targets": targets,
"local_binary_targets": localBinaryTargets,
"remote_binary_targets": remoteBinaryTargets
"remote_binary_targets": remoteBinaryTargets,
"swift_versions": swiftLanguageVersions
]
return values.compactMapValues { $0 }
}
Expand Down Expand Up @@ -190,3 +194,8 @@ struct RemoteBinaryTarget: Decodable {
let url: String
let checksum: String
}

struct SwiftLanguageVersion: Decodable {
let version: String
let isToolsVersion: Bool?
}
19 changes: 18 additions & 1 deletion Templates/Package.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@
checksum: "{{ target.checksum }}"
),
{% endmacro %}
{% if swift_versions %}
{% for swift_version in swift_versions %}
{% if swift_version.isToolsVersion %}
// swift-tools-version: {{ swift_version.version }}
{% endif %}
{% endfor %}
{% else %}
// swift-tools-version: 5.7
{% endif %}

// This file was automatically generated by PackageGenerator and untracked
// PLEASE DO NOT EDIT MANUALLY
Expand Down Expand Up @@ -115,5 +123,14 @@ let package = Package(
{% for target in remote_binary_targets %}
{% call addRemoteBinaryTarget target %}
{% endfor %}
{% if swift_versions %}
],
swiftLanguageVersions: [
{% for swift_version in swift_versions %}
.version("{{ swift_version.version }}"),
{% endfor %}
]
{% else %}
]
)
{% endif %}
)