Skip to content

Commit

Permalink
Split framework dependencies into separate subspecs to reduce binary …
Browse files Browse the repository at this point in the history
…size and dynamic linking time when they're not needed (#1028)
  • Loading branch information
Adlai-Holler committed Jul 14, 2018
1 parent 0dc97fb commit 5cad23b
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 37 deletions.
3 changes: 3 additions & 0 deletions AsyncDisplayKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,9 @@
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
"AS_USE_ASSETS_LIBRARY=1",
"AS_USE_MAPKIT=1",
"AS_USE_PHOTOS=1",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)
- 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
- Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877)
Expand Down
5 changes: 4 additions & 1 deletion Source/ASMapNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
// 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>
#if TARGET_OS_IOS
#import <MapKit/MapKit.h>

NS_ASSUME_NONNULL_BEGIN
Expand Down
7 changes: 3 additions & 4 deletions Source/ASMapNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
// http://www.apache.org/licenses/LICENSE-2.0
//

#import <Foundation/Foundation.h>

#if TARGET_OS_IOS
#import <AsyncDisplayKit/ASMapNode.h>

#if TARGET_OS_IOS && AS_USE_MAPKIT

#import <tgmath.h>

#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
Expand Down Expand Up @@ -448,4 +447,4 @@ - (BOOL)supportsLayerBacking
}

@end
#endif
#endif // TARGET_OS_IOS && AS_USE_MAPKIT
24 changes: 19 additions & 5 deletions Source/ASMultiplexImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@

#import <AsyncDisplayKit/ASMultiplexImageNode.h>

#if TARGET_OS_IOS
#if TARGET_OS_IOS && AS_USE_ASSETS_LIBRARY
#import <AssetsLibrary/AssetsLibrary.h>
#endif

#import <AsyncDisplayKit/ASAvailability.h>
#import <AsyncDisplayKit/ASDisplayNodeExtras.h>
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
#import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h>
#import <AsyncDisplayKit/ASPhotosFrameworkImageRequest.h>
#import <AsyncDisplayKit/ASEqualityHelpers.h>
#import <AsyncDisplayKit/ASInternalHelpers.h>
#import <AsyncDisplayKit/ASLog.h>
#import <AsyncDisplayKit/ASThread.h>

#if AS_USE_PHOTOS
#import <AsyncDisplayKit/ASPhotosFrameworkImageRequest.h>
#endif

#if AS_PIN_REMOTE_IMAGE
#import <AsyncDisplayKit/ASPINRemoteImageDownloader.h>
#else
Expand All @@ -39,7 +42,9 @@

NSString *const ASMultiplexImageNodeErrorDomain = @"ASMultiplexImageNodeErrorDomain";

#if AS_USE_ASSETS_LIBRARY
static NSString *const kAssetsLibraryURLScheme = @"assets-library";
#endif

static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0};

