Split framework dependencies into separate subspecs to reduce binary size and dynamic linking time when they're not needed (#1028)

This commit is contained in:
Adlai Holler 2018-07-14 11:10:19 -07:00 committed by GitHub
parent 0dc97fbb2f
commit 5cad23b925
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 96 additions and 37 deletions

View File

@ -2609,6 +2609,9 @@
GCC_PREPROCESSOR_DEFINITIONS = ( GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1", "DEBUG=1",
"$(inherited)", "$(inherited)",
"AS_USE_ASSETS_LIBRARY=1",
"AS_USE_MAPKIT=1",
"AS_USE_PHOTOS=1",
); );
GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES;

View File

@ -20,6 +20,7 @@
- Fix misleading/scary stack trace shown when an assertion occurs during node measurement [Huy Nguyen](https://github.com/nguyenhuy) [#1022](https://github.com/TextureGroup/Texture/pull/1022) - Fix misleading/scary stack trace shown when an assertion occurs during node measurement [Huy Nguyen](https://github.com/nguyenhuy) [#1022](https://github.com/TextureGroup/Texture/pull/1022)
- Fix build on 32-bit simulator in Xcode 9.3 and later, caused by `Thread-local storage is not supported on this architecture.` [Adlai Holler](https://github.com/Adlai-Holler) - Fix build on 32-bit simulator in Xcode 9.3 and later, caused by `Thread-local storage is not supported on this architecture.` [Adlai Holler](https://github.com/Adlai-Holler)
- Enable locking assertions (and add some more) to improve and enforce locking safety within the framework [Huy Nguyen](https://github.com/nguyenhuy) [#1024](https://github.com/TextureGroup/Texture/pull/1024) - Enable locking assertions (and add some more) to improve and enforce locking safety within the framework [Huy Nguyen](https://github.com/nguyenhuy) [#1024](https://github.com/TextureGroup/Texture/pull/1024)
- Split MapKit, Photos, and AssetsLibrary dependent code into separate subspecs to improve binary size and start time when they're not needed. The default subspec includes all three for backwards compatibility, but this **will change in 3.0**. When using non-Cocoapods build environments, define `AS_USE_PHOTOS, AS_USE_MAPKIT, AS_USE_ASSETS_LIBRARY` to 1 respectively to signal their use. [Adlai Holler](https://github.com/Adlai-Holler)
## 2.7 ## 2.7
- Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877) - Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877)

View File

@ -15,8 +15,11 @@
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
#import <Foundation/Foundation.h>
#import <AsyncDisplayKit/ASAvailability.h>
#if TARGET_OS_IOS && AS_USE_MAPKIT
#import <AsyncDisplayKit/ASImageNode.h> #import <AsyncDisplayKit/ASImageNode.h>
#if TARGET_OS_IOS
#import <MapKit/MapKit.h> #import <MapKit/MapKit.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN

View File

@ -15,11 +15,10 @@
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
#import <Foundation/Foundation.h>
#if TARGET_OS_IOS
#import <AsyncDisplayKit/ASMapNode.h> #import <AsyncDisplayKit/ASMapNode.h>
#if TARGET_OS_IOS && AS_USE_MAPKIT
#import <tgmath.h> #import <tgmath.h>
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h> #import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
@ -448,4 +447,4 @@
} }
@end @end
#endif #endif // TARGET_OS_IOS && AS_USE_MAPKIT

View File

