Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CodePush.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
s.preserve_paths = '*.js'
s.libraries = 'z', 'bz2'
s.source_files = [
'ios/CodePush/*.{h,m,swift}',
'ios/CodePush/*.{h,m}',

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is meant to prevent accidentally picking up .swift files from the main CodePush source dir. New Swift code should go to CodePushCore

'ios/CodePushCore/Sources/CodePushCore/**/*.swift',
'shared/diffpatch/*.{c,h}',
'shared/third_party/hdiffpatch/libHDiffPatch/HPatch/patch.{c,h}',
Expand Down
77 changes: 77 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// swift-tools-version:5.9
import PackageDescription

// How this package finds React Native's header products (ReactHeaders etc.).
//
// `react-native spm scaffold` emits this same path, and react-native-screens, reanimated and
// Sentry ship this same pattern.
// RN generates these products in a local package inside each app, at
// <app>/ios/build/xcframeworks, and gives a hand-written manifest no way to locate the app. The
// path works because the autolinker loads this manifest through a symlink at
// <app>/ios/build/generated/autolinking/libs/CodePush, and SwiftPM resolves relative paths from
// that symlink, not from node_modules. Shipping no manifest is not an option: the autolinker
// rejects a dependency without one.
//
// It breaks in remote mode (RN_SPM_REMOTE_URL) and with a custom `--xcframeworks-path`.
// RN's documented contract for hand-written manifests is a remote package dependency instead,
// which RN doesn't publish as of 0.88:
// https://github.com/react/react-native/blob/v0.88.0/packages/react-native/scripts/spm/__docs__/spm-header-paths-contract.md#hand-authored-community-library-contract
let reactNativePackagePath = "../../../../xcframeworks"

let package = Package(
name: "CodePush",
platforms: [
.iOS("15.5"),
.tvOS("15.5"),
],
products: [
.library(name: "CodePush", targets: ["CodePush"]),
],
dependencies: [
.package(name: "ReactNative", path: reactNativePackagePath),

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional and not fixable today. See PR description for details.

.package(url: "https://github.com/ZipArchive/ZipArchive", .upToNextMinor(from: "2.5.5")),
],
targets: [
.target(
name: "CodePush",
dependencies: [
"CodePushCore",
"CodePushHDiffPatch",
.product(name: "ZipArchive", package: "ZipArchive"),
.product(name: "ReactHeaders", package: "ReactNative"),
.product(name: "ReactNativeHeaders", package: "ReactNative"),
.product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"),
],
path: "ios/CodePush",
publicHeadersPath: "include"
),
.target(
name: "CodePushCore",
path: "ios/CodePushCore/Sources/CodePushCore"
),
.target(
name: "CodePushHDiffPatch",
path: "shared",
sources: [
"diffpatch/bspatch_bridge.c",
"third_party/hdiffpatch/libHDiffPatch/HPatch/patch.c",
"third_party/hdiffpatch/bsdiff_wrapper/bspatch_wrapper.c",
"third_party/hdiffpatch/file_for_patch.c",
],
publicHeadersPath: "diffpatch",
cSettings: [
// Keep in sync with CodePush.podspec and android/app/src/main/cpp/CMakeLists.txt.
.define("_IS_NEED_BLOCK_DEV", to: "0"),
.define("_IS_USED_MULTITHREAD", to: "0"),
.define("_IS_NEED_DIR_DIFF_PATCH", to: "0"),
.headerSearchPath("."),
.headerSearchPath("third_party/hdiffpatch"),
.headerSearchPath("third_party/hdiffpatch/libHDiffPatch/HPatch"),
],
linkerSettings: [
.linkedLibrary("z"),
.linkedLibrary("bz2"),
]
),
]
)
4 changes: 4 additions & 0 deletions ios/CodePush/CodePushPackage.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
#import "CodePushDiffManifest.h"
#import "CodePushErrorUtils.h"
#import "CodePushBinaryDiffPatcher.h"
#if SWIFT_PACKAGE
@import ZipArchive;
#else
#import <SSZipArchive/SSZipArchive.h>
#endif

@implementation CodePushPackage

Expand Down
8 changes: 5 additions & 3 deletions ios/CodePush/CodePushUpdateUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#import "CodePushErrorUtils.h"
#import "CodePushSha256.h"

// Cocoapods static library vs framework interop: the generated header lives at a different
// path depending on whether the pod is built as a static library or as a framework.
#if __has_include(<CodePush/CodePush-Swift.h>)
// SwiftPM builds the Swift sources as a separate module. In CocoaPods they are part of the
// CodePush module, and the generated header path depends on static library vs framework linkage.
#if SWIFT_PACKAGE
@import CodePushCore;
#elif __has_include(<CodePush/CodePush-Swift.h>)
#import <CodePush/CodePush-Swift.h>
#else
#import "CodePush-Swift.h"
Expand Down
3 changes: 3 additions & 0 deletions ios/CodePush/include/CodePush/CodePush.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// SwiftPM exposes only include/ to dependents, so this gives them `#import <CodePush/CodePush.h>`.
// SwiftPM also generates the CodePush module map from this umbrella header.
#import "../../CodePush.h"
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
"type": "git",
"url": "https://github.com/bitrise-io/react-native-code-push"
},
"swiftpmConfig": {
"name": "CodePush"
},
"dependencies": {
"hoist-non-react-statics": "^3.3.2"
},
Expand Down
Loading