Skip to content

Commit

Permalink
Using built version from gcc4.8 as default (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
linxGnu authored Oct 21, 2019
1 parent 74224fc commit 990d304
Show file tree
Hide file tree
Showing 23 changed files with 312 additions and 53 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ install:
- go get -u github.com/mattn/goveralls

script:
- GO111MODULE="on" go test -v -tags static_rocksdb -coverprofile=coverage.out
- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci
- GO111MODULE="on" go test -v -tags builtin_static -coverprofile=coverage.out
- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ DEST_LIB=$(DEST)/lib
DEST_INCLUDE=$(DEST)/include

MAKE_FLAGS = -j16
CFLAGS += ${EXTRA_CFLAGS}
CXXFLAGS += ${EXTRA_CXXFLAGS}
LDFLAGS += $(EXTRA_LDFLAGS)
MACHINE ?= $(shell uname -m)
ARFLAGS = ${EXTRA_ARFLAGS} rs
STRIPFLAGS = -S -x

# Dependencies and Rocksdb
Expand All @@ -24,6 +20,13 @@ ZSTD_COMMIT = ed65210c9b6635e21e67e60138f86d04a071681f
BZ2_COMMIT = 6a8690fc8d26c815e798c588f796eabe9d684cf0
ROCKSDB_COMMIT = d47cdbc1888440a75ecf43646fd1ddab8ebae9be

ROCKSDB_EXTRA_CXXFLAGS :=
ifeq ($(GOOS), darwin)
ROCKSDB_EXTRA_CXXFLAGS += -fPIC -O2 -w -I$(DEST_INCLUDE) -DZLIB -DBZIP2 -DSNAPPY -DLZ4 -DZSTD
else
ROCKSDB_EXTRA_CXXFLAGS += -fPIC -O2 -Wno-error=shadow -I$(DEST_INCLUDE) -DZLIB -DBZIP2 -DSNAPPY -DLZ4 -DZSTD
endif

default: prepare zlib snappy bz2 lz4 zstd rocksdb

.PHONY: prepare
Expand All @@ -39,17 +42,16 @@ zlib:
$(MAKE) clean && $(MAKE) $(MAKE_FLAGS) all
cp libs/zlib/libz.a $(DEST_LIB)/
cp libs/zlib/*.h $(DEST_INCLUDE)/
cp libs/zlib/libz.a /usr/local/lib/
cp libs/zlib/*.h /usr/local/include/

.PHONY: snappy
snappy:
git submodule update --remote --init --recursive -- libs/snappy
cd libs/snappy && git checkout $(SNAPPY_COMMIT)
cd libs/snappy && rm -rf build && mkdir -p build && cd build && \
CFLAGS='-O2 ${EXTRA_CFLAGS}' cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON .. && \
$(MAKE) clean && $(MAKE) $(MAKE_FLAGS) install
$(MAKE) clean && $(MAKE) $(MAKE_FLAGS) snappy
cp libs/snappy/build/libsnappy.a $(DEST_LIB)/
cp libs/snappy/build/*.h $(DEST_INCLUDE)/
cp libs/snappy/*.h $(DEST_INCLUDE)/

.PHONY: lz4
Expand All @@ -59,8 +61,6 @@ lz4:
cd libs/lz4 && $(MAKE) clean && $(MAKE) $(MAKE_FLAGS) CFLAGS='-fPIC -O2 ${EXTRA_CFLAGS}' lz4 lz4-release
cp libs/lz4/lib/liblz4.a $(DEST_LIB)/
cp libs/lz4/lib/*.h $(DEST_INCLUDE)/
cp libs/lz4/lib/liblz4.a /usr/local/lib/
cp libs/lz4/lib/*.h /usr/local/include/

.PHONY: zstd
zstd:
Expand All @@ -69,22 +69,22 @@ zstd:
cd libs/zstd/lib && $(MAKE) clean && DESTDIR=. PREFIX= $(MAKE) $(MAKE_FLAGS) CFLAGS='-fPIC -O2 ${EXTRA_CFLAGS}' default install
cp libs/zstd/lib/libzstd.a $(DEST_LIB)/
cp libs/zstd/lib/include/*.h $(DEST_INCLUDE)/
cp libs/zstd/lib/libzstd.a /usr/local/lib/
cp libs/zstd/lib/include/*.h /usr/local/include/

.PHONY: bz2
bz2:
cd libs/bzip2 && $(MAKE) $(MAKEFLAGS) CFLAGS='-fPIC -O2 -g -D_FILE_OFFSET_BITS=64 ${EXTRA_CFLAGS}' AR='ar ${EXTRA_ARFLAGS}' bzip2
cp libs/bzip2/libbz2.a $(DEST_LIB)/
cp libs/bzip2/*.h $(DEST_INCLUDE)/
cp libs/bzip2/libbz2.a /usr/local/lib/
cp libs/bzip2/*.h /usr/local/include/

.PHONY: rocksdb
rocksdb:
git submodule update --remote --init --recursive -- libs/rocksdb
cd libs/rocksdb && git checkout $(ROCKSDB_COMMIT) && $(MAKE) clean && \
CXXFLAGS='-fPIC -O2 -Wno-error=shadow ${EXTRA_CXXFLAGS}' $(MAKE) $(MAKE_FLAGS) static_lib
$(MAKE) $(MAKE_FLAGS) EXTRA_CXXFLAGS='$(ROCKSDB_EXTRA_CXXFLAGS)' EXTRA_LDFLAGS='-L$(DEST_LIB)' static_lib
cd libs/rocksdb && strip $(STRIPFLAGS) librocksdb.a
cp libs/rocksdb/librocksdb.a $(DEST_LIB)/
cp -R libs/rocksdb/include/rocksdb $(DEST_INCLUDE)/

.PHONY: test
test:
go test -v -count=1 -tags builtin_static
35 changes: 16 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,44 @@ convention of how/when to free c-mem, thus break the rule of [tecbot/gorocksdb](

## Install

### Default (Linux, Mac OS)
### Default - Builtin Static (Linux, Mac OS)

`grocksdb` contains built static version of `Rocksdb`. You have to do nothing on your machine. Just install it like other go libraries:
`grocksdb` contains built static version of `Rocksdb` with:
- gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
- Apple clang version 11.0.0 (clang-1100.0.33.8).

You have to do nothing on your machine. Just install it like other go libraries:

```bash
go get -u github.com/linxGnu/grocksdb

# Build your project with `static_rocksdb` tags:
go build -tags static_rocksdb
# Build your project with `builtin_static` tags:
go build -tags builtin_static
```

### Static lib (Linux, Mac OS)

If you don't trust my built-ready static version, you could build your own:

#### For CentOS:

```bash
sh build_centos.sh
```

#### Others:
If you don't trust my builtin/want to build with your compiler/env:

##### Prerequisite
- cmake 3.11+
- make
- For linking purpose:
- libsnappy-dev/snappy-devel
- zlib1g-dev/zlib-devel
- libbz2-dev/bzip2-devel
- liblz4-dev/lz4-devel

##### Build

Make sure to install libraries for linking before making targets.

```bash
# You could find `Makefile` at root of repository

# build static libs
make
```

# On success, you could remove above linked libraries safely
Then, build your project with tags (same as above):

```
go build -tags builtin_static
```

### Shared lib
Expand Down
16 changes: 0 additions & 16 deletions build_centos.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build static_rocksdb
// +build builtin_static

package grocksdb

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build static_rocksdb
// +build builtin_static

package grocksdb

Expand Down
62 changes: 62 additions & 0 deletions dist/darwin_amd64/include/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_
#define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_

/* Define to 1 if the compiler supports __builtin_ctz and friends. */
#define HAVE_BUILTIN_CTZ 1

/* Define to 1 if the compiler supports __builtin_expect. */
#define HAVE_BUILTIN_EXPECT 1

/* Define to 1 if you have the <byteswap.h> header file. */
/* #undef HAVE_BYTESWAP_H */

/* Define to 1 if you have a definition for mmap() in <sys/mman.h>. */
#define HAVE_FUNC_MMAP 1

/* Define to 1 if you have a definition for sysconf() in <unistd.h>. */
#define HAVE_FUNC_SYSCONF 1

/* Define to 1 to use the gflags package for command-line parsing. */
/* #undef HAVE_GFLAGS */

/* Define to 1 if you have Google Test. */
/* #undef HAVE_GTEST */

/* Define to 1 if you have the `lzo2' library (-llzo2). */
/* #undef HAVE_LIBLZO2 */

/* Define to 1 if you have the `z' library (-lz). */
#define HAVE_LIBZ 1

/* Define to 1 if you have the <sys/endian.h> header file. */
/* #undef HAVE_SYS_ENDIAN_H */

/* Define to 1 if you have the <sys/mman.h> header file. */
#define HAVE_SYS_MMAN_H 1

/* Define to 1 if you have the <sys/resource.h> header file. */
#define HAVE_SYS_RESOURCE_H 1

/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1

/* Define to 1 if you have the <sys/uio.h> header file. */
#define HAVE_SYS_UIO_H 1

/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1

/* Define to 1 if you have the <windows.h> header file. */
/* #undef HAVE_WINDOWS_H */

/* Define to 1 if you target processors with SSSE3+ and have <tmmintrin.h>. */
#define SNAPPY_HAVE_SSSE3 1

/* Define to 1 if you target processors with BMI2+ and have <bmi2intrin.h>. */
#define SNAPPY_HAVE_BMI2 0

/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
/* #undef SNAPPY_IS_BIG_ENDIAN */

#endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_
74 changes: 74 additions & 0 deletions dist/darwin_amd64/include/snappy-stubs-public.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2011 Google Inc. All Rights Reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Various type stubs for the open-source version of Snappy.
//
// This file cannot include config.h, as it is included from snappy.h,
// which is a public header. Instead, snappy-stubs-public.h is generated by
// from snappy-stubs-public.h.in at configure time.

#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
#define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_

#include <cstddef>
#include <cstdint>
#include <string>

#if 1 // HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif // HAVE_SYS_UIO_H

#define SNAPPY_MAJOR 1
#define SNAPPY_MINOR 1
#define SNAPPY_PATCHLEVEL 7
#define SNAPPY_VERSION \
((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)

namespace snappy {

using int8 = std::int8_t;
using uint8 = std::uint8_t;
using int16 = std::int16_t;
using uint16 = std::uint16_t;
using int32 = std::int32_t;
using uint32 = std::uint32_t;
using int64 = std::int64_t;
using uint64 = std::uint64_t;

#if !1 // !HAVE_SYS_UIO_H
// Windows does not have an iovec type, yet the concept is universally useful.
// It is simple to define it ourselves, so we put it inside our own namespace.
struct iovec {
void* iov_base;
size_t iov_len;
};
#endif // !HAVE_SYS_UIO_H

} // namespace snappy

#endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
Binary file modified dist/darwin_amd64/lib/libbz2.a
Binary file not shown.
Binary file modified dist/darwin_amd64/lib/liblz4.a
Binary file not shown.
Binary file modified dist/darwin_amd64/lib/librocksdb.a
Binary file not shown.
Binary file modified dist/darwin_amd64/lib/libsnappy.a
Binary file not shown.
Binary file modified dist/darwin_amd64/lib/libz.a
Binary file not shown.
Binary file modified dist/darwin_amd64/lib/libzstd.a
Binary file not shown.
62 changes: 62 additions & 0 deletions dist/linux_amd64/include/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_
#define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_

/* Define to 1 if the compiler supports __builtin_ctz and friends. */
#define HAVE_BUILTIN_CTZ 1

/* Define to 1 if the compiler supports __builtin_expect. */
#define HAVE_BUILTIN_EXPECT 1

/* Define to 1 if you have the <byteswap.h> header file. */
#define HAVE_BYTESWAP_H 1

/* Define to 1 if you have a definition for mmap() in <sys/mman.h>. */
#define HAVE_FUNC_MMAP 1

/* Define to 1 if you have a definition for sysconf() in <unistd.h>. */
#define HAVE_FUNC_SYSCONF 1

/* Define to 1 to use the gflags package for command-line parsing. */
/* #undef HAVE_GFLAGS */

/* Define to 1 if you have Google Test. */
/* #undef HAVE_GTEST */

/* Define to 1 if you have the `lzo2' library (-llzo2). */
/* #undef HAVE_LIBLZO2 */

/* Define to 1 if you have the `z' library (-lz). */
/* #undef HAVE_LIBZ */

/* Define to 1 if you have the <sys/endian.h> header file. */
/* #undef HAVE_SYS_ENDIAN_H */

/* Define to 1 if you have the <sys/mman.h> header file. */
#define HAVE_SYS_MMAN_H 1

/* Define to 1 if you have the <sys/resource.h> header file. */
#define HAVE_SYS_RESOURCE_H 1

/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1

/* Define to 1 if you have the <sys/uio.h> header file. */
#define HAVE_SYS_UIO_H 1

/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1

/* Define to 1 if you have the <windows.h> header file. */
/* #undef HAVE_WINDOWS_H */

/* Define to 1 if you target processors with SSSE3+ and have <tmmintrin.h>. */
#define SNAPPY_HAVE_SSSE3 0

/* Define to 1 if you target processors with BMI2+ and have <bmi2intrin.h>. */
#define SNAPPY_HAVE_BMI2 0

/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
/* #undef SNAPPY_IS_BIG_ENDIAN */

#endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_
Loading

0 comments on commit 990d304

Please sign in to comment.