github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/Makefile (about)

     1  PACKAGES=$(shell go list ./...)
     2  SRCPATH=$(shell pwd)
     3  OUTPUT?=build/ostracon
     4  
     5  INCLUDE = -I=${GOPATH}/src/github.com/line/ostracon -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
     6  BUILD_TAGS ?= ostracon
     7  VERSION := $(shell git describe --always)
     8  ifeq ($(LIBSODIUM), 1)
     9    BUILD_TAGS += libsodium
    10    LIBSODIUM_TARGET = libsodium
    11  else
    12    BUILD_TAGS += r2ishiguro
    13    LIBSODIUM_TARGET =
    14  endif
    15  LD_FLAGS = -X github.com/line/ostracon/version.OCCoreSemVer=$(VERSION)
    16  BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
    17  HTTPS_GIT := https://github.com/line/ostracon.git
    18  DOCKER_BUF := docker run -v $(shell pwd):/workspace --workdir /workspace bufbuild/buf
    19  CGO_ENABLED ?= 0
    20  TARGET_OS ?= $(shell go env GOOS)
    21  TARGET_ARCH ?= $(shell go env GOARCH)
    22  
    23  # handle nostrip
    24  ifeq (,$(findstring nostrip,$(OSTRACON_BUILD_OPTIONS)))
    25    BUILD_FLAGS += -trimpath
    26    LD_FLAGS += -s -w
    27  endif
    28  
    29  # handle race
    30  ifeq (race,$(findstring race,$(OSTRACON_BUILD_OPTIONS)))
    31    BUILD_FLAGS += -race
    32  endif
    33  
    34  # handle cleveldb
    35  ifeq (cleveldb,$(findstring cleveldb,$(OSTRACON_BUILD_OPTIONS)))
    36    BUILD_TAGS += cleveldb
    37  endif
    38  
    39  # handle badgerdb
    40  ifeq (badgerdb,$(findstring badgerdb,$(OSTRACON_BUILD_OPTIONS)))
    41    BUILD_TAGS += badgerdb
    42  endif
    43  
    44  # handle rocksdb
    45  ifeq (rocksdb,$(findstring rocksdb,$(OSTRACON_BUILD_OPTIONS)))
    46    CGO_ENABLED=1
    47    BUILD_TAGS += rocksdb
    48  endif
    49  
    50  # handle boltdb
    51  ifeq (boltdb,$(findstring boltdb,$(OSTRACON_BUILD_OPTIONS)))
    52    BUILD_TAGS += boltdb
    53  endif
    54  
    55  # allow users to pass additional flags via the conventional LDFLAGS variable
    56  LD_FLAGS += $(LDFLAGS)
    57  
    58  all: build test install
    59  .PHONY: all
    60  
    61  include tests.mk
    62  
    63  ###############################################################################
    64  ###                                Build Ostracon                           ###
    65  ###############################################################################
    66  
    67  build: $(LIBSODIUM_TARGET)
    68  	CGO_ENABLED=1 go build $(BUILD_FLAGS) -tags "$(BUILD_TAGS)" -o $(OUTPUT) ./cmd/ostracon/
    69  .PHONY: build
    70  
    71  install: $(LIBSODIUM_TARGET)
    72  	CGO_ENABLED=1 go install $(BUILD_FLAGS) -tags "$(BUILD_TAGS)" ./cmd/ostracon
    73  .PHONY: install
    74  
    75  ###############################################################################
    76  ###                                 Mockery                                 ###
    77  ###############################################################################
    78  
    79  ###
    80  # https://github.com/vektra/mockery
    81  # Should install
    82  ### brew
    83  # brew install mockery
    84  # brew upgrade mockery
    85  ### go get
    86  # go get github.com/vektra/mockery/v2/.../
    87  
    88  mock-gen:
    89  	go generate ./...
    90  .PHONY: mock
    91  
    92  ###############################################################################
    93  ###                                Protobuf                                 ###
    94  ###############################################################################
    95  
    96  containerProtoVer=v0.2
    97  containerProtoImage=tendermintdev/sdk-proto-gen:$(containerProtoVer)
    98  
    99  ###
   100  # https://github.com/protocolbuffers/protobuf
   101  # https://developers.google.com/protocol-buffers/docs/gotutorial
   102  # Should install
   103  ### go install
   104  # go install google.golang.org/protobuf/cmd/protoc-gen-go
   105  ### Docker for Protocol Buffer
   106  # https://hub.docker.com/r/bufbuild/buf
   107  
   108  proto-all: proto-gen proto-lint proto-check-breaking
   109  .PHONY: proto-all
   110  
   111  proto-gen:
   112  	@docker pull -q tendermintdev/docker-build-proto
   113  	@echo "Generating Protobuf files"
   114  	@docker run --rm -v $(shell pwd):/workspace --workdir /workspace $(containerProtoImage) sh ./scripts/protocgen.sh
   115  .PHONY: proto-gen
   116  
   117  proto-lint:
   118  	@$(DOCKER_BUF) lint --error-format=json
   119  .PHONY: proto-lint
   120  
   121  proto-format:
   122  	@echo "Formatting Protobuf files"
   123  	docker run --rm -v $(shell pwd):/workspace --workdir /workspace tendermintdev/docker-build-proto find ./ -not -path "./third_party/*" -name *.proto -exec clang-format -i {} \;
   124  .PHONY: proto-format
   125  
   126  proto-check-breaking:
   127  	@$(DOCKER_BUF) breaking --against .git#branch=main
   128  .PHONY: proto-check-breaking
   129  
   130  proto-check-breaking-ci:
   131  	@$(DOCKER_BUF) breaking --against $(HTTPS_GIT)#branch=main
   132  .PHONY: proto-check-breaking-ci
   133  
   134  ###############################################################################
   135  ###                              Build ABCI                                 ###
   136  ###############################################################################
   137  
   138  build_abci:
   139  	@go build -mod=readonly -i ./abci/cmd/...
   140  .PHONY: build_abci
   141  
   142  install_abci:
   143  	@go install -mod=readonly ./abci/cmd/...
   144  .PHONY: install_abci
   145  
   146  ###############################################################################
   147  ###                              Distribution                               ###
   148  ###############################################################################
   149  
   150  ########################################
   151  ### libsodium
   152  
   153  VRF_ROOT = $(SRCPATH)/crypto/vrf/internal/vrf
   154  LIBSODIUM_ROOT = $(VRF_ROOT)/libsodium
   155  LIBSODIUM_OS = $(VRF_ROOT)/sodium/$(TARGET_OS)_$(TARGET_ARCH)
   156  ifneq ($(TARGET_HOST), "")
   157  LIBSODIUM_HOST = "--host=$(TARGET_HOST)"
   158  endif
   159  
   160  libsodium:
   161  	@if [ ! -f $(LIBSODIUM_OS)/lib/libsodium.a ]; then \
   162  		rm -rf $(LIBSODIUM_ROOT) && \
   163  		mkdir $(LIBSODIUM_ROOT) && \
   164  		git submodule update --init --recursive && \
   165  		cd $(LIBSODIUM_ROOT) && \
   166  		./autogen.sh && \
   167  		./configure --disable-shared --prefix="$(LIBSODIUM_OS)" $(LIBSODIUM_HOST) && \
   168  		$(MAKE) && \
   169  		$(MAKE) install; \
   170  	fi
   171  .PHONY: libsodium
   172  
   173  ########################################
   174  ### Distribution
   175  
   176  # dist builds binaries for all platforms and packages them for distribution
   177  # TODO add abci to these scripts
   178  dist:
   179  	@BUILD_TAGS=$(BUILD_TAGS) sh -c "'$(CURDIR)/scripts/dist.sh'"
   180  .PHONY: dist
   181  
   182  go-mod-cache: go.sum
   183  	@echo "--> Download go modules to local cache"
   184  	@go mod download
   185  .PHONY: go-mod-cache
   186  
   187  go.sum: go.mod
   188  	@echo "--> Ensure dependencies have not been modified"
   189  	@go mod verify
   190  	@go mod tidy
   191  
   192  draw_deps:
   193  	@# requires brew install graphviz or apt-get install graphviz
   194  	go get github.com/RobotsAndPencils/goviz
   195  	@goviz -i github.com/line/ostracon/cmd/ostracon -d 3 | dot -Tpng -o dependency-graph.png
   196  .PHONY: draw_deps
   197  
   198  get_deps_bin_size:
   199  	@# Copy of build recipe with additional flags to perform binary size analysis
   200  	$(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/ostracon/ 2>&1))
   201  	@find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
   202  	@echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
   203  .PHONY: get_deps_bin_size
   204  
   205  ###############################################################################
   206  ###                                  Libs                                   ###
   207  ###############################################################################
   208  
   209  # generates certificates for TLS testing in remotedb and RPC server
   210  gen_certs: clean_certs
   211  	certstrap init --common-name "blockchain.line.me" --passphrase ""
   212  	certstrap request-cert --common-name "server" -ip "127.0.0.1" --passphrase ""
   213  	certstrap sign "server" --CA "blockchain.line.me" --passphrase ""
   214  	mv out/server.crt rpc/jsonrpc/server/test.crt
   215  	mv out/server.key rpc/jsonrpc/server/test.key
   216  	rm -rf out
   217  .PHONY: gen_certs
   218  
   219  # deletes generated certificates
   220  clean_certs:
   221  	rm -f rpc/jsonrpc/server/test.crt
   222  	rm -f rpc/jsonrpc/server/test.key
   223  .PHONY: clean_certs
   224  
   225  ###############################################################################
   226  ###                  Formatting, linting, and vetting                       ###
   227  ###############################################################################
   228  
   229  format:
   230  	find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofmt -w -s
   231  	find . -name '*.go' -type f -not -path "*.git*"  -not -name '*.pb.go' -not -name '*pb_test.go' | xargs goimports -w -local github.com/line/ostracon
   232  .PHONY: format
   233  
   234  lint:
   235  	@echo "--> Running linter"
   236  	@golangci-lint run
   237  .PHONY: lint
   238  
   239  DESTINATION = ./index.html.md
   240  
   241  ###############################################################################
   242  ###                           Documentation                                 ###
   243  ###############################################################################
   244  
   245  BRANCH := $(shell git branch --show-current)
   246  BRANCH_URI := $(shell git branch --show-current | sed 's/[\#]/%23/g')
   247  build-docs:
   248  	@cd docs && \
   249  	npm install && \
   250  	VUEPRESS_BASE="/$(BRANCH_URI)/" npm run build && \
   251  	mkdir -p ~/output/$(BRANCH) && \
   252  	cp -r .vuepress/dist/* ~/output/$(BRANCH)/ && \
   253  	for f in `find . -name '*.png' | grep -v '/node_modules/'`; do if [ ! -e `dirname $$f` ]; then mkdir `dirname $$f`; fi; cp $$f ~/output/$(BRANCH)/`dirname $$f`; done && \
   254  	echo '<html><head><meta http-equiv="refresh" content="0;/$(BRANCH_URI)/index.html"/></head></html>' > ~/output/index.html
   255  .PHONY: build-docs
   256  
   257  sync-docs:
   258  	cd ~/output && \
   259  	echo "role_arn = ${DEPLOYMENT_ROLE_ARN}" >> /root/.aws/config ; \
   260  	echo "CI job = ${CIRCLE_BUILD_URL}" >> version.html ; \
   261  	aws s3 sync . s3://${WEBSITE_BUCKET} --profile terraform --delete ; \
   262  	aws cloudfront create-invalidation --distribution-id ${CF_DISTRIBUTION_ID} --profile terraform --path "/*" ;
   263  .PHONY: sync-docs
   264  
   265  ###############################################################################
   266  ###                            Docker image                                 ###
   267  ###############################################################################
   268  
   269  # Build linux binary on other platforms
   270  # Should run from within a linux if CGO_ENABLED=1
   271  build-linux:
   272  	GOOS=linux GOARCH=$(TARGET_ARCH) $(MAKE) build
   273  .PHONY: build-linux
   274  
   275  build-linux-docker:
   276  	docker build --label=ostracon --tag="ostracon/ostracon" -f ./DOCKER/Dockerfile .
   277  .PHONY: build-linux-docker
   278  
   279  standalone-linux-docker:
   280  	docker run -it --rm -v "/tmp:/ostracon" -p 26656:26656 -p 26657:26657 -p 26660:26660  ostracon/ostracon
   281  .PHONY: standalone-linux-docker
   282  
   283  # XXX Warning: Not test yet
   284  # Runs `make build OSTRACON_BUILD_OPTIONS=cleveldb` from within an Amazon
   285  # Linux (v2)-based Docker build container in order to build an Amazon
   286  # Linux-compatible binary. Produces a compatible binary at ./build/ostracon
   287  build_c-amazonlinux:
   288  	$(MAKE) -C ./DOCKER build_amazonlinux_buildimage
   289  	docker run --rm -it -v `pwd`:/ostracon ostracon/ostracon:build_c-amazonlinux
   290  .PHONY: build_c-amazonlinux
   291  
   292  ###############################################################################
   293  ###                       Local testnet using docker                        ###
   294  ###############################################################################
   295  
   296  DOCKER_HOME = /go/src/github.com/line/ostracon
   297  DOCKER_CMD = docker run --rm \
   298                          -v `pwd`:$(DOCKER_HOME) \
   299                          -w $(DOCKER_HOME)
   300  DOCKER_IMG = golang:1.18-alpine
   301  BUILD_CMD = apk add --update --no-cache git make gcc libc-dev build-base curl jq bash file gmp-dev clang libtool autoconf automake \
   302  	&& cd $(DOCKER_HOME) \
   303  	&& LIBSODIUM=$(LIBSODIUM) make build-linux
   304  
   305  # Login docker-container for confirmation building linux binary
   306  build-shell:
   307  	$(DOCKER_CMD) -it --entrypoint '' ${DOCKER_IMG} /bin/sh
   308  .PHONY: build-shell
   309  
   310  build-localnode:
   311  	$(DOCKER_CMD) ${DOCKER_IMG} /bin/sh -c "$(BUILD_CMD)"
   312  .PHONY: build-localnode
   313  
   314  build-localnode-docker: build-localnode
   315  	@cd networks/local && make
   316  .PHONY: build-localnode-docker
   317  
   318  # Run a 4-node testnet locally
   319  localnet-start: localnet-stop build-localnode-docker
   320  	@if ! [ -f build/node0/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/ostracon:Z ostracon/localnode testnet --config /etc/ostracon/config-template.toml --o . --starting-ip-address 192.167.10.2; fi
   321  	docker-compose up
   322  .PHONY: localnet-start
   323  
   324  # Stop testnet
   325  localnet-stop:
   326  	docker-compose down
   327  .PHONY: localnet-stop