From fb7a71034b77c49002dddea0e6cee379bcb553f1 Mon Sep 17 00:00:00 2001 From: Riku <46352032+rikublock@users.noreply.github.com> Date: Fri, 8 Apr 2022 22:21:51 +0200 Subject: [PATCH] [feature] add option to build portable binaries (#685) Co-authored-by: Martin --- Makefile | 3 ++- build/docker/bin/Dockerfile | 3 ++- docs/build.md | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 714463e9..dfe5b5f3 100644 --- a/Makefile +++ b/Makefile @@ -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)) @@ -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 diff --git a/build/docker/bin/Dockerfile b/build/docker/bin/Dockerfile index b749e45f..d11c7838 100644 --- a/build/docker/bin/Dockerfile +++ b/build/docker/bin/Dockerfile @@ -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 && \ @@ -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 diff --git a/docs/build.md b/docs/build.md index 9900fbac..a464ccb5 100644 --- a/docs/build.md +++ b/docs/build.md @@ -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*. @@ -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 \