-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathMakefile
More file actions
190 lines (150 loc) · 5.88 KB
/
Makefile
File metadata and controls
190 lines (150 loc) · 5.88 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
# Copyright The containerd Authors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
GO ?= go
DOCKER ?= docker
BUILDX ?= $(DOCKER) buildx
ROOTDIR=$(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
WHALE = "🇩"
ONI = "👹"
ARCH = $(shell uname -m)
OS = $(shell uname -s)
LDFLAGS_x86_64_Linux = -lkrun
LDFLAGS_aarch64_Linux = -lkrun
LDFLAGS_arm64_Darwin = -L/opt/homebrew/lib -lkrun
CFLAGS = -O2 -g -I../include
LDFLAGS += -s -w
DEBUG_GO_GCFLAGS :=
DEBUG_TAGS :=
ifdef BUILDTAGS
GO_BUILDTAGS = ${BUILDTAGS}
endif
GO_BUILDTAGS ?= no_grpc
GO_BUILDTAGS += ${DEBUG_TAGS}
GO_STATIC_BUILDTAGS ?=
GO_STATIC_BUILDTAGS += ${DEBUG_TAGS}
GO_STATIC_BUILDTAGS += osusergo netgo static_build no_grpc
GO_TAGS=$(if $(GO_BUILDTAGS),-tags "$(strip $(GO_BUILDTAGS))",)
GO_STATIC_TAGS=$(if $(GO_STATIC_BUILDTAGS),-tags "$(strip $(GO_STATIC_BUILDTAGS))",)
GO_BUILD_FLAGS ?=
GO_LDFLAGS ?= -ldflags '$(LDFLAGS) $(EXTRA_LDFLAGS)'
GO_STATIC_LDFLAGS := -ldflags '-extldflags "-static" $(LDFLAGS) $(EXTRA_LDFLAGS)'
MODULE_NAME=$(shell go list -m)
API_PACKAGES=$(shell ($(GO) list ${GO_TAGS} ./... | grep /api/ ))
.PHONY: clean all build validate lint generate protos check-protos check-api-descriptors proto-fmt shell
all: build
build:
@echo "$(WHALE) $@"
HOST_OS=$(shell uname -s | tr '[:upper:]' '[:lower:]') KERNEL_ARCH=$(ARCH) $(BUILDX) bake
_output/containerd-shim-nerdbox-v1: cmd/containerd-shim-nerdbox-v1 FORCE
@echo "$(WHALE) $@"
$(GO) build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@ ${GO_LDFLAGS} ${GO_TAGS} ./$<
ifeq ($(OS),Darwin)
codesign --entitlements cmd/containerd-shim-nerdbox-v1/containerd-shim-nerdbox-v1.entitlements --force -s - $@
endif
_output/containerd-shim-nerdbox-v1.exe: cmd/containerd-shim-nerdbox-v1 FORCE
@echo "$(WHALE) $@"
GOOS=windows GOARCH=amd64 $(GO) build ${GO_BUILD_FLAGS} -o $@ ${GO_LDFLAGS} ${GO_TAGS} ./$<
_output/vminitd: cmd/vminitd FORCE
@echo "$(WHALE) $@"
$(GO) build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@ ${GO_STATIC_LDFLAGS} ${GO_STATIC_TAGS} ./$<
_output/nerdbox-initrd: cmd/vminitd FORCE
@echo "$(WHALE) $@"
$(BUILDX) bake initrd
_output/integration.test: integration FORCE
@echo "$(WHALE) $@"
$(GO) test -c -o $@ ${GO_LDFLAGS} ${GO_TAGS} ./integration
ifeq ($(OS),Darwin)
codesign --entitlements cmd/containerd-shim-nerdbox-v1/containerd-shim-nerdbox-v1.entitlements --force -s - $@
endif
_output/test_vminitd: cmd/test_vminitd FORCE
@echo "$(WHALE) $@"
$(GO) build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@ ${GO_LDFLAGS} ${GO_TAGS} ./$<
ifeq ($(OS),Darwin)
codesign --entitlements cmd/test_vminitd/test_vminitd.entitlements --force -s - $@
endif
_output/run_vminitd: cmd/run_vminitd/main.c
gcc -o $@ $< $(CFLAGS) $(LDFLAGS_$(ARCH)_$(OS))
ifeq ($(OS),Darwin)
codesign --entitlements src/run_vminitd.entitlements --force -s - $@
endif
_output/libkrun.so: FORCE
@echo "$(WHALE) $@"
$(BUILDX) bake libkrun
generate: protos
@echo "$(WHALE) $@"
@PATH="${ROOTDIR}/bin:${PATH}" $(GO) generate -x ${PACKAGES}
protos:
@echo "$(WHALE) $@"
@(cd ${ROOTDIR}/api && PATH="${ROOTDIR}/bin:${PATH}" buf generate)
@(cd ${ROOTDIR}/api && buf build --exclude-imports -o next.txtpb)
go-fix-acronym -w -a '^Os' $(shell find api/ -name '*.pb.go')
go-fix-acronym -w -a '(Id|Io|Uuid|Os)$$' $(shell find api/ -name '*.pb.go')
check-protos: protos ## check if protobufs needs to be generated again
@echo "$(WHALE) $@"
@test -z "$$(git status --short | grep ".pb.go" | tee /dev/stderr)" || \
((git diff | cat) && \
(echo "$(ONI) please run 'make protos' when making changes to proto files" && false))
check-api-descriptors: protos ## check that protobuf changes aren't present.
@echo "$(WHALE) $@"
@test -z "$$(git status --short | grep ".txtpb" | tee /dev/stderr)" || \
((git diff $$(find . -name '*.txtpb') | cat) && \
(echo "$(ONI) please run 'make protos' when making changes to proto files and check-in the generated descriptor file changes" && false))
proto-fmt: ## check format of proto files
@echo "$(WHALE) $@"
@test -z "$$(find . -name '*.proto' -type f -exec grep -Hn -e "^ " {} \; | tee /dev/stderr)" || \
(echo "$(ONI) please indent proto files with tabs only" && false)
menuconfig:
ifeq ($(KERNEL_VERSION),)
$(error KERNEL_VERSION is not set)
endif
ifeq ($(KERNEL_ARCH),)
$(error KERNEL_ARCH is not set)
endif
@echo "$(WHALE) $@"
@$(BUILDX) bake menuconfig
docker run --rm -it \
-v ./kernel:/config \
-w /usr/src/linux \
-e KCONFIG_CONFIG=/config/config-$(KERNEL_VERSION)-$(KERNEL_ARCH) \
nerdbox-menuconfig \
make menuconfig
FORCE:
validate:
@$(BUILDX) bake validate
lint:
@$(BUILDX) bake lint
clean:
rm -rf _output
shell:
@echo "$(WHALE) $@"
@$(BUILDX) bake dev
@docker run --rm -it --privileged \
--name nerdbox-dev \
-v ./:/go/src/$(MODULE_NAME) \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/$(MODULE_NAME) \
-e KERNEL_ARCH=$(ARCH) \
-e KERNEL_NPROC \
$(DOCKER_EXTRA_ARGS) \
nerdbox-dev
verify-vendor: ## verify if all the go.mod/go.sum files are up-to-date
@echo "$(WHALE) $@"
$(eval TMPDIR := $(shell mktemp -d))
@cp -R ${ROOTDIR} ${TMPDIR}
@(cd ${TMPDIR}/nerdbox && ${GO} mod tidy)
@(cd ${TMPDIR}/nerdbox && ${GO} mod verify)
diff -r -u ${ROOTDIR} ${TMPDIR}/nerdbox
@rm -rf ${TMPDIR}
test-unit:
go test -count=1 $(shell go list ./... | grep -v /integration)
test-integration: _output/integration.test
@echo "$(WHALE) $@"
gotestsum -f testname --raw-command ./integration/test.sh