@ -17,7 +17,7 @@
#import <AsyncDisplayKit/ASMultiplexImageNode.h> #import <AsyncDisplayKit/ASMultiplexImageNode.h>
#if TARGET_OS_IOS #if TARGET_OS_IOS && AS_USE_ASSETS_LIBRARY
#import <AssetsLibrary/AssetsLibrary.h> #import <AssetsLibrary/AssetsLibrary.h>
#endif #endif
@ -25,12 +25,15 @@
#import <AsyncDisplayKit/ASDisplayNodeExtras.h> #import <AsyncDisplayKit/ASDisplayNodeExtras.h>
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h> #import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
#import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h> #import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h>
#import <AsyncDisplayKit/ASPhotosFrameworkImageRequest.h>
#import <AsyncDisplayKit/ASEqualityHelpers.h> #import <AsyncDisplayKit/ASEqualityHelpers.h>
#import <AsyncDisplayKit/ASInternalHelpers.h> #import <AsyncDisplayKit/ASInternalHelpers.h>
#import <AsyncDisplayKit/ASLog.h> #import <AsyncDisplayKit/ASLog.h>
#import <AsyncDisplayKit/ASThread.h> #import <AsyncDisplayKit/ASThread.h>
#if AS_USE_PHOTOS
#import <AsyncDisplayKit/ASPhotosFrameworkImageRequest.h>
#endif
#if AS_PIN_REMOTE_IMAGE #if AS_PIN_REMOTE_IMAGE
#import <AsyncDisplayKit/ASPINRemoteImageDownloader.h> #import <AsyncDisplayKit/ASPINRemoteImageDownloader.h>
#else #else
@ -39,7 +42,9 @@
NSString *const ASMultiplexImageNodeErrorDomain = @"ASMultiplexImageNodeErrorDomain"; NSString *const ASMultiplexImageNodeErrorDomain = @"ASMultiplexImageNodeErrorDomain";
#if AS_USE_ASSETS_LIBRARY
static NSString *const kAssetsLibraryURLScheme = @"assets-library"; static NSString *const kAssetsLibraryURLScheme = @"assets-library";
#endif
static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0}; static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0};
@ -133,7 +138,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
*/ */
- (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image))completionBlock; - (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image))completionBlock;
#if TARGET_OS_IOS #if TARGET_OS_IOS && AS_USE_ASSETS_LIBRARY
/** /**
@abstract Loads the image corresponding to the given assetURL from the device's Assets Library. @abstract Loads the image corresponding to the given assetURL from the device's Assets Library.
@param imageIdentifier The identifier for the image to be loaded. May not be nil. @param imageIdentifier The identifier for the image to be loaded. May not be nil.
@ -143,6 +148,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
- (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL completion:(void (^)(UIImage *image, NSError *error))completionBlock; - (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL completion:(void (^)(UIImage *image, NSError *error))completionBlock;
#endif #endif
#if AS_USE_PHOTOS
/** /**
@abstract Loads the image corresponding to the given image request from the Photos framework. @abstract Loads the image corresponding to the given image request from the Photos framework.
@param imageIdentifier The identifier for the image to be loaded. May not be nil. @param imageIdentifier The identifier for the image to be loaded. May not be nil.
@ -150,6 +156,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
@param completionBlock The block to be performed when the image has been loaded, if possible. May not be nil. @param completionBlock The block to be performed when the image has been loaded, if possible. May not be nil.
*/ */
- (void)_loadPHAssetWithRequest:(ASPhotosFrameworkImageRequest *)request identifier:(id)imageIdentifier completion:(void (^)(UIImage *image, NSError *error))completionBlock API_AVAILABLE(ios(8.0), tvos(10.0)); - (void)_loadPHAssetWithRequest:(ASPhotosFrameworkImageRequest *)request identifier:(id)imageIdentifier completion:(void (^)(UIImage *image, NSError *error))completionBlock API_AVAILABLE(ios(8.0), tvos(10.0));
#endif
/** /**
@abstract Downloads the image corresponding to the given imageIdentifier from the given URL. @abstract Downloads the image corresponding to the given imageIdentifier from the given URL.
@ -620,7 +627,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
return; return;
} }
#if TARGET_OS_IOS #if TARGET_OS_IOS && AS_USE_ASSETS_LIBRARY
// If it's an assets-library URL, we need to fetch it from the assets library. // If it's an assets-library URL, we need to fetch it from the assets library.
if ([[nextImageURL scheme] isEqualToString:kAssetsLibraryURLScheme]) { if ([[nextImageURL scheme] isEqualToString:kAssetsLibraryURLScheme]) {
// Load the asset. // Load the asset.
@ -633,6 +640,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
} }
#endif #endif
#if AS_USE_PHOTOS
if (AS_AVAILABLE_IOS_TVOS(9, 10)) { if (AS_AVAILABLE_IOS_TVOS(9, 10)) {
// Likewise, if it's a Photos asset, we need to fetch it accordingly. // Likewise, if it's a Photos asset, we need to fetch it accordingly.
if (ASPhotosFrameworkImageRequest *request = [ASPhotosFrameworkImageRequest requestWithURL:nextImageURL]) { if (ASPhotosFrameworkImageRequest *request = [ASPhotosFrameworkImageRequest requestWithURL:nextImageURL]) {
@ -644,6 +652,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
return; return;
} }
} }
#endif
// Otherwise, it's a web URL that we can download. // Otherwise, it's a web URL that we can download.
// First, check the cache. // First, check the cache.
@ -677,7 +686,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
}]; }];
}]; }];
} }
#if TARGET_OS_IOS #if TARGET_OS_IOS && AS_USE_ASSETS_LIBRARY
- (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL completion:(void (^)(UIImage *image, NSError *error))completionBlock - (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL completion:(void (^)(UIImage *image, NSError *error))completionBlock
{ {
ASDisplayNodeAssertNotNil(imageIdentifier, @"imageIdentifier is required"); ASDisplayNodeAssertNotNil(imageIdentifier, @"imageIdentifier is required");
@ -702,6 +711,8 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
#pragma clang diagnostic pop #pragma clang diagnostic pop
} }
#endif #endif
#if AS_USE_PHOTOS
- (void)_loadPHAssetWithRequest:(ASPhotosFrameworkImageRequest *)request identifier:(id)imageIdentifier completion:(void (^)(UIImage *image, NSError *error))completionBlock - (void)_loadPHAssetWithRequest:(ASPhotosFrameworkImageRequest *)request identifier:(id)imageIdentifier completion:(void (^)(UIImage *image, NSError *error))completionBlock
{ {
ASDisplayNodeAssertNotNil(imageIdentifier, @"imageIdentifier is required"); ASDisplayNodeAssertNotNil(imageIdentifier, @"imageIdentifier is required");
@ -789,6 +800,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
_phImageRequestOperation = newImageRequestOp; _phImageRequestOperation = newImageRequestOp;
[phImageRequestQueue addOperation:newImageRequestOp]; [phImageRequestQueue addOperation:newImageRequestOp];
} }
#endif
- (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image))completionBlock - (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image))completionBlock
{ {
@ -892,6 +904,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
@end @end
#if AS_USE_PHOTOS
@implementation NSURL (ASPhotosFrameworkURLs) @implementation NSURL (ASPhotosFrameworkURLs)
+ (NSURL *)URLWithAssetLocalIdentifier:(NSString *)assetLocalIdentifier targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:(PHImageRequestOptions *)options NS_RETURNS_RETAINED + (NSURL *)URLWithAssetLocalIdentifier:(NSString *)assetLocalIdentifier targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:(PHImageRequestOptions *)options NS_RETURNS_RETAINED
@ -904,3 +917,4 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
} }
@end @end
#endif

View File

@ -25,6 +25,18 @@
#define AS_TLS_AVAILABLE 1 #define AS_TLS_AVAILABLE 1
#endif #endif
#ifndef AS_USE_PHOTOS
# define AS_USE_PHOTOS 0
#endif
#ifndef AS_USE_MAPKIT
# define AS_USE_MAPKIT 0
#endif
#ifndef AS_USE_ASSETS_LIBRARY
# define AS_USE_ASSETS_LIBRARY 0
#endif
#ifndef kCFCoreFoundationVersionNumber_iOS_10_0 #ifndef kCFCoreFoundationVersionNumber_iOS_10_0
#define kCFCoreFoundationVersionNumber_iOS_10_0 1348.00 #define kCFCoreFoundationVersionNumber_iOS_10_0 1348.00
#endif #endif

View File

@ -15,6 +15,10 @@
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
#import <AsyncDisplayKit/ASAvailability.h>
#if AS_USE_PHOTOS
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <Photos/Photos.h> #import <Photos/Photos.h>
#import <AsyncDisplayKit/ASBaseDefines.h> #import <AsyncDisplayKit/ASBaseDefines.h>
@ -73,3 +77,5 @@ API_AVAILABLE(ios(8.0), tvos(10.0))
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
#endif // AS_USE_PHOTOS

View File

@ -16,6 +16,9 @@
// //
#import <AsyncDisplayKit/ASPhotosFrameworkImageRequest.h> #import <AsyncDisplayKit/ASPhotosFrameworkImageRequest.h>
#if AS_USE_PHOTOS
#import <AsyncDisplayKit/ASBaseDefines.h> #import <AsyncDisplayKit/ASBaseDefines.h>
NSString *const ASPhotosURLScheme = @"ph"; NSString *const ASPhotosURLScheme = @"ph";
@ -160,3 +163,5 @@ static NSString *const _ASPhotosURLQueryKeyCropHeight = @"crop_h";
} }
@end @end
#endif // AS_USE_PHOTOS

View File

@ -11,55 +11,71 @@ Pod::Spec.new do |spec|
spec.documentation_url = 'http://texturegroup.org/appledoc/' spec.documentation_url = 'http://texturegroup.org/appledoc/'
spec.ios.weak_frameworks = 'AssetsLibrary'
spec.weak_frameworks = 'Photos','MapKit'
spec.ios.deployment_target = '9.0' spec.ios.deployment_target = '9.0'
spec.tvos.deployment_target = '9.0' spec.tvos.deployment_target = '9.0'
# Subspecs # Subspecs
spec.subspec 'Core' do |core| spec.subspec 'Core' do |core|
core.public_header_files = [ core.public_header_files = [
'Source/*.h', 'Source/*.h',
'Source/Details/**/*.h', 'Source/Details/**/*.h',
'Source/Layout/**/*.h', 'Source/Layout/**/*.h',
'Source/Base/*.h', 'Source/Base/*.h',
'Source/Debug/**/*.h', 'Source/Debug/**/*.h',
'Source/TextKit/ASTextNodeTypes.h', 'Source/TextKit/ASTextNodeTypes.h',
'Source/TextKit/ASTextKitComponents.h' 'Source/TextKit/ASTextKitComponents.h'
] ]
core.source_files = [ core.source_files = [
'Source/**/*.{h,m,mm}', 'Source/**/*.{h,m,mm}',
'Base/*.{h,m}', 'Base/*.{h,m}',
# Most TextKit components are not public because the C++ content # Most TextKit components are not public because the C++ content
# in the headers will cause build errors when using # in the headers will cause build errors when using
# `use_frameworks!` on 0.39.0 & Swift 2.1. # `use_frameworks!` on 0.39.0 & Swift 2.1.
# See https://github.com/facebook/AsyncDisplayKit/issues/1153 # See https://github.com/facebook/AsyncDisplayKit/issues/1153
'Source/TextKit/*.h', 'Source/TextKit/*.h',
] ]
end end
spec.subspec 'PINRemoteImage' do |pin| spec.subspec 'PINRemoteImage' do |pin|
pin.dependency 'PINRemoteImage/iOS', '= 3.0.0-beta.13' pin.dependency 'PINRemoteImage/iOS', '= 3.0.0-beta.13'
pin.dependency 'PINRemoteImage/PINCache' pin.dependency 'PINRemoteImage/PINCache'
pin.dependency 'Texture/Core' pin.dependency 'Texture/Core'
end end
spec.subspec 'IGListKit' do |igl| spec.subspec 'IGListKit' do |igl|
igl.dependency 'IGListKit', '~> 3.0' igl.dependency 'IGListKit', '~> 3.0'
igl.dependency 'Texture/Core' igl.dependency 'Texture/Core'
end end
spec.subspec 'Yoga' do |yoga| spec.subspec 'Yoga' do |yoga|
yoga.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) YOGA=1' } yoga.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) YOGA=1' }
yoga.dependency 'Yoga', '1.6.0' yoga.dependency 'Yoga', '1.6.0'
yoga.dependency 'Texture/Core' yoga.dependency 'Texture/Core'
end end
# Include optional PINRemoteImage module spec.subspec 'MapKit' do |map|
spec.default_subspec = 'PINRemoteImage' map.frameworks = 'MapKit'
map.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) AS_USE_MAPKIT=1' }
map.dependency 'Texture/Core'
end
spec.subspec 'Photos' do |photos|
photos.frameworks = 'Photos'
photos.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) AS_USE_PHOTOS=1' }
photos.dependency 'Texture/Core'
end
spec.subspec 'AssetsLibrary' do |assetslib|
assetslib.frameworks = 'AssetsLibrary'
assetslib.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) AS_USE_ASSETS_LIBRARY=1' }
assetslib.dependency 'Texture/Core'
end
# Include these by default for backwards compatibility.
# This will change in 3.0.
spec.default_subspecs = 'PINRemoteImage', 'MapKit', 'AssetsLibrary', 'Photos'
spec.social_media_url = 'https://twitter.com/TextureiOS' spec.social_media_url = 'https://twitter.com/TextureiOS'
spec.library = 'c++' spec.library = 'c++'