-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathPackage.swift
More file actions
133 lines (121 loc) · 5.27 KB
/
Copy pathPackage.swift
File metadata and controls
133 lines (121 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// swift-tools-version: 5.9
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
// Swift Package Manager manifest for the 1DS C++ SDK (Microsoft Applications
// Telemetry) on Apple platforms.
//
// PROTOTYPE — distribution model:
// * The compiled C++ core + Obj-C wrappers ship as a prebuilt binary
// xcframework (built by tools/apple/build-xcframework.sh). This avoids
// compiling the CMake/Bond/sqlite/zlib C++ tree through SPM, which is not
// practical.
// * The thin Swift wrapper (wrappers/swift/Sources/OneDSSwift) is compiled
// from source on top of the Obj-C module vended by the xcframework.
//
// Local development:
// 1. Run `tools/apple/build-xcframework.sh release` on macOS with Xcode.
// It produces ./build/apple/MATTelemetry.xcframework.
// 2. `swift build` validates macOS consumption; for iOS / Mac Catalyst /
// visionOS, add this package as a local dependency or build the package
// with the desired Xcode destination.
//
// Release distribution (so consumers can add the repo by URL in Xcode):
// .github/workflows/spm-release.yml builds, validates, and uploads the
// xcframework, rewrites the local `.binaryTarget(... path:)` below to
// `url:`+`checksum:`, removes repository submodules from the tag-only commit,
// validates that commit through a clean consumer, and pushes the
// 3-component SemVer tag that SPM can resolve. Because vX.Y.Z.W release tags
// map to one X.Y.Z SPM tag, only one build per three-component version can
// publish; later fourth-component hotfixes for the same X.Y.Z are skipped
// unless the mapping changes.
import PackageDescription
import Foundation
let packageDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
func readAvailability() -> [String: Bool] {
let candidates = [
"build/apple/MATTelemetryAvailability.json",
"tools/apple/MATTelemetryAvailability.json",
]
for relativePath in candidates {
let url = packageDirectory.appendingPathComponent(relativePath).standardizedFileURL
guard let data = try? Data(contentsOf: url),
let object = try? JSONSerialization.jsonObject(with: data) as? [String: Bool] else {
continue
}
return object
}
return [:]
}
let availability = readAvailability()
let hasDiagnosticDataViewer = availability["diagnosticDataViewer"] ?? false
let hasPrivacyGuard = availability["privacyGuard"] ?? false
let hasSanitizer = availability["sanitizer"] ?? false
var excludedSources: [String] = []
var swiftSettings: [SwiftSetting] = []
if !hasDiagnosticDataViewer {
excludedSources.append("DiagnosticDataViewer.swift")
}
if hasPrivacyGuard {
swiftSettings.append(.define("MATSDK_PRIVACYGUARD_AVAILABLE"))
} else {
excludedSources.append(contentsOf: [
"PrivacyGuard.swift",
"PrivacyGuardInitConfig.swift",
])
}
if !hasSanitizer {
excludedSources.append(contentsOf: [
"Sanitizer.swift",
"SanitizerInitConfig.swift",
])
}
let package = Package(
name: "OneDSSwift",
platforms: [
.iOS(.v13),
.macCatalyst(.v14),
.macOS(.v10_15),
.visionOS(.v1),
],
products: [
.library(name: "OneDSSwift", targets: ["OneDSSwift"]),
],
targets: [
// Prebuilt C++ core + Obj-C wrappers. The xcframework's bundled
// module map vends the Clang module `MATTelemetryObjC` (see
// tools/apple/module.modulemap), which the Swift layer imports.
//
// For a tagged release, swap the local path for the hosted artifact:
//
// .binaryTarget(
// name: "MATTelemetry",
// url: "https://github.com/microsoft/cpp_client_telemetry/releases/download/v3.10.161.1/MATTelemetry.xcframework.zip",
// checksum: "<output of swift package compute-checksum>"),
.binaryTarget(
name: "MATTelemetry",
path: "build/apple/MATTelemetry.xcframework"),
// Thin Swift API layer (source). Depends on the Obj-C module from the
// xcframework. The conditional source exclusions above must stay in sync
// with the headers baked into the xcframework.
.target(
name: "OneDSSwift",
dependencies: ["MATTelemetry"],
path: "wrappers/swift/Sources/OneDSSwift",
exclude: excludedSources,
swiftSettings: swiftSettings,
linkerSettings: [
.linkedLibrary("c++"),
.linkedLibrary("sqlite3"),
.linkedLibrary("z"),
.linkedFramework("CFNetwork", .when(platforms: [.iOS, .macCatalyst, .macOS, .visionOS])),
.linkedFramework("CoreFoundation", .when(platforms: [.iOS, .macCatalyst, .macOS, .visionOS])),
.linkedFramework("Foundation", .when(platforms: [.iOS, .macCatalyst, .macOS, .visionOS])),
.linkedFramework("Network", .when(platforms: [.iOS, .macCatalyst, .macOS, .visionOS])),
.linkedFramework("SystemConfiguration", .when(platforms: [.iOS, .macCatalyst, .macOS, .visionOS])),
.linkedFramework("IOKit", .when(platforms: [.macOS])),
.linkedFramework("UIKit", .when(platforms: [.iOS, .macCatalyst, .visionOS])),
]),
]
)