Skip to content

Commit

Permalink
fix: xcframework builds (#288)
Browse files Browse the repository at this point in the history
* fix: xcframework builds

* fix: import access level

* feat: add sample xcframework project

* fix: build examples

* chore: update CHANGELOG
  • Loading branch information
ioannisj authored Jan 28, 2025
1 parent 830de0f commit 75a686f
Show file tree
Hide file tree
Showing 19 changed files with 1,205 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Next

- fix: XCFramework builds failing ([#288](https://github.com/PostHog/posthog-ios/pull/288))
- chore: Session Replay GA ([#286](https://github.com/PostHog/posthog-ios/pull/286))

## 3.19.1 - 2025-01-13
Expand Down
60 changes: 34 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ buildSdk:
set -o pipefail && xcrun xcodebuild clean build -scheme PostHog -destination generic/platform=watchos | xcpretty #watchOS
set -o pipefail && xcrun xcodebuild clean build -scheme PostHog -destination 'platform=visionOS Simulator,name=Apple Vision Pro' | xcpretty #visionOS

buildExamples:
buildExamples: \
buildExamplesPlatforms \
buildExampleXCFramework \
buildExamplePodsDynamic \
buildExamplePodsStatic \

buildExamplesPlatforms:
set -o pipefail && xcrun xcodebuild -downloadAllPlatforms
set -o pipefail && xcrun xcodebuild clean build -scheme PostHogExample -destination generic/platform=ios | xcpretty #ios
set -o pipefail && xcrun xcodebuild clean build -scheme PostHogExample -destination 'platform=visionOS Simulator,name=Apple Vision Pro' | xcpretty #visionOS
Expand All @@ -21,33 +27,35 @@ buildExamples:
set -o pipefail && xcrun xcodebuild clean build -scheme PostHogExampleTvOS -destination generic/platform=tvos | xcpretty #watchOS
set -o pipefail && xcrun xcodebuild clean build -scheme PostHogExampleWithSPM -destination generic/platform=ios | xcpretty #SPM

## Build with dynamic framework
cd PostHogExampleWithPods && \
pod install && \
cd .. && \
xcrun xcodebuild clean build \
-workspace PostHogExampleWithPods/PostHogExampleWithPods.xcworkspace \
-scheme PostHogExampleWithPods \
-destination generic/platform=ios | xcpretty

## Build with static library
buildExamplePodsDynamic:
cd PostHogExampleWithPods && pod install && cd .. && \
set -o pipefail && xcrun xcodebuild clean build \
-workspace PostHogExampleWithPods/PostHogExampleWithPods.xcworkspace \
-scheme PostHogExampleWithPods \
-destination generic/platform=ios | xcpretty

buildExamplePodsStatic:
cd PostHogExampleWithPods && \
cp Podfile{,.backup} && \
cp Podfile.static Podfile && \
cp PostHogExampleWithPods.xcodeproj/project.pbxproj{,.backup} && \
pod install && \
cd .. && \
xcrun xcodebuild clean build \
-workspace PostHogExampleWithPods/PostHogExampleWithPods.xcworkspace \
-scheme PostHogExampleWithPods \
-destination generic/platform=ios | xcpretty

## Restore original files
cp Podfile{,.backup} && \
cp Podfile.static Podfile && \
cp PostHogExampleWithPods.xcodeproj/project.pbxproj{,.backup} && \
pod install && \
cd .. && \
set -o pipefail && xcrun xcodebuild clean build \
-workspace PostHogExampleWithPods/PostHogExampleWithPods.xcworkspace \
-scheme PostHogExampleWithPods \
-destination generic/platform=ios | xcpretty && \
cd PostHogExampleWithPods && \
mv Podfile{.backup,} && \
pod install && \
mv PostHogExampleWithPods.xcodeproj/project.pbxproj{.backup,}

mv Podfile{.backup,} && \
pod install && \
mv PostHogExampleWithPods.xcodeproj/project.pbxproj{.backup,}

buildExampleXCFramework:
./PostHogExampleExternalSDK/build_xcframework.sh
set -o pipefail && xcrun xcodebuild clean build \
-project ./PostHogExampleExternalSDK/SDKClient/PostHogExampleExternalSDKClient.xcodeproj \
-scheme ExternalSDKClient \
-destination "generic/platform=iOS Simulator" | xcpretty

format: swiftLint swiftFormat

Expand Down
4 changes: 0 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ let package = Package(
name: "PostHog",
targets: ["PostHog"]
),
.library(
name: "phlibwebp",
targets: ["phlibwebp"]
),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand Down
7 changes: 6 additions & 1 deletion PostHog/Utils/UIImage+WebP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
import Foundation
#if canImport(phlibwebp)
// SPM package is linked via a lib since mix-code is not yet supported
import phlibwebp

// `internal import`: added in Swift 5.9 and it's the "official" feature. Should replace when we switch to swift-tools-version:5.9
// see: (https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md)

// @_implementationOnly: available since Swift 5.1
@_implementationOnly import phlibwebp
#endif
import UIKit

Expand Down
34 changes: 34 additions & 0 deletions PostHogExampleExternalSDK/ExternalSDK.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// ExternalSDK.swift
// ExternalSDK
//
// Created by Yiannis Josephides on 24/01/2025.
//

import Foundation
import PostHog

public final class MyExternalSDK {
public static let shared = MyExternalSDK()

private init() {
let config = PostHogConfig(
apiKey: "phc_QFbR1y41s5sxnNTZoyKG2NJo2RlsCIWkUfdpawgb40D"
)

config.captureScreenViews = true
config.captureApplicationLifecycleEvents = true
config.debug = true
config.sendFeatureFlagEvent = false
config.sessionReplay = true
config.sessionReplayConfig.maskAllImages = false
config.sessionReplayConfig.maskAllTextInputs = false
config.sessionReplayConfig.maskAllSandboxedViews = false

PostHogSDK.shared.setup(config)
}

public func track(event: String) {
PostHogSDK.shared.capture("An Event From ExternalSDK - \(event)")
}
}
18 changes: 18 additions & 0 deletions PostHogExampleExternalSDK/ExternalSDK/ExternalSDK.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ExternalSDK.h
// ExternalSDK
//
// Created by Yiannis Josephides on 23/01/2025.
//

#import <Foundation/Foundation.h>

//! Project version number for ExternalSDK.
FOUNDATION_EXPORT double ExternalSDKVersionNumber;

//! Project version string for TestBuildIssues.
FOUNDATION_EXPORT const unsigned char ExternalSDKVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <TestBuildIssues/PublicHeader.h>


28 changes: 28 additions & 0 deletions PostHogExampleExternalSDK/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "ExternalSDK",
platforms: [.iOS(.v15)],
products: [
.library(
name: "ExternalSDK",
targets: ["ExternalSDK-iOS"]
),
],
dependencies: [
.package(path: "../"),
],
targets: [
.target(
name: "ExternalSDK-iOS",
dependencies: [
.product(name: "PostHog", package: "posthog-ios"),
.target(name: "ExternalSDK"),
]
),
.binaryTarget(name: "ExternalSDK", path: "./build/bin/ExternalSDK.xcframework"),
]
)
Loading

0 comments on commit 75a686f

Please sign in to comment.