From 1c3428af31ed186de9020ade4115f63f404f7393 Mon Sep 17 00:00:00 2001 From: Gemfield Date: Thu, 28 Mar 2019 21:35:17 -0700 Subject: [PATCH] Enhance build_ios.sh to be consistent with build_android.sh (#18564) Summary: 1, Enhance build_ios.sh to be consistent with build_android.sh; 2, Add docs for build_ios.sh. Pull Request resolved: https://github.com/pytorch/pytorch/pull/18564 Differential Revision: D14680752 Pulled By: soumith fbshipit-source-id: 6d2667ed8a3c85a057a522838f5d0461dd4788cf --- scripts/README.md | 17 +++++++++++++++++ scripts/build_ios.sh | 9 +++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 07e12e5..06b5eb2 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -21,3 +21,20 @@ You can also override the cmake flags via command line, e.g., following command ```bash bash scripts/build_android.sh -DBUILD_BINARY=ON ``` + +## build_ios.sh +This script is to build PyTorch/Caffe2 library for iOS, and can only be performed on macOS. Take the following steps to start the build: + +- Install Xcode from App Store, and configure "Command Line Tools" properly on Xcode. +- Install the dependencies: + +```bash +brew install cmake automake libtool +``` + +- run build_ios.sh +```bash +#in your PyTorch root directory +bash scripts/build_ios.sh +``` +If succeeded, the libraries and headers would be generated to build_ios/install directory. You can then copy these files to your Xcode project for further usage. \ No newline at end of file diff --git a/scripts/build_ios.sh b/scripts/build_ios.sh index bc44a3a..194c54f 100755 --- a/scripts/build_ios.sh +++ b/scripts/build_ios.sh @@ -18,6 +18,7 @@ $CAFFE2_ROOT/scripts/build_host_protoc.sh --other-flags $BITCODE_FLAGS # Now, actually build the iOS target. BUILD_ROOT=${BUILD_ROOT:-"$CAFFE2_ROOT/build_ios"} +INSTALL_PREFIX=${BUILD_ROOT}/install mkdir -p $BUILD_ROOT cd $BUILD_ROOT @@ -79,12 +80,16 @@ fi CMAKE_ARGS+=("-DCMAKE_C_FLAGS=-fembed-bitcode") CMAKE_ARGS+=("-DCMAKE_CXX_FLAGS=-fembed-bitcode") - cmake "$CAFFE2_ROOT" \ - -DCMAKE_INSTALL_PREFIX=../install \ + -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SHARED_LIBS=OFF \ ${CMAKE_ARGS[@]} \ $@ cmake --build . -- "-j$(sysctl -n hw.ncpu)" + +# copy headers and libs to install directory +echo "Will install headers and libs to $INSTALL_PREFIX for further Xcode project usage." +make install +echo "Installation completed, now you can copy the headers/libs from $INSTALL_PREFIX to your Xcode project directory." -- 2.7.4