[iOS] Add podspec for libTorch-lite nightly build (#62691)
authorHanton Yang <hantonyang@fb.com>
Thu, 12 Aug 2021 22:32:25 +0000 (15:32 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 12 Aug 2021 22:35:14 +0000 (15:35 -0700)
Summary:
The nightly pod version will be aliased with [PyTorch nightly build version](https://l.facebook.com/l.php?u=https%3A%2F%2Fgithub.com%2Fpytorch%2Fpytorch%2Fblob%2Fmaster%2F.circleci%2Fscripts%2Fbinary_populate_env.sh%23L88&h=AT3AeTpSGcz9YVeG7Lr_bweWOv8H2-kAMevglFfMslaZwgEPptNM59WdWj2ZER806rKVLNhQGM5EQcyFC_8xOq334LBo2J6YzgPW2LELkgASlA6UxP2gaD2 (https://github.com/pytorch/pytorch/commit/fa22f6303f5cf23058accf899723d6f589066ddf)Wy5mA6_lu_YlHHbEGPIU7ewJQD1 (https://github.com/pytorch/pytorch/commit/2d884f226365f94833df91de532e3a31b0db310d)aBSlOy) and [CocoaPods version specification](https://l.facebook.com/l.php?u=https%3A%2F%2Fguides.cocoapods.org%2Fusing%2Fthe-podfile.html%23specifying-pod-versions&h=AT3AeTpSGcz9YVeG7Lr_bweWOv8H2-kAMevglFfMslaZwgEPptNM59WdWj2ZER806rKVLNhQGM5EQcyFC_8xOq334LBo2J6YzgPW2LELkgASlA6UxP2gaD2 (https://github.com/pytorch/pytorch/commit/fa22f6303f5cf23058accf899723d6f589066ddf)Wy5mA6_lu_YlHHbEGPIU7ewJQD1 (https://github.com/pytorch/pytorch/commit/2d884f226365f94833df91de532e3a31b0db310d)aBSlOy), the version format of the podspect is `PyTorch version + nightly build date`, like `1.10.0.20210812`.

Usage:
1. Add `pod 'LibTorch-Lite-Nightly'` to `Podfile`
2. Run `pod install` to install the nightly built lib
3. Run `pod update` to update the lib to the latest version

Pull Request resolved: https://github.com/pytorch/pytorch/pull/62691

Test Plan:
* Test on [TestApp](https://github.com/pytorch/pytorch/tree/master/ios/TestApp) and [HelloWorld](https://github.com/pytorch/ios-demo-app):
Podfile: `pod 'LibTorch-Lite-Nightly'`

* Test on Private Pod:
{F642106928}

Reviewed By: xta0

Differential Revision: D30090760

Pulled By: hanton

fbshipit-source-id: 361aa2ed24a11d6aced8374cb45f70f49bd5da52

.circleci/scripts/binary_ios_test.sh
.circleci/scripts/binary_ios_upload.sh
ios/LibTorch-Lite-Nightly.podspec.template [new file with mode: 0644]

index 7038b89..8dc0b3f 100644 (file)
@@ -26,4 +26,4 @@ if ! [ -x "$(command -v xcodebuild)" ]; then
     exit 1
 fi
 PROFILE=PyTorch_CI_2021
-ruby ${PROJ_ROOT}/scripts/xcode_build.rb -i ${PROJ_ROOT}/build_ios/install -x ${PROJ_ROOT}/ios/TestApp/TestApp.xcodeproj -p ${IOS_PLATFORM} -c ${PROFILE} -t ${IOS_DEV_TEAM_ID} -f Accelerate,MetalPerformanceShaders
++ruby ${PROJ_ROOT}/scripts/xcode_build.rb -i ${PROJ_ROOT}/build_ios/install -x ${PROJ_ROOT}/ios/TestApp/TestApp.xcodeproj -p ${IOS_PLATFORM} -c ${PROFILE} -t ${IOS_DEV_TEAM_ID} -f Accelerate,MetalPerformanceShaders,CoreML
index c4d4475..b0b0fe1 100644 (file)
@@ -28,12 +28,13 @@ cp ${PROJ_ROOT}/ios/LibTorch-Lite.h ${ZIP_DIR}/src/
 cp ${PROJ_ROOT}/LICENSE ${ZIP_DIR}/
 # zip the library
 export DATE="$(date -u +%Y%m%d)"
-# libtorch_lite_ios_nightly_1.10.0dev20210810.zip
-ZIPFILE="libtorch_lite_ios_nightly_1.10.0.dev$DATE.zip"
+export IOS_NIGHTLY_BUILD_VERSION="1.10.0.${DATE}"
+# libtorch_lite_ios_nightly_1.10.0.20210810.zip
+ZIPFILE="libtorch_lite_ios_nightly_${IOS_NIGHTLY_BUILD_VERSION}.zip"
 cd ${ZIP_DIR}
 #for testing
 touch version.txt
-echo "$DATE" > version.txt
+echo "${IOS_NIGHTLY_BUILD_VERSION}" > version.txt
 zip -r ${ZIPFILE} install src version.txt LICENSE
 # upload to aws
 # Install conda then 'conda install' awscli
@@ -50,3 +51,14 @@ set +x
 # echo "AWS KEY: ${AWS_ACCESS_KEY_ID}"
 # echo "AWS SECRET: ${AWS_SECRET_ACCESS_KEY}"
 aws s3 cp ${ZIPFILE} s3://ossci-ios-build/ --acl public-read
+
+# create a new LibTorch-Lite-Nightly.podspec from the template
+echo "cp ${PROJ_ROOT}/ios/LibTorch-Lite-Nightly.podspec.template ${PROJ_ROOT}/ios/LibTorch-Lite-Nightly.podspec"
+cp ${PROJ_ROOT}/ios/LibTorch-Lite-Nightly.podspec.template ${PROJ_ROOT}/ios/LibTorch-Lite-Nightly.podspec
+
+# update pod version
+sed -i '' -e "s/IOS_NIGHTLY_BUILD_VERSION/${IOS_NIGHTLY_BUILD_VERSION}/g" ${PROJ_ROOT}/ios/LibTorch-Lite-Nightly.podspec
+cat ${PROJ_ROOT}/ios/LibTorch-Lite-Nightly.podspec
+
+# push the new LibTorch-Lite-Nightly.podspec to CocoaPods
+pod trunk push --verbose --allow-warnings --use-libraries --skip-import-validation ${PROJ_ROOT}/ios/LibTorch-Lite-Nightly.podspec
diff --git a/ios/LibTorch-Lite-Nightly.podspec.template b/ios/LibTorch-Lite-Nightly.podspec.template
new file mode 100644 (file)
index 0000000..542a43b
--- /dev/null
@@ -0,0 +1,37 @@
+Pod::Spec.new do |s|
+    s.name             = 'LibTorch-Lite-Nightly'
+    s.version          = 'IOS_NIGHTLY_BUILD_VERSION'
+    s.authors          = 'PyTorch Team'
+    s.license          = { :type => 'BSD' }
+    s.homepage         = 'https://github.com/pytorch/pytorch'
+    s.source           = { :http => "https://ossci-ios-build.s3.amazonaws.com/libtorch_lite_ios_nightly_#{s.version}.zip" }
+    s.summary          = 'The nightly build version of PyTorch C++ library for iOS'
+    s.description      = <<-DESC
+        The nightly build version of PyTorch C++ library for iOS.
+    DESC
+    s.ios.deployment_target = '12.0'
+    s.default_subspec = 'Core'
+    s.subspec 'Core' do |ss|
+        ss.dependency 'LibTorch-Lite-Nightly/Torch'
+        ss.source_files = 'src/*.{h,cpp,c,cc}'
+        ss.public_header_files = ['src/LibTorch-Lite.h']
+    end
+    s.subspec 'Torch' do |ss|
+        ss.header_mappings_dir = 'install/include/'
+        ss.preserve_paths = 'install/include/**/*.{h,cpp,cc,c}'
+        ss.vendored_libraries = 'install/lib/*.a'
+        ss.libraries = ['c++', 'stdc++']
+    end
+    s.user_target_xcconfig = {
+        'HEADER_SEARCH_PATHS' => '$(inherited) "$(PODS_ROOT)/LibTorch-Lite-Nightly/install/include/"',
+        'OTHER_LDFLAGS' => '-force_load "$(PODS_ROOT)/LibTorch-Lite-Nightly/install/lib/libtorch.a" -force_load "$(PODS_ROOT)/LibTorch-Lite-Nightly/install/lib/libtorch_cpu.a"',
+        'CLANG_CXX_LANGUAGE_STANDARD' => 'c++14',
+        'CLANG_CXX_LIBRARY' => 'libc++'
+    }
+    s.pod_target_xcconfig = {
+        'HEADER_SEARCH_PATHS' => '$(inherited) "$(PODS_ROOT)/LibTorch-Lite-Nightly/install/include/"',
+        'VALID_ARCHS' => 'x86_64 arm64'
+    }
+    s.library = ['c++', 'stdc++']
+    s.frameworks = 'Accelerate', 'MetalPerformanceShaders', 'CoreML'
+end
\ No newline at end of file