Skip to content

Commit

Permalink
[feature] add option to build portable binaries (#685)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin <martin.boehm@1mbsoftware.net>
  • Loading branch information
rikublock and martinboehm authored Apr 8, 2022
1 parent 5802a43 commit fb7a710
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PACKAGER = $(shell id -u):$(shell id -g)
BASE_IMAGE = $$(awk -F= '$$1=="ID" { print $$2 ;}' /etc/os-release):$$(awk -F= '$$1=="VERSION_ID" { print $$2 ;}' /etc/os-release | tr -d '"')
NO_CACHE = false
TCMALLOC =
PORTABLE = 0
ARGS ?=

TARGETS=$(subst .json,, $(shell ls configs/coins))
Expand Down Expand Up @@ -46,7 +47,7 @@ build-images: clean-images
.bin-image:
@if [ $$(build/tools/image_status.sh $(BIN_IMAGE):latest build/docker) != "ok" ]; then \
echo "Building image $(BIN_IMAGE) from $(BASE_IMAGE)"; \
docker build --no-cache=$(NO_CACHE) --build-arg TCMALLOC=$(TCMALLOC) --build-arg BASE_IMAGE=$(BASE_IMAGE) -t $(BIN_IMAGE) build/docker/bin; \
docker build --no-cache=$(NO_CACHE) --build-arg TCMALLOC=$(TCMALLOC) --build-arg BASE_IMAGE=$(BASE_IMAGE) --build-arg PORTABLE_ROCKSDB=$(PORTABLE) -t $(BIN_IMAGE) build/docker/bin; \
else \
echo "Image $(BIN_IMAGE) is up to date"; \
fi
Expand Down
3 changes: 2 additions & 1 deletion build/docker/bin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ARG BASE_IMAGE
FROM $BASE_IMAGE
ARG DEBIAN_FRONTEND=noninteractive
ARG PORTABLE_ROCKSDB

RUN apt-get update && \
apt-get upgrade -y && \
Expand Down Expand Up @@ -36,7 +37,7 @@ RUN echo -n "GOPATH: " && echo $GOPATH

# install rocksdb
RUN cd /opt && git clone -b $ROCKSDB_VERSION --depth 1 https://github.com/facebook/rocksdb.git
RUN cd /opt/rocksdb && CFLAGS=-fPIC CXXFLAGS=-fPIC make -j 4 release
RUN cd /opt/rocksdb && CFLAGS=-fPIC CXXFLAGS=-fPIC PORTABLE=$PORTABLE_ROCKSDB make -j 4 release
RUN strip /opt/rocksdb/ldb /opt/rocksdb/sst_dump && \
cp /opt/rocksdb/ldb /opt/rocksdb/sst_dump /build

Expand Down
5 changes: 4 additions & 1 deletion docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ command: `make NO_CACHE=true all-bitcoin`.

`TCMALLOC`: RocksDB, the storage engine used by Blockbook, allows to use alternative memory allocators. Use the `TCMALLOC` variable to specify Google's TCMalloc allocator `make TCMALLOC=true all-bitcoin`. To run Blockbook built with TCMalloc, the library must be installed on the target server, for example by `sudo apt-get install google-perftools`.

`PORTABLE`: By default, the RocksDB binaries shipped with Blockbook are optimized for the platform you're compiling on (-march=native or the equivalent). If you want to build a portable binary, use `make PORTABLE=1 all-bitcoin`.

### Naming conventions and versioning

All configuration keys described below are in coin definition file in *configs/coins*.
Expand Down Expand Up @@ -199,7 +201,8 @@ export PATH=$PATH:$GOPATH/bin
```

Install RocksDB: https://github.com/facebook/rocksdb/blob/master/INSTALL.md
and compile the static_lib and tools
and compile the static_lib and tools. Optionally, consider adding `PORTABLE=1` before the
make command to create a portable binary.

```
sudo apt-get update && sudo apt-get install -y \
Expand Down

0 comments on commit fb7a710

Please sign in to comment.