Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
82 changes: 81 additions & 1 deletion .circleci/config.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ===----------------------------------------------------------------------===//
amends "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.circleci@1.1.1#/PklCI.pkl"
amends "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.circleci@1.2.1#/PklCI.pkl"

import "pkl:semver"

Expand Down Expand Up @@ -55,6 +55,62 @@ local pklDistributions: Listing<PklDistribution> = new {
pklCurrent
}

local typealias Platform ="iOS Simulator"|"watchOS Simulator"|"tvOS Simulator"|"visionOS Simulator"|"Mac Catalyst"

local class SimulatorRuntime {
name: String
platform: Platform
fixed sdk: String = Map(
"iOS Simulator", "iphonesimulator",
"watchOS Simulator", "watchsimulator",
"tvOS Simulator", "appletvsimulator",
"visionOS Simulator", "xrsimulator",
"Mac Catalyst", "macosx"
)[platform]
hidden destination: String = "platform=\(platform),name=\(name)"
settings: Mapping<String, Any> = new {
["ONLY_ACTIVE_ARCH"] = "YES"
["CODE_SIGNING_REQUIRED"] = "NO"
["CODE_SIGNING_ALLOWED"] = "YES"
["COMPILER_INDEX_STORE_ENABLE"] = "NO"
}
flags: Listing<String> = new {
"-sdk \(sdk)"
"-destination '\(destination)'"
for (k, v in settings) {
"\(k)=\(v)"
}
}
}

local simulators: Mapping<Platform, SimulatorRuntime> = new {
default { key -> platform = key }
["iOS Simulator"] {
name = "iPhone 17"
}
["watchOS Simulator"] {
name = "Apple Watch Series 11 (42mm)"
}
["tvOS Simulator"] {
name = "Apple TV 4K (3rd generation)"
}
// ["visionOS Simulator"] {
// name = "Apple Vision Pro"
// }
["Mac Catalyst"] {
destination = "platform=macOS,variant=Mac Catalyst,arch=\(settings["ARCH"])"
settings {
["ARCH"] = "arm64"
["VALID_ARCHS"] = this["ARCH"]
["SUPPORTS_MACCATALYST"] = "YES"
["TARGETED_DEVICE_FAMILY"] = 2
["CODE_SIGN_IDENTITY"] = "-"
["CODE_SIGNING_REQUIRED"] = "NO"
["CODE_SIGNING_ALLOWED"] = "NO"
}
}
}

local testJobs = jobs.keys.filter((it) -> it.startsWith("test"))

main {
Expand Down Expand Up @@ -146,6 +202,30 @@ jobs {
}
}

