Skip to content

Instantly share code, notes, and snippets.

@beschulz
Last active August 2, 2017 16:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beschulz/9bf0af3b68f58784fc4d to your computer and use it in GitHub Desktop.
Save beschulz/9bf0af3b68f58784fc4d to your computer and use it in GitHub Desktop.
Notes on how to build thrift for iOS
# get and compile boost
git clone https://gist.github.com/7513324.git boost
cd boost
bash boost.sh
# get and build opensslbe
git@github.com:x2on/OpenSSL-for-iPhone.git
cd OpenSSL-for-iPhone
./build-libssl.sh
# finaly ???
brew install bison
git clone git@github.com:apache/thrift.git
cd thrift
# ??? ./bootstrap.sh
# use these for iOS
#IOS_SDK="/Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/"
#ARCHS="-arch armv7 -arch armv7s -arch arm64 -miphoneos-version-min=5.0"
#OUTPUT_DIRECTORY="/absolute/path/to/where/you/want/the/files/to/go/ios-build"
# and those for the simulator
IOS_SDK="/Applications/XCode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/"
ARCHS="-arch i386 -arch x86_64 -mios-simulator-version-min=5.0"
OUTPUT_DIRECTORY="/absolute/path/to/where/you/want/the/files/to/go/ios-simulator-build"
IOS_SDK="/Applications/XCode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/"
SSL_DIR="/path/to/OpenSSL-for-iPhone/"
BOOST_DIR="/path/to/boost/ios/prefix/"
PATH=/usr/local/Cellar/bison/3.0.2/bin:$PATH \
./configure \
--host=arm-apple-darwin \
CFLAGS=" $ARCHS -isysroot $IOS_SDK -I$IOS_SDK/usr/include -I$SSL_DIR/include" \
CXXFLAGS="$ARCHS -isysroot $IOS_SDK -I$IOS_SDK/usr/include -I$SSL_DIR/include -std=c++11 -stdlib=libc++" \
LDFLAGS=" $ARCHS -isysroot $IOS_SDK -L$IOS_SDK/usr/lib -L$SSL_DIR/lib -stdlib=libc++" \
--without-libevent \
--without-zlib \
--with-cpp \
--without-qt4 \
--without-c_glib \
--without-csharp \
--without-java \
--without-erlang \
--without-nodejs \
--without-lua \
--without-python \
--without-perl \
--without-php \
--without-php_extension \
--without-ruby \
--without-haskell \
--without-go \
--without-d \
--disable-debug \
--disable-tutorial \
--disable-tests \
--with-boost=$BOOST_DIR \
--with-openssl=$SSL_DIR \
--prefix=$IOS_SDK/usr/ \
--prefix $OUTPUT_DIRECTORY \
# I had to manually edit config.h and lib/cpp/src/thrift/config.h, because does #define malloc rpl_malloc and #define realloc rpl_realloc
make install
# if you build both (Device & Simulator), you might want to run
lipo -create ../ios-build/lib/libthrift.a ../ios-simulator-build/lib/libthrift.a -output libthrift.a
# tadahhh, a nice all in one libthrift.a
@beschulz
Copy link
Author

beschulz commented Dec 2, 2014

@gomttang
Copy link

gomttang commented May 25, 2016

Hello. I have a problem with build Thrift for ios.
When I use your build script It occured error. below
/usr/local/include/thrift/transport/TBufferTransports.h:444:28: error: no member named 'rpl_malloc' in namespace 'std'
buf = (uint8_t*)std::malloc(size);
~~~~~^
/usr/local/include/thrift/config.h:418:16: note: expanded from macro 'malloc'

define malloc rpl_malloc

           ^

src/thrift/transport/THttpTransport.cpp:50:26: error: no member named 'rpl_malloc' in namespace 'std'
httpBuf_ = (char*)std::malloc(httpBufSize_ + 1);
~~~~~^
/usr/local/include/thrift/config.h:418:16: note: expanded from macro 'malloc'

define malloc rpl_malloc

           ^

src/thrift/transport/THttpTransport.cpp:203:28: error: no member named 'rpl_realloc' in namespace 'std'
httpBuf_ = (char*)std::realloc(httpBuf_, httpBufSize_ + 1);
~~~~~^
/usr/local/include/thrift/config.h:430:17: note: expanded from macro 'realloc'

define realloc rpl_realloc

I think you changed something in config.h and lib/cpp/src/thrift/config.h.
Could you let me know what you changed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment