Update RocksDB's Java bindings to support multiple native RocksDB builds in the same Jar file. Cross build RocksDB for linux32 and linux64 using Vagrant. Build a cross-platform fat jar that contains osx, linux32, and linux64 RocksDB static builds.
This commit is contained in:
parent
d439451fab
commit
9db13987b1
14
Makefile
14
Makefile
@ -270,6 +270,7 @@ clean:
|
||||
-rm -rf ios-x86/* ios-arm/*
|
||||
-find . -name "*.[oda]" -exec rm {} \;
|
||||
-find . -type f -regex ".*\.\(\(gcda\)\|\(gcno\)\)" -exec rm {} \;
|
||||
-rm -rf bzip2* snappy* zlib*
|
||||
tags:
|
||||
ctags * -R
|
||||
cscope -b `find . -name '*.cc'` `find . -name '*.h'`
|
||||
@ -510,11 +511,14 @@ ldb: tools/ldb.o $(LIBOBJECTS)
|
||||
|
||||
JNI_NATIVE_SOURCES = ./java/rocksjni/*.cc
|
||||
JAVA_INCLUDE = -I$(JAVA_HOME)/include/ -I$(JAVA_HOME)/include/linux
|
||||
ROCKSDBJNILIB = librocksdbjni.so
|
||||
ROCKSDB_JAR = rocksdbjni.jar
|
||||
ARCH := $(shell getconf LONG_BIT)
|
||||
ROCKSDBJNILIB = librocksdbjni-linux$(ARCH).so
|
||||
ROCKSDB_JAR = rocksdbjni-linux$(ARCH).jar
|
||||
ROCKSDB_JAR_ALL = rocksdbjni-all.jar
|
||||
|
||||
ifeq ($(PLATFORM), OS_MACOSX)
|
||||
ROCKSDBJNILIB = librocksdbjni.jnilib
|
||||
ROCKSDBJNILIB = librocksdbjni-osx.jnilib
|
||||
ROCKSDB_JAR = rocksdbjni-osx.jar
|
||||
JAVA_INCLUDE = -I/System/Library/Frameworks/JavaVM.framework/Headers/
|
||||
endif
|
||||
|
||||
@ -549,6 +553,10 @@ rocksdbjavastatic: libz.a libbz2.a libsnappy.a
|
||||
cd java;jar -cf $(ROCKSDB_JAR) org/rocksdb/*.class org/rocksdb/util/*.class HISTORY*.md $(ROCKSDBJNILIB)
|
||||
|
||||
|
||||
rocksdbjavastaticrelease: rocksdbjavastatic
|
||||
cd java/crossbuild && vagrant destroy -f && vagrant up
|
||||
cd java;jar -cf $(ROCKSDB_JAR_ALL) org/rocksdb/*.class org/rocksdb/util/*.class HISTORY*.md librocksdbjni-*.so librocksdbjni-*.jnilib
|
||||
|
||||
rocksdbjava:
|
||||
OPT="-fPIC -DNDEBUG -O2" $(MAKE) $(LIBRARY) -j32
|
||||
cd java;$(MAKE) java;
|
||||
|
@ -1,12 +1,16 @@
|
||||
NATIVE_JAVA_CLASSES = org.rocksdb.RocksDB org.rocksdb.Options org.rocksdb.WriteBatch org.rocksdb.WriteBatchInternal org.rocksdb.WriteBatchTest org.rocksdb.WriteOptions org.rocksdb.BackupableDB org.rocksdb.BackupableDBOptions org.rocksdb.Statistics org.rocksdb.RocksIterator org.rocksdb.VectorMemTableConfig org.rocksdb.SkipListMemTableConfig org.rocksdb.HashLinkedListMemTableConfig org.rocksdb.HashSkipListMemTableConfig org.rocksdb.PlainTableConfig org.rocksdb.BlockBasedTableConfig org.rocksdb.ReadOptions org.rocksdb.Filter org.rocksdb.BloomFilter org.rocksdb.RestoreOptions org.rocksdb.RestoreBackupableDB org.rocksdb.RocksEnv org.rocksdb.GenericRateLimiterConfig
|
||||
|
||||
NATIVE_INCLUDE = ./include
|
||||
ROCKSDB_JAR = rocksdbjni.jar
|
||||
ARCH := $(shell getconf LONG_BIT)
|
||||
ROCKSDB_JAR = rocksdbjni-linux$(ARCH).jar
|
||||
|
||||
ifeq ($(PLATFORM), OS_MACOSX)
|
||||
ROCKSDB_JAR = rocksdbjni-osx.jar
|
||||
endif
|
||||
|
||||
clean:
|
||||
-find . -name "*.class" -exec rm {} \;
|
||||
-find . -name "hs*.log" -exec rm {} \;
|
||||
rm -f $(ROCKSDB_JAR)
|
||||
|
||||
java:
|
||||
javac org/rocksdb/util/*.java org/rocksdb/*.java
|
||||
|
0
java/crossbuild/README.md
Normal file
0
java/crossbuild/README.md
Normal file
25
java/crossbuild/Vagrantfile
vendored
Normal file
25
java/crossbuild/Vagrantfile
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
||||
VAGRANTFILE_API_VERSION = "2"
|
||||
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
config.vm.define "linux32" do |linux32|
|
||||
linux32.vm.box = "ubuntu/trusty32"
|
||||
linux32.vm.provision :shell, path: "build-linux.sh"
|
||||
linux32.vm.synced_folder "../..", "/rocksdb"
|
||||
end
|
||||
|
||||
config.vm.define "linux64" do |linux64|
|
||||
linux64.vm.box = "ubuntu/trusty64"
|
||||
linux64.vm.provision :shell, path: "build-linux.sh"
|
||||
linux64.vm.synced_folder "../..", "/rocksdb"
|
||||
end
|
||||
|
||||
config.vm.provider "virtualbox" do |v|
|
||||
v.memory = 2048
|
||||
v.cpus = 4
|
||||
end
|
||||
end
|
11
java/crossbuild/build-linux.sh
Executable file
11
java/crossbuild/build-linux.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
# install all required packages for rocksdb
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install git make gcc g++ libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev default-jdk
|
||||
|
||||
# set java home so we can build rocksdb jars
|
||||
export JAVA_HOME=$(echo /usr/lib/jvm/java-7-openjdk*)
|
||||
cd /rocksdb
|
||||
make jclean clean -j 4 rocksdbjavastatic
|
||||
sudo shutdown -h now
|
||||
|
@ -1,16 +1,16 @@
|
||||
package org.rocksdb;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import org.rocksdb.util.Environment;
|
||||
|
||||
/**
|
||||
* This class is used to load the RocksDB shared library from within the jar.
|
||||
* The shared library is extracted to a temp folder and loaded from there.
|
||||
*/
|
||||
public class NativeLibraryLoader {
|
||||
private static String sharedLibraryName = "librocksdbjni.so";
|
||||
private static String sharedLibraryName = Environment.getJniLibraryName("rockdsb");
|
||||
private static String tempFilePrefix = "librocksdbjni";
|
||||
private static String tempFileSuffix = ".so";
|
||||
private static String tempFileSuffix = "." + Environment.getJniLibraryExtension();
|
||||
|
||||
public static void loadLibraryFromJar(String tmpDir)
|
||||
throws IOException {
|
||||
|
@ -2,6 +2,7 @@ package org.rocksdb.util;
|
||||
|
||||
public class Environment {
|
||||
private static String OS = System.getProperty("os.name").toLowerCase();
|
||||
private static String ARCH = System.getProperty("os.arch").toLowerCase();
|
||||
|
||||
public static boolean isWindows() {
|
||||
return (OS.indexOf("win") >= 0);
|
||||
@ -17,6 +18,10 @@ public class Environment {
|
||||
OS.indexOf("aix") >= 0);
|
||||
}
|
||||
|
||||
public static boolean is64Bit() {
|
||||
return (ARCH.indexOf("64") > 0);
|
||||
}
|
||||
|
||||
public static String getSharedLibraryName(String name) {
|
||||
if (isUnix()) {
|
||||
return String.format("lib%s.so", name);
|
||||
@ -28,10 +33,15 @@ public class Environment {
|
||||
|
||||
public static String getJniLibraryName(String name) {
|
||||
if (isUnix()) {
|
||||
return String.format("lib%s.so", name);
|
||||
String arch = (is64Bit()) ? "64" : "32";
|
||||
return String.format("lib%s-linux%s.so", name, arch);
|
||||
} else if (isMac()) {
|
||||
return String.format("lib%s.jnilib", name);
|
||||
return String.format("lib%s-osx.jnilib", name);
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public static String getJniLibraryExtension() {
|
||||
return (isMac()) ? ".jnilib" : ".so";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user