Help users build your application by writing a ./Makefile
in the root directory that includes common commands:
NOTE: The below Makefile contains some of same commands as the Cosmos SDK and Tendermint Makefiles.
all: lint install
install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/nsd
go install -mod=readonly $(BUILD_FLAGS) ./cmd/nscli
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify
lint:
golangci-lint run
@find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
go mod verify
This requires a few small changes:
- Create a file
Makefile.ledger
with the following content:
LEDGER_ENABLED ?= true
build_tags =
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
endif
- Add
include Makefile.ledger
at the beginning of the Makefile:
PACKAGES=$(shell go list ./... | grep -v '/simulation')
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=NameService \
-X github.com/cosmos/cosmos-sdk/version.ServerName=nsd \
-X github.com/cosmos/cosmos-sdk/version.ClientName=nscli \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags)"
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
include Makefile.ledger
all: lint install
install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/nsd
go install -mod=readonly $(BUILD_FLAGS) ./cmd/nscli
go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify
lint:
golangci-lint run
@find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
go mod verify
test:
@go test -mod=readonly $(PACKAGES)
Golang has a few dependency management tools. In this tutorial you will be using Go Modules
. Go Modules
uses a go.mod
file in the root of the repository to define what dependencies the application needs. Cosmos SDK apps currently depend on specific versions of some libraries. The below manifest contains all the necessary versions. To get started replace the contents of the ./go.mod
file with the constraints
and overrides
below:
NOTE: If you are following along in your own repo you will need to change the module path to reflect that (
github.com/{ .Username }/{ .Project.Repo }
).
- You will have to run go get ./... to get all the modules the application is using. This command will get the latest releases of the dependancies
- If you would like to use a specific version of a dependency then you have to run
go get github.com/<github_org>/<repo_name>@<version>
module github.com/cosmos/sdk-application-tutorial
go 1.13
require (
<List of Modules, this will vary on version you are using>
)
# Install the app into your $GOBIN
make install
# Now you should be able to run the following commands:
nsd help
nscli help