Skip to content

Commit

Permalink
wip: rocksdb binding ld options
Browse files Browse the repository at this point in the history
  • Loading branch information
gdiazlo committed Mar 14, 2019
1 parent 1abf0b6 commit e22dbf2
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ tests/cloud/aws/outputs.tf
tests/cloud/aws/results
tests/cloud/aws/to_upload/rendered
tests/results
c-deps/libs

# Documents
*.pdf
TODO.md
Expand Down
10 changes: 9 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
[submodule "github.com/facebook/rocksdb"]
path = c-deps/rocksdb
url = https://github.com/facebook/rocksdb.git

[submodule "github.com/google/snappy"]
path = c-deps/snappy
url = https://github.com/google/snappy.git

[submodule "github.com/lz4/lz4"]
path = c-deps/lz4
url = https://github.com/lz4/lz4.git

[submodule "github.com/enthought/bzip2-1.0.6"]
path = c-deps/bzip2
url = https://github.com/enthought/bzip2-1.0.6.git

[submodule "github.com/facebook/zstd"]
path = c-deps/zstd
url = https://github.com/facebook/zstd.git

[submodule "github.com/madler/zlib"]
path = c-deps/zlib
url = https://github.com/madler/zlib.git


[submodule "github.com/jemalloc/jemalloc"]
path = c-deps/jemalloc
url = https://github.com/jemalloc/jemalloc
111 changes: 103 additions & 8 deletions c-deps/builddeps.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,109 @@
#!/usr/bin/env bash

BASE=$(pwd)
LIBS="$BASE/libs"

# build jemalloc
if [ ! -f $LIBS/libjemalloc.so.2 ]; then
cd jemalloc
bash autogen.sh
make -j8
cp lib/libjemalloc.so.2 ../libs/
cp lib/libjemalloc.a ../libs
cd ../libs
ln -s ibjemalloc.so.2 libjemalloc.so
fi

cd $BASE

# # build bzip2 shared lib
# if [ ! -f $LIBS/libbz2.so.1.0.6 ]; then
# cd bzip2
# make -j8 -f Makefile-libbz2_so
# make -j8
# cp libbz2.so.1.0.6 ../libs/
# cp libbz2.a ../libs/
# cd ../libs/
# ln -s libbz2.so.1.0.6 libbz2.so.1
# ln -s libbz2.so.1.0.6 libbz2.so
# fi

# cd $BASE

# # build lz4 shared lib
# if [ ! -f $LIBS/liblz4.so.1.8.3 ]; then
# cd lz4
# make -j8
# cp lib/liblz4.so.1.8.3 ../libs/
# cp lib/liblz4.a ../libs
# cd ../libs
# ln -s liblz4.so.1.8.3 liblz4.so.1
# ln -s liblz4.so.1.8.3 liblz4.so
# fi

# cd $BASE

# build snappy shared lib
if [ ! -f $LIBS/libsnappy.so.1.1.7 ]; then
cd snappy
mkdir build
cd build
cmake ../
sed -i.bak s/BUILD_SHARED_LIBS:BOOL=OFF/BUILD_SHARED_LIBS:BOOL=ON/g CMakeCache.txt
make -j8
cp libsnappy.so.1.1.7 ../../libs/
cp libsnappy.a ../../libs/
cp snappy-stub-public.h ../
cd ../../libs/
ln -s libsnappy.so.1.1.7 libsnappy.so.1
ln -s libsnappy.so.1.1.7 libsnappy.so
fi

cd $BASE

# # build zlib shared lib
# if [ ! -f $LIBS/libz.so.1.2.9 ]; then
# cd zlib
# ./configure
# make -j8
# cp libz.so.1.2.9 ../libs/
# cp libz.a ../libs/
# cd ../libs
# ln -s libz.so.1.2.9 libz.so.1
# ln -s libz.so.1.2.9 libz.so
# fi

# cd $BASE

