Skip to content

Commit bcf2936

Browse files
committed
Update Makefile, and Package.swift to support binaryTargets
1 parent 79d964a commit bcf2936

File tree

2 files changed

+97
-50
lines changed

2 files changed

+97
-50
lines changed

Makefile

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,31 @@ endif
5555
install: check-submodule $(SWIFT_FILES)
5656
@echo "::notice:: make $@"
5757

58-
#XCFrameworks:
59-
# mint run giginet/Scipio create . \
60-
# --embed-debug-symbols \
61-
# --support-simulators
62-
# echo "::notice:: make $@"
58+
XCFrameworks:
59+
mint run giginet/Scipio create . \
60+
--static \
61+
--embed-debug-symbols \
62+
--support-simulators
63+
@touch $@
64+
@echo "::notice:: make $@"
65+
66+
%.zip: %.xcframework
67+
@zip -qr "$@" "$<"
68+
@rm -rf "$<"
69+
@git add "$@"
70+
@echo "::debug:: make $@"
71+
72+
install-zips: XCFrameworks
73+
@$(MAKE) $(shell echo XCFrameworks/*.xcframework | sed 's/\.xcframework/\.zip/g');
74+
# @git commit -m "[Make] Modify xcframework zips" || true
75+
# @echo "::notice:: make $@"
6376

64-
#XCFRAMEWORKS := $(wildcard XCFrameworks/*.xcframework)
65-
#ZIP_FILES := $(XCFRAMEWORKS:%.xcframework=%.zip)
66-
#%.zip: %.xcframework
67-
# zip -r "$@" "$^"
68-
# rm -rf "$^"
69-
# git add "$@"
70-
#
71-
#install-zips: XCFrameworks $(ZIP_FILES)
72-
# git commit -m "[Make] Re-gen framework zips" || true
73-
# echo "::notice:: make $@"
77+
.PHONY: update-to-date
78+
update-to-date:
79+
touch Submodule
80+
touch Sources/**/openapi-generator-config.yml
81+
touch Sources/**/openapi.yml
82+
touch Sources/**/Client.swift
7483

7584
#.build/docs: ## Need env GITHUB_PAGES is created as 'true'
7685
# swift package --allow-writing-to-directory $@ generate-documentation \

Package.swift

Lines changed: 73 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@
44
import PackageDescription
55
import Foundation
66

7-
/// The generator supports filtering the OpenAPI document prior to generation,
7+
let package = Package(
8+
name: "GitHubRestAPISwiftOpenAPI",
9+
platforms: [.macOS(.v10_15)],
10+
products: GitHubRestAPIOpenAPITag.allCases.map(\.library),
11+
dependencies: [
12+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
13+
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
14+
],
15+
targets: GitHubRestAPIOpenAPITag.allCases.map(\.target)
16+
+ GitHubRestAPIOpenAPITag.allCases.compactMap(\.testTarget)
17+
)
18+
19+
/// The generator supports filtering the OpenAPI document prior to generation,
820
/// which can be useful when generating client code for a subset of a large API,
921
/// or splitting an implementation of a server across multiple modules.
1022
enum GitHubRestAPIOpenAPITag: String, CaseIterable {
@@ -46,56 +58,82 @@ enum GitHubRestAPIOpenAPITag: String, CaseIterable {
4658
case classroom
4759
case desktop
4860

49-
var targetName: String {
61+
var library: PackageDescription.Product {
62+
let targetName = targetName
63+
if isBuildingCode {
64+
return .library(
65+
name: targetName,
66+
targets: [targetName]
67+
)
68+
} else {
69+
return .library(
70+
name: targetName,
71+
targets: [targetName, Self.dependenciesTarget.name]
72+
)
73+
}
74+
}
75+
76+
private var targetName: String {
5077
let name = rawValue.replacingOccurrences(of: "-", with: "_").capitalized
5178
return "GitHubRestAPI\(name)"
5279
}
5380

5481
var target: PackageDescription.Target {
5582
let targetName = targetName
56-
return .target(
57-
name: targetName,
58-
dependencies: [
59-
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
60-
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
61-
],
62-
path: "Sources/\(rawValue)",
63-
exclude: [
64-
"openapi-generator-config.yml",
65-
"openapi.yml",
66-
]
67-
)
68-
}
69-
70-
var library: PackageDescription.Product {
71-
let targetName = targetName
72-
return .library(
73-
name: targetName,
74-
targets: [targetName]
75-
)
83+
if isBuildingCode {
84+
return .target(
85+
name: targetName,
86+
dependencies: [
87+
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
88+
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
89+
],
90+
path: "Sources/\(rawValue)",
91+
exclude: [
92+
"openapi-generator-config.yml",
93+
"openapi.yml",
94+
]
95+
)
96+
} else {
97+
return .binaryTarget(
98+
name: targetName,
99+
path: "XCFrameworks/\(targetName).zip")
100+
}
76101
}
77102

78-
var testTarget: PackageDescription.Target {
103+
var testTarget: PackageDescription.Target? {
104+
guard self == .users else { return nil }
105+
let dependencies: [Target.Dependency] = [
106+
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
107+
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
108+
]
79109
let targetName = targetName
80110
return .testTarget(
81111
name: "UserTests",
82-
dependencies: [.target(name: targetName)]
112+
dependencies: dependencies + [
113+
.target(name: targetName)
114+
]
83115
)
84116
}
117+
118+
static var dependenciesTarget: PackageDescription.Target = .target(
119+
name: "DependenciesTarget",
120+
dependencies: [
121+
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
122+
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
123+
],
124+
path: "XCFrameworks/DependenciesTarget"
125+
)
126+
85127
}
86128

87-
let package = Package(
88-
name: "GitHubRestAPISwiftOpenAPI",
89-
platforms: [.macOS(.v10_15)],
90-
products: GitHubRestAPIOpenAPITag.allCases.map(\.library),
91-
dependencies: [
92-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
93-
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
94-
],
95-
targets: GitHubRestAPIOpenAPITag.allCases.map(\.target) + [
96-
GitHubRestAPIOpenAPITag.users.testTarget,
129+
let isBuildingCode = ProcessInfo.processInfo.environment["BUILD_CODE"] == "true"
130+
131+
// dependencies is needed for package users
132+
if !isBuildingCode {
133+
package.targets += [
134+
GitHubRestAPIOpenAPITag.dependenciesTarget
97135
]
98-
)
136+
}
99137

100138
let isBuildingDocC = ProcessInfo.processInfo.environment["GITHUB_PAGES"] == "true"
101139

0 commit comments

Comments
 (0)