mirror of
https://github.com/apple/swift-system-metrics.git
synced 2026-05-26 18:50:35 +00:00
3a60fcb0d1
Use task-local metrics factory bootstrap in the example. ### Motivation: `swift-metrics` now supports bootstrapping without the global state. `swift-system-metrics` should have an up-to date example with all the best practices. ### Modifications: - Initialize `SystemMetricsMonitor` with a scoped task-local metrics factory created by the `swift-otel`. ### Result: `SystemMetricsMonitor` is initialized and operational without the global metrics factory.
62 lines
2.2 KiB
Swift
62 lines
2.2 KiB
Swift
// swift-tools-version:6.1
|
|
|
|
import PackageDescription
|
|
|
|
let package = Package(
|
|
name: "swift-system-metrics",
|
|
platforms: [
|
|
.macOS(.v13),
|
|
.iOS(.v16),
|
|
.watchOS(.v9),
|
|
.tvOS(.v16),
|
|
],
|
|
products: [
|
|
.library(name: "SystemMetrics", targets: ["SystemMetrics"])
|
|
],
|
|
dependencies: [
|
|
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.10.1"),
|
|
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.9.1"),
|
|
.package(url: "https://github.com/apple/swift-async-algorithms", from: "1.1.1"),
|
|
],
|
|
targets: [
|
|
.target(
|
|
name: "SystemMetrics",
|
|
dependencies: [
|
|
.product(name: "CoreMetrics", package: "swift-metrics"),
|
|
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
|
|
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
|
|
]
|
|
),
|
|
.testTarget(
|
|
name: "SystemMetricsTests",
|
|
dependencies: [
|
|
"SystemMetrics",
|
|
.product(name: "MetricsTestKit", package: "swift-metrics"),
|
|
]
|
|
),
|
|
]
|
|
)
|
|
|
|
for target in package.targets
|
|
where [.executable, .test, .regular].contains(
|
|
target.type
|
|
) {
|
|
var settings = target.swiftSettings ?? []
|
|
|
|
// https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md
|
|
// Require `any` for existential types.
|
|
settings.append(.enableUpcomingFeature("ExistentialAny"))
|
|
|
|
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md
|
|
settings.append(.enableUpcomingFeature("MemberImportVisibility"))
|
|
|
|
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md
|
|
settings.append(.enableUpcomingFeature("InternalImportsByDefault"))
|
|
|
|
// https://docs.swift.org/compiler/documentation/diagnostics/nonisolated-nonsending-by-default/
|
|
settings.append(.enableUpcomingFeature("NonisolatedNonsendingByDefault"))
|
|
|
|
// Note: do not use .unsafeFlags, this will prevent SPM from checking out the package with tag.
|
|
target.swiftSettings = settings
|
|
}
|