Skip to content

Commit fe003c5

Browse files
authored
Merge pull request #7 from Wei18/feat/scipio
Feat: Use scipio for generating static frameworks to optimize compilation time.
2 parents 79d964a + 62aa515 commit fe003c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+115
-60
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 \

Mintfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
apple/swift-openapi-generator@1.1.0
1+
apple/swift-openapi-generator@1.1.0
2+
giginet/Scipio@0.17.2

Package.swift

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

7-
/// The generator supports filtering the OpenAPI document prior to generation,
7+
let isBuildingCode = ProcessInfo.processInfo.environment["BUILD_CODE"] == "true"
8+
let isBuildingDocC = ProcessInfo.processInfo.environment["GITHUB_PAGES"] == "true"
9+
10+
let package = Package(
11+
name: "GitHubRestAPISwiftOpenAPI",
12+
platforms: [.macOS(.v10_15)],
13+
products: GitHubRestAPIOpenAPITag.allCases.map(\.library),
14+
dependencies: [
15+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
16+
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
17+
],
18+
targets: GitHubRestAPIOpenAPITag.allCases.map(\.target)
19+
+ GitHubRestAPIOpenAPITag.allCases.compactMap(\.testTarget)
20+
)
21+
22+
// dependencies is needed for package users
23+
if !isBuildingCode {
24+
package.targets += [
25+
GitHubRestAPIOpenAPITag.dependenciesTarget
26+
]
27+
}
28+
29+
// swift-docs is not needed for package users
30+
if isBuildingDocC {
31+
package.dependencies += [
32+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
33+
]
34+
}
35+
36+
/// The generator supports filtering the OpenAPI document prior to generation,
837
/// which can be useful when generating client code for a subset of a large API,
938
/// or splitting an implementation of a server across multiple modules.
1039
enum GitHubRestAPIOpenAPITag: String, CaseIterable {
@@ -46,62 +75,70 @@ enum GitHubRestAPIOpenAPITag: String, CaseIterable {
4675
case classroom
4776
case desktop
4877

49-
var targetName: String {
78+
var library: PackageDescription.Product {
79+
let targetName = targetName
80+
if isBuildingCode {
81+
return .library(
82+
name: targetName,
83+
targets: [targetName]
84+
)
85+
} else {
86+
return .library(
87+
name: targetName,
88+
targets: [targetName, Self.dependenciesTarget.name]
89+
)
90+
}
91+
}
92+
93+
private var targetName: String {
5094
let name = rawValue.replacingOccurrences(of: "-", with: "_").capitalized
5195
return "GitHubRestAPI\(name)"
5296
}
5397

5498
var target: PackageDescription.Target {
5599
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-
)
100+
if isBuildingCode {
101+
return .target(
102+
name: targetName,
103+
dependencies: [
104+
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
105+
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
106+
],
107+
path: "Sources/\(rawValue)",
108+
exclude: [
109+
"openapi-generator-config.yml",
110+
"openapi.yml",
111+
]
112+
)
113+
} else {
114+
return .binaryTarget(
115+
name: targetName,
116+
path: "XCFrameworks/\(targetName).zip")
117+
}
76118
}
77119

78-
var testTarget: PackageDescription.Target {
120+
var testTarget: PackageDescription.Target? {
121+
guard self == .users else { return nil }
122+
let dependencies: [Target.Dependency] = [
123+
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
124+
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
125+
]
79126
let targetName = targetName
80127
return .testTarget(
81128
name: "UserTests",
82-
dependencies: [.target(name: targetName)]
129+
dependencies: dependencies + [
130+
.target(name: targetName)
131+
]
83132
)
84133
}
85-
}
86-
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,
97-
]
98-
)
99134

100-
let isBuildingDocC = ProcessInfo.processInfo.environment["GITHUB_PAGES"] == "true"
135+
static var dependenciesTarget: PackageDescription.Target = .target(
136+
name: "DependenciesTarget",
137+
dependencies: [
138+
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
139+
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
140+
],
141+
path: "XCFrameworks/DependenciesTarget"
142+
)
101143

102-
// swift-docs is not needed for package users
103-
if isBuildingDocC {
104-
package.dependencies += [
105-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
106-
]
107144
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by zwc on 2024/1/2.
6+
//
7+
8+
import Foundation

XCFrameworks/DequeModule.zip

700 KB
Binary file not shown.
14.3 MB
Binary file not shown.
6.21 MB
Binary file not shown.

XCFrameworks/GitHubRestAPIApps.zip

6.73 MB
Binary file not shown.
668 KB
Binary file not shown.
3.32 MB
Binary file not shown.

0 commit comments

Comments
 (0)