forked from dragonflyoss/nydus
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
211 lines (159 loc) · 7.52 KB
/
Makefile
File metadata and controls
211 lines (159 loc) · 7.52 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
all: release
all-build: build contrib-build
all-release: release contrib-release
all-static-release: static-release docker-static contrib-release
all-install: install contrib-install
all-clean: clean contrib-clean
TEST_WORKDIR_PREFIX ?= "/tmp"
INSTALL_DIR_PREFIX ?= "/usr/local/bin"
DOCKER ?= "true"
CARGO ?= $(shell which cargo)
RUSTUP ?= $(shell which rustup)
CARGO_BUILD_GEARS = -v ~/.ssh/id_rsa:/root/.ssh/id_rsa -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry
SUDO = $(shell which sudo)
CARGO_COMMON ?=
EXCLUDE_PACKAGES =
UNAME_M := $(shell uname -m)
UNAME_S := $(shell uname -s)
STATIC_TARGET = $(UNAME_M)-unknown-linux-musl
ifeq ($(UNAME_S),Linux)
CARGO_COMMON += --features=virtiofs
ifeq ($(UNAME_M),ppc64le)
STATIC_TARGET = powerpc64le-unknown-linux-gnu
endif
ifeq ($(UNAME_M),riscv64)
STATIC_TARGET = riscv64gc-unknown-linux-gnu
endif
endif
ifeq ($(UNAME_S),Darwin)
EXCLUDE_PACKAGES += --exclude nydus-blobfs
ifeq ($(UNAME_M),amd64)
STATIC_TARGET = x86_64-apple-darwin
endif
ifeq ($(UNAME_M),arm64)
STATIC_TARGET = aarch64-apple-darwin
endif
endif
RUST_TARGET_STATIC ?= $(STATIC_TARGET)
NYDUSIFY_PATH = contrib/nydusify
NYDUS-OVERLAYFS_PATH = contrib/nydus-overlayfs
LLVM_PROFILE_FILE := $(PWD)/coverage/nydus-%p-%m.profraw
DEBUG_BINARY_DIR := $(PWD)/target/debug/
GRCOV_ARGS := --binary-path ${DEBUG_BINARY_DIR} -s . \
--branch --ignore-not-existing \
--ignore '*/.rustup/*' --ignore '*/rustup/*' \
--ignore '*/.cargo/*' --ignore '*/cargo/*'
CARGO_COV_FLAGS :=
# define ENABLE_DEBUG to disable release optimization and trace code coverage
ifdef ENABLE_DEBUG
$(eval CARGO_COV_FLAGS += NYDUS_NYDUSD_latest=${DEBUG_BINARY_DIR}/nydusd )
$(eval CARGO_COV_FLAGS += NYDUS_BUILDER_latest=${DEBUG_BINARY_DIR}/nydus-image )
$(eval CARGO_COV_FLAGS += RUSTFLAGS='-C instrument-coverage')
$(eval CARGO_COV_FLAGS += TEST_WORKDIR_PREFIX=$(TEST_WORKDIR_PREFIX) )
$(eval CARGO_COV_FLAGS += LLVM_PROFILE_FILE=$(LLVM_PROFILE_FILE) )
else
$(eval CARGO_BUILD_FLAGS += --release)
endif
current_dir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
env_go_path := $(shell go env GOPATH 2> /dev/null)
go_path := $(if $(env_go_path),$(env_go_path),"$(HOME)/go")
go_work_version := $(shell grep '^go ' go.work | awk '{print $$2}')
# Functions
# Func: build golang target in docker
# Args:
# $(1): The path where go build a golang project
# $(2): How to build the golang project
define build_golang
echo "Building target $@ by invoking: $(2)"
if [ $(DOCKER) = "true" ]; then \
docker run --rm -v ${go_path}:/go -v ${current_dir}:/nydus-rs --workdir /nydus-rs/$(1) golang:${go_work_version} \
sh -c "git config --global --add safe.directory /nydus-rs && $(2)" ;\
else \
$(2) -C $(1); \
fi
endef
.PHONY: .format .musl_target .clean_libz_sys \
all all-build all-release all-static-release build release static-release
.format:
${CARGO} fmt -- --check
.musl_target:
$(eval CARGO_BUILD_FLAGS += --target ${RUST_TARGET_STATIC})
# Workaround to clean up stale cache for libz-sys
.clean_libz_sys:
@${CARGO} clean --target ${RUST_TARGET_STATIC} -p libz-sys
@${CARGO} clean --target ${RUST_TARGET_STATIC} --release -p libz-sys
prepare-codecov:
${CARGO} install grcov --locked
${RUSTUP} component add llvm-tools-preview
# Targets that are exposed to developers and users.
build: .format
$(CARGO_COV_FLAGS) ${CARGO} build $(CARGO_COMMON) $(CARGO_BUILD_FLAGS)
# Cargo will skip checking if it is already checked
${CARGO} clippy --workspace $(EXCLUDE_PACKAGES) $(CARGO_COMMON) $(CARGO_BUILD_FLAGS) --bins --tests -- -Dwarnings --allow clippy::unnecessary_cast --allow clippy::needless_borrow --allow clippy::result_large_err --allow clippy::manual_is_multiple_of --allow clippy::io_other_error
release: .format build
static-release: .clean_libz_sys .musl_target .format build
clean:
[ -d coverage ] && rm -rf coverage || true
${CARGO} clean
install: release
@sudo mkdir -m 755 -p $(INSTALL_DIR_PREFIX)
@sudo install -m 755 target/release/nydusd $(INSTALL_DIR_PREFIX)/nydusd
@sudo install -m 755 target/release/nydus-image $(INSTALL_DIR_PREFIX)/nydus-image
@sudo install -m 755 target/release/nydusctl $(INSTALL_DIR_PREFIX)/nydusctl
# unit test
ut:
$(CARGO_COV_FLAGS) TEST_WORKDIR_PREFIX=$(TEST_WORKDIR_PREFIX) RUST_BACKTRACE=1 ${CARGO} test --no-fail-fast --workspace $(EXCLUDE_PACKAGES) $(CARGO_COMMON) $(CARGO_BUILD_FLAGS) -- --skip integration --nocapture --test-threads=8
# you need install cargo nextest first from: https://nexte.st/book/pre-built-binaries.html
ut-nextest:
$(CARGO_COV_FLAGS) TEST_WORKDIR_PREFIX=$(TEST_WORKDIR_PREFIX) RUST_BACKTRACE=1 ${RUSTUP} run stable cargo nextest run --no-fail-fast --filter-expr 'test(test) - test(integration)' --workspace $(EXCLUDE_PACKAGES) $(CARGO_COMMON) $(CARGO_BUILD_FLAGS)
# install miri first from https://github.com/rust-lang/miri/
miri-ut-nextest:
$(CARGO_COV_FLAGS) MIRIFLAGS=-Zmiri-disable-isolation TEST_WORKDIR_PREFIX=$(TEST_WORKDIR_PREFIX) RUST_BACKTRACE=1 ${RUSTUP} run nightly cargo miri nextest run --no-fail-fast --filter-expr 'test(test) - test(integration) - test(deduplicate::tests) - test(inode_bitmap::tests::test_inode_bitmap)' --workspace $(EXCLUDE_PACKAGES) $(CARGO_COMMON) $(CARGO_BUILD_FLAGS)
smoke-only:
CARGO_COV_FLAGS="$(CARGO_COV_FLAGS)" make -C smoke test
smoke-performance:
CARGO_COV_FLAGS="$(CARGO_COV_FLAGS)" make -C smoke test-performance
smoke-benchmark:
CARGO_COV_FLAGS="$(CARGO_COV_FLAGS)" make -C smoke test-benchmark
smoke-takeover:
CARGO_COV_FLAGS=$(CARGO_COV_FLAGS) make -C smoke test-takeover
smoke: release smoke-only
generate-codecov-markdown: prepare-codecov
grcov $(dir ${LLVM_PROFILE_FILE})/*.profraw -t markdown $(GRCOV_ARGS) --output-path coverage/coverage.md
generate-codecov: prepare-codecov
grcov $(dir ${LLVM_PROFILE_FILE})/*.profraw -t lcov $(GRCOV_ARGS) --output-path coverage/coverage.info
# write unit teset coverage to codecov.json, used for Github CI
coverage-codecov:
TEST_WORKDIR_PREFIX=$(TEST_WORKDIR_PREFIX) ${RUSTUP} run stable cargo llvm-cov --codecov --output-path codecov.json --workspace $(EXCLUDE_PACKAGES) $(CARGO_COMMON) $(CARGO_BUILD_FLAGS) -- --skip integration --nocapture --test-threads=8
contrib-build: nydusify nydus-overlayfs
contrib-release: nydusify-release nydus-overlayfs-release
contrib-test: nydusify-test nydus-overlayfs-test
contrib-lint: nydusify-lint nydus-overlayfs-lint
contrib-clean: nydusify-clean nydus-overlayfs-clean
contrib-install:
@sudo mkdir -m 755 -p $(INSTALL_DIR_PREFIX)
@sudo install -m 755 contrib/nydus-overlayfs/bin/nydus-overlayfs $(INSTALL_DIR_PREFIX)/nydus-overlayfs
@sudo install -m 755 contrib/nydusify/cmd/nydusify $(INSTALL_DIR_PREFIX)/nydusify
nydusify:
$(call build_golang,${NYDUSIFY_PATH},make)
nydusify-release:
$(call build_golang,${NYDUSIFY_PATH},make release)
nydusify-test:
$(call build_golang,${NYDUSIFY_PATH},make test)
nydusify-clean:
$(call build_golang,${NYDUSIFY_PATH},make clean)
nydusify-lint:
$(call build_golang,${NYDUSIFY_PATH},make lint)
nydus-overlayfs:
$(call build_golang,${NYDUS-OVERLAYFS_PATH},make)
nydus-overlayfs-release:
$(call build_golang,${NYDUS-OVERLAYFS_PATH},make release)
nydus-overlayfs-test:
$(call build_golang,${NYDUS-OVERLAYFS_PATH},make test)
nydus-overlayfs-clean:
$(call build_golang,${NYDUS-OVERLAYFS_PATH},make clean)
nydus-overlayfs-lint:
$(call build_golang,${NYDUS-OVERLAYFS_PATH},make lint)
docker-static:
docker build -t nydus-rs-static --build-arg RUST_TARGET=${RUST_TARGET_STATIC} misc/musl-static
docker run --rm ${CARGO_BUILD_GEARS} -e RUST_TARGET=${RUST_TARGET_STATIC} --workdir /nydus-rs -v ${current_dir}:/nydus-rs nydus-rs-static