Browse Source

simplified reproducible buildsystem (#5477)

pull/5487/head
Alessio Treglia 4 years ago
committed by GitHub
parent
commit
93b9bab932
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 5 deletions
  1. +1
    -0
      .gitignore
  2. +24
    -5
      Makefile
  3. +40
    -0
      build.sh

+ 1
- 0
.gitignore View File

@ -4,6 +4,7 @@
*.bak
.DS_Store
build/*
artifacts/*
rpc/test/.tendermint
.tendermint
remote_dump


+ 24
- 5
Makefile View File

@ -1,5 +1,7 @@
#!/usr/bin/make -f
PACKAGES=$(shell go list ./...)
OUTPUT?=build/tendermint
BUILDDIR ?= $(CURDIR)/build
BUILD_TAGS?=tendermint
LD_FLAGS = -X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`
@ -56,14 +58,17 @@ include tests.mk
### Build Tendermint ###
###############################################################################
build:
CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o $(OUTPUT) ./cmd/tendermint/
build: $(BUILDDIR)/
CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o $(BUILDDIR)/ ./cmd/tendermint/
.PHONY: build
install:
CGO_ENABLED=$(CGO_ENABLED) go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/tendermint
.PHONY: install
$(BUILDDIR)/:
mkdir -p $@
###############################################################################
### Protobuf ###
###############################################################################
@ -142,7 +147,7 @@ draw_deps:
get_deps_bin_size:
@# Copy of build recipe with additional flags to perform binary size analysis
$(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/ 2>&1))
$(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(BUILDDIR)/ ./cmd/tendermint/ 2>&1))
@find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
@echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
.PHONY: get_deps_bin_size
@ -210,7 +215,7 @@ sync-docs:
###############################################################################
build-docker: build-linux
cp $(OUTPUT) DOCKER/tendermint
cp $(BUILDDIR)/tendermint DOCKER/tendermint
docker build --label=tendermint --tag="tendermint/tendermint" DOCKER
rm -rf DOCKER/tendermint
.PHONY: build-docker
@ -264,3 +269,17 @@ endif
contract-tests:
dredd
.PHONY: contract-tests
clean:
rm -rf $(CURDIR)/artifacts/ $(BUILDDIR)/
build-reproducible:
docker rm latest-build || true
docker run --volume=$(CURDIR):/sources:ro \
--env TARGET_PLATFORMS='linux/amd64 linux/arm64 darwin/amd64 windows/amd64' \
--env APP=tendermint \
--env COMMIT=$(shell git rev-parse --short=8 HEAD) \
--env VERSION=$(shell git describe --tags) \
--name latest-build cosmossdk/rbuilder:latest
docker cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/
.PHONY: build-reproducible

+ 40
- 0
build.sh View File

@ -0,0 +1,40 @@
#!/bin/bash
set -ue
# Expect the following envvars to be set:
# - APP
# - VERSION
# - COMMIT
# - TARGET_OS
# - LEDGER_ENABLED
# - DEBUG
# Source builder's functions library
. /usr/local/share/cosmos-sdk/buildlib.sh
# These variables are now available
# - BASEDIR
# - OUTDIR
# Build for each os-architecture pair
for platform in ${TARGET_PLATFORMS} ; do
# This function sets GOOS, GOARCH, and OS_FILE_EXT environment variables
# according to the build target platform. OS_FILE_EXT is empty in all
# cases except when the target platform is 'windows'.
setup_build_env_for_platform "${platform}"
make clean
echo Building for $(go env GOOS)/$(go env GOARCH) >&2
GOROOT_FINAL="$(go env GOROOT)" \
make build LDFLAGS=-buildid=${VERSION} COMMIT=${COMMIT}
mv ./build/${APP}${OS_FILE_EXT} ${OUTDIR}/${APP}-${VERSION}-$(go env GOOS)-$(go env GOARCH)${OS_FILE_EXT}
# This function restore the build environment variables to their
# original state.
restore_build_env
done
# Generate and display build report.
generate_build_report
cat ${OUTDIR}/build_report

Loading…
Cancel
Save