compile rocksdb as backend for asyncstorage

October 25, 2015 ยท View on GitHub

Credits

All credit to @sahrens for sharing fb's internal implementation.

Setup

  • clone rocksdb from https://github.com/facebook/rocksdb.

  • edit MakeFile inside rocksdb. Search for Platform-specific compilation around line 1122. Make th next few lines to look like this:

ifeq ($(PLATFORM), IOS)
# For iOS, create universal object files to be used on both the simulator and
# a device.
PLATFORMSROOT=/Applications/Xcode.app/Contents/Developer/Platforms
SIMULATORROOT=$(PLATFORMSROOT)/iPhoneSimulator.platform/Developer
DEVICEROOT=$(PLATFORMSROOT)/iPhoneOS.platform/Developer
IOSVERSION=$(shell defaults read $(PLATFORMSROOT)/iPhoneOS.platform/version CFBundleShortVersionString)

.cc.o:
	# mkdir -p ios-x86/$(dir $@)
	# $(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -arch x86_64 -c $< -o ios-x86/$@
	mkdir -p ios-arm/$(dir $@)
	export IPHONEOS_DEPLOYMENT_TARGET=7.0
	xcrun -sdk iphoneos $(CXX) $(CXXFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -arch armv7s -arch arm64 -c $< -o ios-arm/$@
	lipo ios-arm/$@ -create -output $@

.c.o:
	# mkdir -p ios-x86/$(dir $@)
	# $(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -arch x86_64 -c $< -o ios-x86/$@
	mkdir -p ios-arm/$(dir $@)
	export IPHONEOS_DEPLOYMENT_TARGET=7.0
	xcrun -sdk iphoneos $(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -arch armv7s -arch arm64 -c $< -o ios-arm/$@
	lipo ios-arm/$@ -create -output $@
  • Run TARGET_OS=IOS -j4 make static_lib in terminal. This will generate librocksdb.a under rocksdb source directory.

  • Add librocksdb.a to libraries in your xcode project from rocksdb source directory. make sure to check copy files.

  • Add RCTAsyncRocksDBStorage.mm and RCTAsyncRocksDBStorage.h to your xcode project. Make sure to name it correctly. extension needs to be .mm and .h

  • Xcode -> project -> build settings -> search enable bitcode. Set it to NO.

  • Xcode -> project -> build settings -> header search path. Add rocksdb/include directory path. for me its: "/Users/chirag/Desktop/rocksdb/include" and set it to recursive.

Hoepfully it works for you :)