├── LICENSE ├── README.md └── build_libcurl_dist.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Bochun Bai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | libcurl for iOS 2 | ================= 3 | Build libcurl for iOS development. 4 | This script will generate static library for armv7 armv7s arm64 i386 and x86_64. 5 | Bitcode support. 6 | OpenSSL and Darwin native ssl support. 7 | 8 | Script only, please download libcurl from here: http://curl.haxx.se/download.html 9 | Tested Xcode 8.2.1 on macOS 10.12.4 10 | Tested curl 7.54.0 11 | 12 | Usage 13 | ================= 14 | ``` 15 | curl -O https://curl.haxx.se/download/curl-7.54.0.tar.gz 16 | tar xf curl-7.54.0.tar.gz 17 | cd curl-7.54.0 18 | curl https://raw.githubusercontent.com/sinofool/build-libcurl-ios/master/build_libcurl_dist.sh |bash 19 | ...... 20 | ``` 21 | Find the result libcurl-ios-dist on your desktop. 22 | 23 | curl-7.52.1 issue 24 | ================= 25 | 7.52.1 is the latest release but have an issue to build with darwinssl 26 | 27 | https://github.com/curl/curl/issues/1172 28 | 29 | https://github.com/curl/curl/commit/8db3afe16c0916ea5acf6aed6e7cf02f06cc8677 30 | 31 | The fix have commited to curl just one day after release, which should be avaliable for the next patch release. 32 | 33 | Workaround for this issue is: 34 | - patch it with the commit (See darwinssl-fix-iOS-build.patch extacted) 35 | - Or, use openssl with: 36 | 37 | ```bash 38 | ../build_libcurl_dist.sh openssl 39 | ``` 40 | 41 | OpenSSL 42 | ================= 43 | The script link with native ssl by default (--with-darwinssl). 44 | To use OpenSSL, use https://github.com/sinofool/build-openssl-ios/ to build OpenSSL for iOS first, in curl source directory run: 45 | 46 | ```bash 47 | curl https://raw.githubusercontent.com/sinofool/build-libcurl-ios/master/build_libcurl_dist.sh openssl |bash 48 | ``` 49 | 50 | Binary 51 | ================= 52 | You can find a prebuild binary (version 7.57.0 built without OpenSSL) here: https://sinofool.net/dl/libcurl-ios-dist.tar.gz 53 | 54 | Double check the binary file before use: 55 | 56 | ``` 57 | SHA1: 58 | a94458b89ef18b90422cf3affbdac5b8e2e0a0fd libcurl-ios-dist.tar.gz 59 | 60 | GnuPG: (My Key ID: 9BE18853) 61 | https://sinofool.net/dl/libcurl-ios-dist.tar.gz.sig 62 | ``` 63 | -------------------------------------------------------------------------------- /build_libcurl_dist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -euo pipefail 2 | 3 | readonly XCODE_DEV="$(xcode-select -p)" 4 | export DEVROOT="${XCODE_DEV}/Toolchains/XcodeDefault.xctoolchain" 5 | DFT_DIST_DIR=${HOME}/Desktop/libcurl-ios-dist 6 | DIST_DIR=${DIST_DIR:-$DFT_DIST_DIR} 7 | 8 | function check_curl_ver() { 9 | echo "#include \"include/curl/curlver.h\" 10 | #if LIBCURL_VERSION_MAJOR < 7 || LIBCURL_VERSION_MINOR < 55 11 | #error Required curl 7.40.0+; See http://curl.haxx.se/docs/adv_20150108A.html 12 | #error Supported minimal version is 7.55.0 for header file changes, see Issue #12 (https://github.com/sinofool/build-libcurl-ios/issues/12) 13 | #endif"|gcc -c -o /dev/null -xc -||exit 9 14 | } 15 | 16 | function build_for_arch() { 17 | ARCH=$1 18 | HOST=$2 19 | SYSROOT=$3 20 | PREFIX=$4 21 | IPHONEOS_DEPLOYMENT_TARGET="6.0" 22 | export PATH="${DEVROOT}/usr/bin/:${PATH}" 23 | export CFLAGS="-DCURL_BUILD_IOS -arch ${ARCH} -pipe -Os -gdwarf-2 -isysroot ${SYSROOT} -miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET} -fembed-bitcode" 24 | export LDFLAGS="-arch ${ARCH} -isysroot ${SYSROOT}" 25 | ./configure --disable-shared --without-zlib --enable-static --enable-ipv6 ${SSL_FLAG} --host="${HOST}" --prefix=${PREFIX} && make -j8 && make install 26 | } 27 | 28 | if [ "${1:-''}" == "openssl" ] 29 | then 30 | if [ ! -d ${HOME}/Desktop/openssl-ios-dist ] 31 | then 32 | echo "Please use https://github.com/sinofool/build-openssl-ios/ to build OpenSSL for iOS first" 33 | exit 8 34 | fi 35 | export SSL_FLAG=--with-ssl=${HOME}/Desktop/openssl-ios-dist 36 | else 37 | check_curl_ver 38 | export SSL_FLAG=--with-darwinssl 39 | fi 40 | 41 | TMP_DIR=/tmp/build_libcurl_$$ 42 | 43 | build_for_arch i386 i386-apple-darwin ${XCODE_DEV}/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk ${TMP_DIR}/i386 || exit 1 44 | build_for_arch x86_64 x86_64-apple-darwin ${XCODE_DEV}/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk ${TMP_DIR}/x86_64 || exit 2 45 | build_for_arch arm64 arm-apple-darwin ${XCODE_DEV}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk ${TMP_DIR}/arm64 || exit 3 46 | build_for_arch armv7s armv7s-apple-darwin ${XCODE_DEV}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk ${TMP_DIR}/armv7s || exit 4 47 | build_for_arch armv7 armv7-apple-darwin ${XCODE_DEV}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk ${TMP_DIR}/armv7 || exit 5 48 | 49 | mkdir -p ${TMP_DIR}/lib/ 50 | ${DEVROOT}/usr/bin/lipo \ 51 | -arch x86_64 ${TMP_DIR}/x86_64/lib/libcurl.a \ 52 | -arch armv7 ${TMP_DIR}/armv7/lib/libcurl.a \ 53 | -arch armv7s ${TMP_DIR}/armv7s/lib/libcurl.a \ 54 | -arch arm64 ${TMP_DIR}/arm64/lib/libcurl.a \ 55 | -output ${TMP_DIR}/lib/libcurl.a -create 56 | 57 | cp -r ${TMP_DIR}/arm64/include ${TMP_DIR}/ 58 | 59 | mkdir -p ${DIST_DIR} 60 | cp -r ${TMP_DIR}/include ${TMP_DIR}/lib ${DIST_DIR} 61 | 62 | --------------------------------------------------------------------------------