Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce rebar3_external plugin to handle leveldb source code #274

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions c_src/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LEVELDB_VSN ?= "2.0.38"
LEVELDB_SRC := $(REBAR_DEPS_DIR)/leveldb/c_src
C_SRC_DIR := $(shell pwd)
PROJECT_DIR := $(abspath $(C_SRC_DIR)/..)
TARGET_DIR := $(PROJECT_DIR)/priv/
Expand All @@ -11,8 +11,8 @@ TOOLS = \
sst_scan

LDFLAGS := $(LDFLAGS) -lsnappy -lpthread
CFLAGS := $(CFLAGS) -I. -I $(C_SRC_DIRC_SRC_DIR)/leveldb/include -fPIC
CXXFLAGS := $(CXXFLAGS) -I. -I $(C_SRC_DIR)/leveldb/include -fPIC
CFLAGS := $(CFLAGS) -I. -I $(LEVELDB_SRC)/include -fPIC
CXXFLAGS := $(CXXFLAGS) -I. -I $(LEVELDB_SRC)/include -fPIC
TEST_CXXFLAGS := $(CXXFLAGS) -Wno-narrowing

ifeq ($(shell uname -s), Darwin)
Expand All @@ -33,25 +33,17 @@ ifeq ($(shell uname -s), Darwin)
TEST_CXXFLAGS += -Wno-c++11-narrowing
endif

get-deps:
git config --global --add safe.directory /__w/eleveldb/eleveldb
echo "ubuntu-latest image with otp-22, are you happy now?"
if [ ! -d leveldb ]; then \
git clone --depth=1 --branch=$(LEVELDB_VSN) https://github.com/basho/leveldb && \
(cd leveldb && git submodule update --depth 1 --init); \
fi

compile: get-deps ldb
for tool in $(TOOLS); do cp leveldb/$$tool $(TARGET_DIR); done
compile: ldb
for tool in $(TOOLS); do cp $(LEVELDB_SRC)/$$tool $(TARGET_DIR); done

ldb:
@echo "Building LevelDB..."
$(MAKE) LDFLAGS="" -C leveldb all
$(MAKE) LDFLAGS="$(LDFLAGS)" -C leveldb tools
$(MAKE) LDFLAGS="" -C $(LEVELDB_SRC) all
$(MAKE) LDFLAGS="$(LDFLAGS)" -C $(LEVELDB_SRC) tools

clean:
$(MAKE) -C leveldb clean
$(MAKE) -C $(LEVELDB_SRC) clean
for tool in $(TOOLS); do rm -f $(TARGET_DIR)$$tool; done

test: compile
$(MAKE) LDFLAGS="$(LDFLAGS)" CXXFLAGS="$(TEST_CXXFLAGS)" CFLAGS="$(CFLAGS)" -C leveldb test
$(MAKE) LDFLAGS="$(LDFLAGS)" CXXFLAGS="$(TEST_CXXFLAGS)" CFLAGS="$(CFLAGS)" -C $(LEVELDB_SRC) test
20 changes: 15 additions & 5 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@

{eunit_opts, [verbose]}.

{plugins, [{eqc_rebar, {git, "https://github.com/Quviq/eqc-rebar", {branch, "master"}}}, pc]}.
{plugins, [
{eqc_rebar, {git, "https://github.com/Quviq/eqc-rebar", {branch, "master"}}},
pc,
rebar3_external
]}.

{deps, [
{leveldb,
{external, {git, "https://github.com/basho/leveldb", {tag, "2.0.38"}}, "c_src", [
{description, "leveldb: A key-value store"},
{vsn, "2.0.38"}
]}}
]}.

{provider_hooks, [
{post, [
Expand Down Expand Up @@ -32,13 +44,11 @@

{port_env, [
%% Make sure to set -fPIC when compiling leveldb
{"CXXFLAGS", "$CXXFLAGS -Wall -O3 -fPIC -I c_src/leveldb/include -I c_src/leveldb"},
{"LDFLAGS", "$LDFLAGS c_src/leveldb/libleveldb.a -lsnappy -lstdc++"}
{"CXXFLAGS", "$CXXFLAGS -Wall -O3 -fPIC -I $REBAR_DEPS_DIR/leveldb/c_src/include -I $REBAR_DEPS_DIR/leveldb/c_src"},
{"LDFLAGS", "$LDFLAGS $REBAR_DEPS_DIR/leveldb/c_src/libleveldb.a -lsnappy -lstdc++"}
]}.

{pre_hooks, [
{"(linux|darwin|solaris)", 'get-deps', "./make -C c_src get-deps"},
{"(freebsd|netbsd|openbsd)", 'get-deps', "gmake -C c_src get-deps"},
{"(linux|darwin|solaris)", compile, "make -C c_src compile"},
{"(freebsd|netbsd|openbsd)", compile, "gmake -C c_src compile"},
{"(linux|darwin|solaris)", eunit, "make -C c_src test"},
Expand Down
6 changes: 5 additions & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[].
[{<<"leveldb">>,
{external,{git,"https://github.com/basho/leveldb",{tag,"2.0.38"}},
"c_src",
[{description,"leveldb: A key-value store"},{vsn,"2.0.38"}]},
0}].