for (simulator in simulators) {
["test-\(simulator.platform.toLowerCase().replaceAll(" ", "-"))"] {
macos {
xcode = "26.0.1"
}
resource_class = "m4pro.large"
steps {
"checkout"
new RunStep { command = "gem install xcpretty" }
new RunStep {
name = "xcodebuild test"
command =
#"""
xcodebuild -scheme pkl-swift-Package \#(simulator.flags.join(" ")) test \
| xcpretty --report junit --output .out/test-results/junit.xml
"""#
}
new StoreTestResults {
path = ".out/test-results/"
}
}
}
}

["test-license-headers"] {
docker {
new {
Expand Down
116 changes: 116 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,66 @@ jobs:
resource_class: xlarge
docker:
- image: swift:6.1-rhel-ubi9
test-ios-simulator:
steps:
- checkout
- run:
command: gem install xcpretty
- run:
command: |-
xcodebuild -scheme pkl-swift-Package -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 17' ONLY_ACTIVE_ARCH=YES CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=YES COMPILER_INDEX_STORE_ENABLE=NO test \
| xcpretty --report junit --output .out/test-results/junit.xml
name: xcodebuild test
- store_test_results:
path: .out/test-results/
resource_class: m4pro.large
macos:
xcode: 26.0.1
test-watchos-simulator:
steps:
- checkout
- run:
command: gem install xcpretty
- run:
command: |-
xcodebuild -scheme pkl-swift-Package -sdk watchsimulator -destination 'platform=watchOS Simulator,name=Apple Watch Series 11 (42mm)' ONLY_ACTIVE_ARCH=YES CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=YES COMPILER_INDEX_STORE_ENABLE=NO test \
| xcpretty --report junit --output .out/test-results/junit.xml
name: xcodebuild test
- store_test_results:
path: .out/test-results/
resource_class: m4pro.large
macos:
xcode: 26.0.1
test-tvos-simulator:
steps:
- checkout
- run:
command: gem install xcpretty
- run:
command: |-
xcodebuild -scheme pkl-swift-Package -sdk appletvsimulator -destination 'platform=tvOS Simulator,name=Apple TV 4K (3rd generation)' ONLY_ACTIVE_ARCH=YES CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=YES COMPILER_INDEX_STORE_ENABLE=NO test \
| xcpretty --report junit --output .out/test-results/junit.xml
name: xcodebuild test
- store_test_results:
path: .out/test-results/
resource_class: m4pro.large
macos:
xcode: 26.0.1
test-mac-catalyst:
steps:
- checkout
- run:
command: gem install xcpretty
- run:
command: |-
xcodebuild -scheme pkl-swift-Package -sdk macosx -destination 'platform=macOS,variant=Mac Catalyst,arch=arm64' ONLY_ACTIVE_ARCH=YES CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO COMPILER_INDEX_STORE_ENABLE=NO ARCH=arm64 VALID_ARCHS=arm64 SUPPORTS_MACCATALYST=YES TARGETED_DEVICE_FAMILY=2 CODE_SIGN_IDENTITY=- test \
| xcpretty --report junit --output .out/test-results/junit.xml
name: xcodebuild test
- store_test_results:
path: .out/test-results/
resource_class: m4pro.large
macos:
xcode: 26.0.1
test-license-headers:
steps:
- checkout
Expand Down Expand Up @@ -208,6 +268,18 @@ workflows:
- test-pkl-0-29-0:
requires:
- hold
- test-ios-simulator:
requires:
- hold
- test-watchos-simulator:
requires:
- hold
- test-tvos-simulator:
requires:
- hold
- test-mac-catalyst:
requires:
- hold
- test-license-headers:
requires:
- hold
Expand All @@ -222,6 +294,10 @@ workflows:
jobs:
- test-pkl-0-25-3
- test-pkl-0-29-0
- test-ios-simulator
- test-watchos-simulator
- test-tvos-simulator
- test-mac-catalyst
- test-license-headers
- test-format
when:
Expand All @@ -242,6 +318,30 @@ workflows:
ignore: /.*/
tags:
only: /^v?\d+\.\d+\.\d+$/
- test-ios-simulator:
filters:
branches:
ignore: /.*/
tags:
only: /^v?\d+\.\d+\.\d+$/
- test-watchos-simulator:
filters:
branches:
ignore: /.*/
tags:
only: /^v?\d+\.\d+\.\d+$/
- test-tvos-simulator:
filters:
branches:
ignore: /.*/
tags:
only: /^v?\d+\.\d+\.\d+$/
- test-mac-catalyst:
filters:
branches:
ignore: /.*/
tags:
only: /^v?\d+\.\d+\.\d+$/
- test-license-headers:
filters:
branches:
Expand All @@ -258,6 +358,10 @@ workflows:
requires:
- test-pkl-0-25-3
- test-pkl-0-29-0
- test-ios-simulator
- test-watchos-simulator
- test-tvos-simulator
- test-mac-catalyst
- test-license-headers
- test-format
filters:
Expand All @@ -269,6 +373,10 @@ workflows:
requires:
- test-pkl-0-25-3
- test-pkl-0-29-0
- test-ios-simulator
- test-watchos-simulator
- test-tvos-simulator
- test-mac-catalyst
- test-license-headers
- test-format
filters:
Expand All @@ -280,6 +388,10 @@ workflows:
requires:
- test-pkl-0-25-3
- test-pkl-0-29-0
- test-ios-simulator
- test-watchos-simulator
- test-tvos-simulator
- test-mac-catalyst
- test-license-headers
- test-format
filters:
Expand All @@ -291,6 +403,10 @@ workflows:
requires:
- test-pkl-0-25-3
- test-pkl-0-29-0
- test-ios-simulator
- test-watchos-simulator
- test-tvos-simulator
- test-mac-catalyst
- test-license-headers
- test-format
filters:
Expand Down
7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import PackageDescription
let package = Package(
name: "pkl-swift",
platforms: [
// required because of `Duration` API
.macOS(.v13),
.iOS(.v16),
.tvOS(.v16),
.watchOS(.v9),
.visionOS(.v1),
],
products: [
.library(
Expand Down Expand Up @@ -50,7 +53,7 @@ let package = Package(
.target(
name: "PklSwift",
dependencies: ["MessagePack", "PklSwiftInternals", "SemanticVersion"],
swiftSettings: [.enableUpcomingFeature("StrictConcurrency")]
swiftSettings: [.enableUpcomingFeature("StrictConcurrency")],
),
.target(
name: "PklSwiftInternals",
Expand Down
10 changes: 9 additions & 1 deletion Sources/PklSwift/EvaluatorManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let PKL_EXEC_NAME="pkl.exe"
let ENV_SEPARATOR=":"
let PKL_EXEC_NAME="pkl"
#endif
/// Perfoms `action`, returns its result and then closes the manager.
/// Performs `action`, returns its result and then closes the manager.
///
/// - Parameter action: The action to perform
/// - Returns: The result of `action`
Expand Down Expand Up @@ -109,7 +109,11 @@ public actor EvaluatorManager {

// note; when our C bindings are released, change `init()` based on compiler flags.
public init() {
#if os(macOS) || os(Linux) || os(Windows)
self.init(transport: ServerMessageTransport())
#else
fatalError("cannot spawn pkl cli on this platform")
#endif
}

// Used for testing only.
Expand All @@ -126,6 +130,7 @@ public actor EvaluatorManager {

/// Get the semantic version as a String of the Pkl interpreter being used.
func getVersion() throws -> String {
#if os(macOS) || os(Linux) || os(Windows)
if let pklVersion {
return pklVersion
}
Expand All @@ -147,6 +152,9 @@ public actor EvaluatorManager {

self.pklVersion = String(output[1])
return self.pklVersion!
#else
throw PklError("cannot spawn pkl cli on this platform")
#endif
}

private func listenForIncomingMessages() async throws {
Expand Down
4 changes: 4 additions & 0 deletions Sources/PklSwift/EvaluatorOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ extension EvaluatorOptions {
]

public static var cacheDir: String {
#if os(macOS) || os(Linux) || os(Windows)
resolvePaths(FileManager.default.homeDirectoryForCurrentUser.path, ".pkl/cache")
#else
resolvePaths(URL.cachesDirectory.path, ".pkl/cache")
#endif
}

public static let preconfigured: EvaluatorOptions = .init(
Expand Down
2 changes: 2 additions & 0 deletions Sources/PklSwift/MessageTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public class BaseMessageTransport: MessageTransport, @unchecked Sendable {
}

/// A ``MessageTransport`` that sends and receives messages by spawning Pkl as a child process.
#if os(macOS) || os(Linux) || os(Windows)
public class ServerMessageTransport: BaseMessageTransport, @unchecked Sendable {
var process: Process?
let pklCommand: [String]?
Expand Down Expand Up @@ -194,6 +195,7 @@ public class ServerMessageTransport: BaseMessageTransport, @unchecked Sendable {
return try super.getMessages()
}
}
#endif

public class ExternalReaderMessageTransport: BaseMessageTransport, @unchecked Sendable {
override var running: Bool { self._running }
Expand Down
2 changes: 2 additions & 0 deletions Tests/PklSwiftTests/EvaluatorManagerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FakeMessageTransport: MessageTransport, @unchecked Sendable {
}
}

#if os(macOS) || os(Linux) || os(Windows)
class EvaluatorManagerTest: XCTestCase {
func testConcurrentEvaluatorManagers() async throws {
let manager1 = EvaluatorManager()
Expand Down Expand Up @@ -141,3 +142,4 @@ class EvaluatorManagerTest: XCTestCase {
}
}
}
#endif
2 changes: 2 additions & 0 deletions Tests/PklSwiftTests/EvaluatorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct VirtualResourceReader: ResourceReader {
}
}

#if os(macOS) || os(Linux) || os(Windows)
final class PklSwiftTests: XCTestCase {
var manager: EvaluatorManager!

Expand Down Expand Up @@ -458,3 +459,4 @@ final class PklSwiftTests: XCTestCase {
// }
// }
}
#endif
Loading