# # build zstd shared lib
# if [ ! -f $LIBS/libzstd.so.0.4.2 ]; then
# cd zstd
# cd lib
# make -j8
# cp libzstd.so.0.4.2 ../../libs
# cp libzstd.a ../../libs
# cd ../../libs
# ln -s libzstd.so.0.4.2 libzstd.so.0
# ln -s libzstd.so.0.4.2 libzstd.so
# fi

cd $BASE

# build rocksdb shared with those libraries
cd rocksdb
DEBUG_LEVEL=0
PORTABLE=1
mkdir -p build
cd build


for lib in libbz2.a liblz4.a libsnappy.a libz.a libzstd.a; do
make $lib
done
make static_lib
strip *.a
cd ..
# -DWITH_LZ4=ON -DLZ4_LIBRARIES="$LIBS/liblz4.a" -DLZ4_INCLUDE_DIR="$BASE/lz4/lib/" \
# -DWITH_ZSTD=ON -DZSTD_LIBRARIES="$LIBS/libzstd.a" -DZSTD_INCLUDE_DIR="$BASE/zstd" \
# -DWITH_BZ2=ON -DBZIP2_LIBRARIES="$LIBS/libbz2.a" -DBZIP2_INCLUDE_DIR="$BASE/bzip2" \
# -DWITH_ZLIB=ON -DZLIB_LIBRARIES="$LIBS/libz.a" -DZLIB_INCLUDE_DIR="$BASE/zlib" \

cmake -DWITH_GFLAGS=OFF -DPORTABLE=ON \
-DWITH_SNAPPY=ON -DSNAPPY_LIBRARIES="$LIBS/libsnappy.a" -DSNAPPY_INCLUDE_DIR="$BASE/snappy" \
-DWITH_JEMALLOC=ON -DJEMALLOC_LIBRARIES="$LIBS/libjemalloc.a" -DJEMALLOC_INCLUDE_DIR="$BASE/jemalloc/include" \
-DCMAKE_BUILD_TYPE=Release -DUSE_RTTI=1 ../
make -j8 rocksdb

cp librocksdb.a* ../libs
1 change: 1 addition & 0 deletions c-deps/jemalloc
Submodule jemalloc added at 61efbd
6 changes: 3 additions & 3 deletions rocksdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

package rocksdb

// #cgo LDFLAGS: -L../c-deps/rocksdb/
// #cgo LDFLAGS: -l:librocksdb.a -l:libstdc++.a -l:libz.a -l:libbz2.a -l:libsnappy.a -l:libzstd.a -lm
// #include "../c-deps/rocksdb/include/rocksdb/c.h"
// #include <rocksdb/c.h>
// #include <stdlib.h>
import "C"
import (
"errors"
"unsafe"
)

// -llz4 -lz -lbz2 -lzstd

// DB is a reusable handler to a RocksDB database on disk, created by Open.
type DB struct {
db *C.rocksdb_t
Expand Down
27 changes: 27 additions & 0 deletions rocksdb/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2018 Banco Bilbao Vizcaya Argentaria, S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package rocksdb

// #cgo CFLAGS: -I${SRCDIR}/../c-deps/rocksdb/include/
// #cgo LDFLAGS: -L${SRCDIR}/../c-deps/libs
// #cgo LDFLAGS: ${SRCDIR}/..c-deps/libs/librocksdb.a
// #cgo LDFLAGS: ${SRCDIR}/../c-deps/libs/libjemalloc.a
// #cgo LDFLAGS: ${SRCDIR}/../c-deps/libs/libsnappy.a
// #cgo LDFLAGS: -lstdc++
// #cgo LDFLAGS: -ldl
// #cgo LDFLAGS: -lm
import "C"
4 changes: 1 addition & 3 deletions rocksdb/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package rocksdb

// #cgo LDFLAGS: -L../c-deps/rocksdb/
// #cgo LDFLAGS: -l:librocksdb.a -l:libstdc++.a -l:libz.a -l:libbz2.a -l:libsnappy.a -l:libzstd.a -lm
// #include "../c-deps/rocksdb/include/rocksdb/c.h"
// #include <rocksdb/c.h>
import "C"

type CompressionType uint
Expand Down

0 comments on commit e22dbf2

Please sign in to comment.