From 60b4f1a9fa9412eaba0b3fc7ba84966295632002 Mon Sep 17 00:00:00 2001 From: Byoungchan Lee Date: Wed, 10 Sep 2025 06:19:52 +0900 Subject: [PATCH] Add Swift Package Manager (SPM) support for several Foundation targets --- .github/workflows/spm.yml | 63 +++++++++++ BUILD | 3 +- GTM.xcodeproj/project.pbxproj | 2 +- GTMiPhone.xcodeproj/project.pbxproj | 2 +- GoogleToolboxForMac.podspec | 4 +- Package.swift | 106 ++++++++++++++++++ .../Defines/Public/GTMDefines.h | 0 7 files changed, 175 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/spm.yml create mode 100644 Package.swift rename GTMDefines.h => Sources/Defines/Public/GTMDefines.h (100%) diff --git a/.github/workflows/spm.yml b/.github/workflows/spm.yml new file mode 100644 index 00000000..a451e0d7 --- /dev/null +++ b/.github/workflows/spm.yml @@ -0,0 +1,63 @@ +name: SPM + +on: + push: + branches: [ main ] + paths: + - 'Sources/**' + - 'Tests/**' + - 'UnitTesting/**' + - 'Package.swift' + - '.github/workflows/spm.yml' + - '!**/BUILD' + pull_request: + branches: [ main ] + paths: + - 'Sources/**' + - 'Tests/**' + - 'UnitTesting/**' + - 'Package.swift' + - '.github/workflows/spm.yml' + - '!**/BUILD' + schedule: + # Run the first and fifteenth of every month at 4:18 UTC + - cron: '18 4 1,18 * *' + # Also allow manual triggering from the github UX to revalidate things. + workflow_dispatch: + +jobs: + spm: + runs-on: macos-15 + strategy: + fail-fast: false + matrix: + MODE: ["Debug", "Release"] + steps: + - uses: actions/checkout@v4 + - name: spm build + run: | + spm_mode="" + if [ "${{ matrix.MODE }}" == "Debug" ]; then + spm_mode="debug" + elif [ "${{ matrix.MODE }}" == "Release" ]; then + spm_mode="release" + else + echo "Invalid mode: ${{ matrix.MODE }}" + exit 1 + fi + swift build -c $spm_mode + swift test -c $spm_mode + # Remove the xcodeproj so that we can build SPM with xcodebuild. + rm -rf *.xcodeproj + # For iOS and tvOS, tests are skipped for now because + # setting up a Host Application in SPM is much more complex. + xcodebuild \ + -scheme GoogleToolboxForMac-Package \ + -destination 'generic/platform=iOS' \ + -configuration ${{ matrix.MODE }} \ + build + xcodebuild \ + -scheme GoogleToolboxForMac-Package \ + -destination 'generic/platform=tvOS' \ + -configuration ${{ matrix.MODE }} \ + build diff --git a/BUILD b/BUILD index 448109b1..0cd320f4 100644 --- a/BUILD +++ b/BUILD @@ -3,7 +3,8 @@ load("@build_bazel_rules_apple//apple:macos.bzl", "macos_build_test") objc_library( name = "Defines", - hdrs = ["GTMDefines.h"], + hdrs = ["Sources/Defines/Public/GTMDefines.h"], + includes = ["Sources/Defines/Public"], visibility = ["//visibility:public"], ) diff --git a/GTM.xcodeproj/project.pbxproj b/GTM.xcodeproj/project.pbxproj index 2b05e782..afd462ff 100644 --- a/GTM.xcodeproj/project.pbxproj +++ b/GTM.xcodeproj/project.pbxproj @@ -188,7 +188,7 @@ 8B158A6010A8BE4500C93125 /* GTMNSAnimation+Duration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GTMNSAnimation+Duration.m"; sourceTree = ""; }; 8B17FD18117638F400E7A908 /* GTMAppKitUnitTestingUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMAppKitUnitTestingUtilities.m; sourceTree = ""; }; 8B17FD19117638F400E7A908 /* GTMAppKitUnitTestingUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMAppKitUnitTestingUtilities.h; sourceTree = ""; }; - 8B1A16050D90344B00CA1E8E /* GTMDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMDefines.h; sourceTree = ""; }; + 8B1A16050D90344B00CA1E8E /* GTMDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GTMDefines.h; path = Sources/Defines/Public/GTMDefines.h; sourceTree = SOURCE_ROOT; }; 8B21DE54117E5CB7000E004F /* GTMLocalizedString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GTMLocalizedString.h; path = Sources/LocalizedString/Public/Foundation/GTMLocalizedString.h; sourceTree = SOURCE_ROOT; }; 8B29078411F8D1BF0064F50F /* GTMNSFileHandle+UniqueName.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "GTMNSFileHandle+UniqueName.h"; path = "Sources/NSFileHandle_UniqueName/Public/Foundation/GTMNSFileHandle+UniqueName.h"; sourceTree = SOURCE_ROOT; }; 8B29078511F8D1BF0064F50F /* GTMNSFileHandle+UniqueName.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "GTMNSFileHandle+UniqueName.m"; path = "Sources/NSFileHandle_UniqueName/GTMNSFileHandle+UniqueName.m"; sourceTree = SOURCE_ROOT; }; diff --git a/GTMiPhone.xcodeproj/project.pbxproj b/GTMiPhone.xcodeproj/project.pbxproj index b9ec23fe..80fd13c9 100644 --- a/GTMiPhone.xcodeproj/project.pbxproj +++ b/GTMiPhone.xcodeproj/project.pbxproj @@ -134,7 +134,7 @@ 8B82CF561D9C24D9007182AA /* iOS.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = iOS.xcconfig; sourceTree = ""; }; 8B82CF571D9C24D9007182AA /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; 8B82CF581D9C24D9007182AA /* Unittest.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Unittest.xcconfig; sourceTree = ""; }; - 8BC047750DAE926E00C2D1CA /* GTMDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMDefines.h; sourceTree = ""; }; + 8BC047750DAE926E00C2D1CA /* GTMDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GTMDefines.h; path = Sources/Defines/Public/GTMDefines.h; sourceTree = SOURCE_ROOT; }; 8BC0477E0DAE928A00C2D1CA /* GTMNSData+zlib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "GTMNSData+zlib.h"; path = "Sources/NSData_zlib/Public/Foundation/GTMNSData+zlib.h"; sourceTree = SOURCE_ROOT; }; 8BC0477F0DAE928A00C2D1CA /* GTMNSData+zlib.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "GTMNSData+zlib.m"; path = "Sources/NSData_zlib/GTMNSData+zlib.m"; sourceTree = SOURCE_ROOT; }; 8BC047800DAE928A00C2D1CA /* GTMNSData+zlibTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "GTMNSData+zlibTest.m"; path = "Tests/NSData_zlibTests/GTMNSData+zlibTest.m"; sourceTree = SOURCE_ROOT; }; diff --git a/GoogleToolboxForMac.podspec b/GoogleToolboxForMac.podspec index e0af4e8a..380f2f5d 100644 --- a/GoogleToolboxForMac.podspec +++ b/GoogleToolboxForMac.podspec @@ -37,8 +37,8 @@ Pod::Spec.new do |s| 'NSString+XML', 'NSThread+Blocks' s.subspec 'Defines' do |sp| - sp.public_header_files = 'GTMDefines.h' - sp.source_files = 'GTMDefines.h' + sp.public_header_files = 'Sources/Defines/Public/GTMDefines.h' + sp.source_files = 'Sources/Defines/Public/GTMDefines.h' sp.resource_bundle = { "GoogleToolboxForMac_Privacy" => "Resources/Base/PrivacyInfo.xcprivacy" } diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..921098d8 --- /dev/null +++ b/Package.swift @@ -0,0 +1,106 @@ +// swift-tools-version:6.0 +import PackageDescription + +let package = Package( + name: "GoogleToolboxForMac", + platforms: [ + .iOS(.v13), + .macOS(.v10_15), + .tvOS(.v13), + ], + products: [ + .library( + name: "GTMLogger", + targets: ["GTMLogger"] + ), + .library( + name: "GTMNSData_zlib", + targets: ["GTMNSData_zlib"] + ), + .library( + name: "GTMStringEncoding", + targets: ["GTMStringEncoding"] + ), + ], + targets: [ + .target( + name: "GTMDefines", + path: "Sources/Defines", + publicHeadersPath: "Public" + ), + .target( + name: "GTMLogger", + dependencies: [ + "GTMDefines" + ], + path: "Sources/Logger", + exclude: [ + "BUILD", + "GTMLogger+ASL.m", + "GTMLoggerRingBufferWriter.m", + ], + publicHeadersPath: "Public/Foundation" + ), + .target( + name: "GTMNSData_zlib", + dependencies: [ + "GTMDefines" + ], + path: "Sources/NSData_zlib", + exclude: [ + "BUILD" + ], + publicHeadersPath: "Public/Foundation", + linkerSettings: [ + .linkedLibrary("z") + ] + ), + .target( + name: "GTMStringEncoding", + dependencies: [ + "GTMDefines" + ], + path: "Sources/StringEncoding", + exclude: [ + "BUILD" + ], + publicHeadersPath: "Public/Foundation" + ), + .target( + name: "SenTestCase", + dependencies: [ + "GTMDefines" + ], + path: "UnitTesting/SenTestCase", + exclude: [ + "GTMSenTestCaseTest.m" + ], + ), + .testTarget( + name: "GTMLoggerTests", + dependencies: ["GTMLogger", "SenTestCase"], + path: "Tests/LoggerTests", + exclude: [ + "BUILD", + "GTMLogger+ASLTest.m", + "GTMLoggerRingBufferWriterTest.m", + ] + ), + .testTarget( + name: "NSData_zlibTests", + dependencies: ["GTMNSData_zlib", "SenTestCase"], + path: "Tests/NSData_zlibTests", + exclude: [ + "BUILD" + ] + ), + .testTarget( + name: "StringEncodingTests", + dependencies: ["GTMStringEncoding", "SenTestCase"], + path: "Tests/StringEncodingTests", + exclude: [ + "BUILD" + ] + ), + ] +) diff --git a/GTMDefines.h b/Sources/Defines/Public/GTMDefines.h similarity index 100% rename from GTMDefines.h rename to Sources/Defines/Public/GTMDefines.h