CACHED_BASIC_EXAMPLES = async_std \
basic \
basic_proc_macro \
kitchen_sink \
kitchen_sink_proc_macro \
tokio
CACHED_REDIS_EXAMPLES = redis \
redis-async
CACHED_CARGO_EXAMPLES = wasm
CARGO_COMMAND = cargo
README_CC = $(CARGO_COMMAND) readme
README_CCFLAGS = --no-indent-headings
FMT_CC = $(CARGO_COMMAND) fmt
FMT_CCFLAGS =
DOCKER_COMMAND = docker
DOCKER_REDIS_CONTAINER_NAME = cached-tests
DOCKER_REDIS_CONTAINER_LOCAL_PORT = 6399
export CACHED_REDIS_CONNECTION_STRING = redis://127.0.0.1:$(DOCKER_REDIS_CONTAINER_LOCAL_PORT)
export RUST_BACKTRACE = 1
ci: check tests examples
examples: examples/basic examples/cargo examples/redis
examples/basic: $(addprefix examples/basic/, $(CACHED_BASIC_EXAMPLES))
examples/cargo: $(addprefix examples/cargo/, $(CACHED_CARGO_EXAMPLES))
examples/redis: $(addprefix examples/redis/, $(CACHED_REDIS_EXAMPLES))
examples/basic/%:
@echo [$@]: Running example $*...
$(CARGO_COMMAND) run --example $* --all-features
examples/cargo/wasm:
@echo [$@]: Building example $*...
cd examples/wasm ; $(CARGO_COMMAND) build --target=wasm32-unknown-unknown
examples/redis/%: docker/redis
@echo [$@]: Running example $*...
$(CARGO_COMMAND) run --example $* --all-features
tests: docker/redis
@echo [$@]: Running tests...
$(CARGO_COMMAND) test --all-features -- --nocapture
docker/redis: docker/status
@echo [$@]: Starting Redis container...
-$(DOCKER_COMMAND) run --rm --name $(DOCKER_REDIS_CONTAINER_NAME) \
-p $(DOCKER_REDIS_CONTAINER_LOCAL_PORT):6379 -d redis
docker/status:
@echo [$@]: Checking the Docker engine
@docker info > /dev/null || (>&2 echo 'Is the Docker engine running?' && exit 42)
docs: docs/readme
docs/readme: README.md
README.md: src/lib.rs
@echo [$@]: Updating $@...
$(README_CC) $(README_CCFLAGS) > $@
fmt:
@echo [$@]: Formatting code...
$(FMT_CC) $(FMT_CCFLAGS)
check: check/fmt check/readme check/clippy
check/fmt: FMT_CCFLAGS += --check
check/fmt:
@echo [$@]: Checking code format...
$(FMT_CC) $(FMT_CCFLAGS)
check/readme:
@echo [$@]: Checking README.md...
$(README_CC) $(README_CCFLAGS) | cmp README.md
check/clippy:
@echo [$@]: Running clippy...
$(CARGO_COMMAND) clippy --all-features --all-targets --examples --tests
clean: clean/docker clean/cargo
clean/cargo:
@echo [$@]: Removing cargo artifacts...
$(CARGO_COMMAND) clean
clean/docker: clean/docker/$(DOCKER_REDIS_CONTAINER_NAME)
clean/docker/%:
@echo [$@]: Removing container called $*...
$(DOCKER_COMMAND) rm -f $*
.PHONY: ci \
$(filter examples%, $(MAKECMDGOALS)) \
$(filter tests%, $(MAKECMDGOALS)) \
$(filter docker%, $(MAKECMDGOALS)) \
$(filter docs%, $(MAKECMDGOALS)) \
$(filter fmt%, $(MAKECMDGOALS)) \
$(filter check%, $(MAKECMDGOALS)) \
$(filter clean%, $(MAKECMDGOALS))