1+ import PackagePlugin
2+ import Foundation
3+
4+ @main
5+ struct CloudSync : BuildToolPlugin {
6+ /// Entry point for creating build commands for targets in Swift packages.
7+ func createBuildCommands( context: PluginContext , target: Target ) async throws -> [ Command ] {
8+ let packageDirectory = context. package . directoryURL
9+ let outputDirectory = context. pluginWorkDirectoryURL
10+ return createCloudSyncBuildCommands ( packageDirectory: packageDirectory, outputDirectory: outputDirectory)
11+ }
12+ }
13+
14+ #if canImport(XcodeProjectPlugin)
15+ import XcodeProjectPlugin
16+
17+ extension CloudSync : XcodeBuildToolPlugin {
18+ // Entry point for creating build commands for targets in Xcode projects.
19+ func createBuildCommands( context: XcodePluginContext , target: XcodeTarget ) throws -> [ Command ] {
20+ let outputDirectory = context. pluginWorkDirectoryURL
21+ return createCloudSyncBuildCommands ( packageDirectory: nil , outputDirectory: outputDirectory)
22+ }
23+ }
24+
25+ #endif
26+
27+ /// Shared function to create CloudSync build commands
28+ func createCloudSyncBuildCommands( packageDirectory: URL ? , outputDirectory: URL ) -> [ Command ] {
29+
30+ // For Xcode projects, use current directory; for Swift packages, use provided packageDirectory
31+ let workingDirectory = packageDirectory? . path ?? " $(pwd) "
32+ let packageDirInfo = packageDirectory != nil ? " Package directory: \( packageDirectory!. path) " : " Working directory: $(pwd) "
33+
34+ return [
35+ . prebuildCommand(
36+ displayName: " Building CloudSync XCFramework " ,
37+ executable: URL ( fileURLWithPath: " /bin/bash " ) ,
38+ arguments: [
39+ " -c " ,
40+ """
41+ set -e
42+ echo " Starting CloudSync XCFramework prebuild... "
43+ echo " \( packageDirInfo) "
44+
45+ # Clean and create output directory
46+ rm -rf " \( outputDirectory. path) "
47+ mkdir -p " \( outputDirectory. path) "
48+
49+ # Build directly from source directory with custom output paths
50+ cd " \( workingDirectory) " && \
51+ echo " Building XCFramework with native network... " && \
52+ make xcframework NATIVE_NETWORK=ON DIST_DIR= " \( outputDirectory. path) " BUILD_RELEASE= " \( outputDirectory. path) /build/release " BUILD_TEST= " \( outputDirectory. path) /build/test " && \
53+ rm -rf " \( outputDirectory. path) /build " && \
54+ echo " XCFramework build completed successfully! "
55+ """
56+ ] ,
57+ outputFilesDirectory: outputDirectory
58+ )
59+ ]
60+ }
0 commit comments