Expand Down Expand Up @@ -133,7 +138,7 @@ - (void)_loadNextImage;
*/
- (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.
@param imageIdentifier The identifier for the image to be loaded. May not be nil.
Expand All @@ -143,13 +148,15 @@ - (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imag
- (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL completion:(void (^)(UIImage *image, NSError *error))completionBlock;
#endif

#if AS_USE_PHOTOS
/**
@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 request The photos image request to load. 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));
#endif

/**
@abstract Downloads the image corresponding to the given imageIdentifier from the given URL.
Expand Down Expand Up @@ -620,7 +627,7 @@ - (void)_loadNextImage
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 ([[nextImageURL scheme] isEqualToString:kAssetsLibraryURLScheme]) {
// Load the asset.
Expand All @@ -633,6 +640,7 @@ - (void)_loadNextImage
}
#endif

#if AS_USE_PHOTOS
if (AS_AVAILABLE_IOS_TVOS(9, 10)) {
// Likewise, if it's a Photos asset, we need to fetch it accordingly.
if (ASPhotosFrameworkImageRequest *request = [ASPhotosFrameworkImageRequest requestWithURL:nextImageURL]) {
Expand All @@ -644,6 +652,7 @@ - (void)_loadNextImage
return;
}
}
#endif

// Otherwise, it's a web URL that we can download.
// First, check the cache.
Expand Down Expand Up @@ -677,7 +686,7 @@ - (void)_loadNextImage
}];
}];
}
#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
{
ASDisplayNodeAssertNotNil(imageIdentifier, @"imageIdentifier is required");
Expand All @@ -702,6 +711,8 @@ - (void)_loadALAssetWithIdentifier:(id)imageIdentifier URL:(NSURL *)assetURL com
#pragma clang diagnostic pop
}
#endif

#if AS_USE_PHOTOS
- (void)_loadPHAssetWithRequest:(ASPhotosFrameworkImageRequest *)request identifier:(id)imageIdentifier completion:(void (^)(UIImage *image, NSError *error))completionBlock
{
ASDisplayNodeAssertNotNil(imageIdentifier, @"imageIdentifier is required");
Expand Down Expand Up @@ -789,6 +800,7 @@ - (void)_loadPHAssetWithRequest:(ASPhotosFrameworkImageRequest *)request identif
_phImageRequestOperation = newImageRequestOp;
[phImageRequestQueue addOperation:newImageRequestOp];
}
#endif

- (void)_fetchImageWithIdentifierFromCache:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image))completionBlock
{
Expand Down Expand Up @@ -892,6 +904,7 @@ - (void)_finishedLoadingImage:(UIImage *)image forIdentifier:(id)imageIdentifier

@end

#if AS_USE_PHOTOS
@implementation NSURL (ASPhotosFrameworkURLs)

+ (NSURL *)URLWithAssetLocalIdentifier:(NSString *)assetLocalIdentifier targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:(PHImageRequestOptions *)options NS_RETURNS_RETAINED
Expand All @@ -904,3 +917,4 @@ + (NSURL *)URLWithAssetLocalIdentifier:(NSString *)assetLocalIdentifier targetSi
}

@end
#endif
12 changes: 12 additions & 0 deletions Source/Base/ASAvailability.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
#define AS_TLS_AVAILABLE 1
#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
#define kCFCoreFoundationVersionNumber_iOS_10_0 1348.00
#endif
Expand Down
6 changes: 6 additions & 0 deletions Source/Details/ASPhotosFrameworkImageRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
// http://www.apache.org/licenses/LICENSE-2.0
//

#import <AsyncDisplayKit/ASAvailability.h>

#if AS_USE_PHOTOS

#import <UIKit/UIKit.h>
#import <Photos/Photos.h>
#import <AsyncDisplayKit/ASBaseDefines.h>
Expand Down Expand Up @@ -73,3 +77,5 @@ API_AVAILABLE(ios(8.0), tvos(10.0))
@end

NS_ASSUME_NONNULL_END

#endif // AS_USE_PHOTOS
5 changes: 5 additions & 0 deletions Source/Details/ASPhotosFrameworkImageRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
//

#import <AsyncDisplayKit/ASPhotosFrameworkImageRequest.h>

#if AS_USE_PHOTOS

#import <AsyncDisplayKit/ASBaseDefines.h>

NSString *const ASPhotosURLScheme = @"ph";
Expand Down Expand Up @@ -160,3 +163,5 @@ - (BOOL)isEqual:(id)object
}

@end

#endif // AS_USE_PHOTOS
70 changes: 43 additions & 27 deletions Texture.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,71 @@ Pod::Spec.new do |spec|

spec.documentation_url = 'http://texturegroup.org/appledoc/'

spec.ios.weak_frameworks = 'AssetsLibrary'
spec.weak_frameworks = 'Photos','MapKit'

spec.ios.deployment_target = '9.0'
spec.tvos.deployment_target = '9.0'

# Subspecs
spec.subspec 'Core' do |core|
core.public_header_files = [
'Source/*.h',
'Source/Details/**/*.h',
'Source/Layout/**/*.h',
'Source/Base/*.h',
'Source/Debug/**/*.h',
'Source/TextKit/ASTextNodeTypes.h',
'Source/TextKit/ASTextKitComponents.h'
'Source/*.h',
'Source/Details/**/*.h',
'Source/Layout/**/*.h',
'Source/Base/*.h',
'Source/Debug/**/*.h',
'Source/TextKit/ASTextNodeTypes.h',
'Source/TextKit/ASTextKitComponents.h'
]

core.source_files = [
'Source/**/*.{h,m,mm}',
'Base/*.{h,m}',
'Source/**/*.{h,m,mm}',
'Base/*.{h,m}',

# Most TextKit components are not public because the C++ content
# in the headers will cause build errors when using
# `use_frameworks!` on 0.39.0 & Swift 2.1.
# See https://github.com/facebook/AsyncDisplayKit/issues/1153
'Source/TextKit/*.h',
# Most TextKit components are not public because the C++ content
# in the headers will cause build errors when using
# `use_frameworks!` on 0.39.0 & Swift 2.1.
# See https://github.com/facebook/AsyncDisplayKit/issues/1153
'Source/TextKit/*.h',
]
end

spec.subspec 'PINRemoteImage' do |pin|
pin.dependency 'PINRemoteImage/iOS', '= 3.0.0-beta.13'
pin.dependency 'PINRemoteImage/PINCache'
pin.dependency 'Texture/Core'
pin.dependency 'PINRemoteImage/iOS', '= 3.0.0-beta.13'
pin.dependency 'PINRemoteImage/PINCache'
pin.dependency 'Texture/Core'
end

spec.subspec 'IGListKit' do |igl|
igl.dependency 'IGListKit', '~> 3.0'
igl.dependency 'Texture/Core'
igl.dependency 'IGListKit', '~> 3.0'
igl.dependency 'Texture/Core'
end

spec.subspec 'Yoga' do |yoga|
yoga.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) YOGA=1' }
yoga.dependency 'Yoga', '1.6.0'
yoga.dependency 'Texture/Core'
yoga.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) YOGA=1' }
yoga.dependency 'Yoga', '1.6.0'
yoga.dependency 'Texture/Core'
end

spec.subspec 'MapKit' do |map|
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 optional PINRemoteImage module
spec.default_subspec = 'PINRemoteImage'
# 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.library = 'c++'
Expand Down

0 comments on commit 5cad23b

Please sign in to comment.