-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
163 lines (126 loc) · 3.75 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# (c) Copyright 2022 Christian Saide
# SPDX-License-Identifier: GPL-3.0-or-later
###
# OS Determination
###
detected_OS := $(shell uname 2>/dev/null || echo Unknown)
ifeq ($(detected_OS),Linux)
BUILD_OS := linux
endif
ifeq ($(detected_OS),FreeBSD)
BUILD_OS := freebsd
endif
ifeq ($(detected_OS),NetBSD)
BUILD_OS := netbsd
endif
ifeq ($(detected_OS),OpenBSD)
BUILD_OS := openbsd
endif
###
# Build args and variables.
###
.SECONDEXPANSION:
BUILD := debug
BUILD_ARCH ?= amd64
###
# Target and build definitions for varios OS/arch combinations
###
# Define the resulting targets for building cross-platform
target_linux-amd64 := x86_64-unknown-linux-gnu
target_linux-arm64 := aarch64-unknown-linux-gnu
target_linux := linux-amd64 linux-arm64
# Define an override so that we can turn on/off release builds.
build_debug =
build_release = --release
strip_linux-amd64 := strip
strip_linux-arm64 := aarch64-linux-gnu-strip
###
# Default target definition
###
.PHONY: default devel
default: compile
devel: check compile
###
# Binary compilation steps.
###
.PHONY: docs compile compile.linux
docs:
@bash ./dist/bin/print.sh "Generating Docs"
@cargo doc
# Ensure we compile each of the targets properly using the correct mode.
compile-bin.%:
@bash ./dist/bin/print.sh "Building target: '$*' mode: '$(BUILD)'"
@mkdir -p ./output/$(BUILD)
@RUSTFLAGS="-Ctarget-feature=+crt-static" cargo build $(build_$(BUILD)) --target $(target_$*)
@if [ "$(BUILD)" = "release" ]; then bash ./dist/bin/strip-compress.sh "$(BUILD)" "$(target_$*)" "$(strip_$*)"; fi
@bash dist/bin/package.sh "$(BUILD)" "$(target_$*)" "$*"
# Build all targets for the biven OS.
compile-exp.%: $$(foreach target,$$(target_$$*),compile-bin.$$(target))
@bash ./dist/bin/print.sh "Finished building targets for OS: '$*' mode: '$(BUILD)'"
# By default build targets for the local OS, but in theory it should be possible to at least
# compile cross-platform.
compile.linux: compile-exp.linux
compile: compile-bin.$(BUILD_OS)-$(BUILD_ARCH)
###
# Docker commands
###
.PHONY: docker
HASH ?= $(shell git rev-parse HEAD)
docker:
@bash ./dist/bin/print.sh "Building image"
@docker buildx build \
--platform linux/amd64 \
--tag ghcr.io/csaide/prism:$(HASH) \
--build-arg BUILD=release \
--file ./dist/docker/prism/Dockerfile \
--load \
.
promote:
@bash ./dist/bin/print.sh "Promoting image"
@docker buildx build \
--platform linux/arm64,linux/amd64 \
--tag ghcr.io/csaide/prism:$(TAG) \
--build-arg HASH=$(HASH) \
--file ./dist/docker/prism/Dockerfile.promote \
--push \
.
compose-up:
@bash ./dist/bin/print.sh "Staring cluster"
@docker-compose -p prism -f ./dist/docker/docker-compose.yaml up
compose-down:
@bash ./dist/bin/print.sh "Staring cluster"
@docker-compose -p prism -f ./dist/docker/docker-compose.yaml down -v
###
# Source code validation, formatting, linting.
###
.PHONY: fmt lint units bench coverage coverage-ci coverage-html license check
fmt:
@bash ./dist/bin/print.sh "Formatting Code"
@cargo fmt --all -- --emit=files
lint:
@bash ./dist/bin/print.sh "Linting"
@cargo fmt --all -- --check
@cargo clippy --all-features --no-deps
units:
@bash ./dist/bin/print.sh "Running tests"
@cargo test
coverage:
@bash ./dist/bin/print.sh "Running tests with coverage"
@cargo +nightly llvm-cov
coverage-ci:
@bash ./dist/bin/print.sh "Running tests with coverage"
@cargo +nightly llvm-cov --hide-instantiations --lcov --output-path coverage.lcov
coverage-html:
@bash ./dist/bin/print.sh "Running tests with coverage"
@cargo +nightly llvm-cov --hide-instantiations --html
license:
@bash ./dist/bin/print.sh "Verifying licensing"
@bash ./dist/bin/lic-check.sh
check: fmt lint units license
###
# Cleanup
###
.PHONY: clean
clean:
@bash ./dist/bin/print.sh "Cleaning"
@rm -rf target/ output/