-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
140 lines (112 loc) · 4.92 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
.SILENT:
.DEFAULT_GOAL := ci
SHELL := /bin/bash
SRCDIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
LINT_DIRTY ?= false
VERSION ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null | tr '[:upper:]' '[:lower:]' || echo "unknown")
DEPS_UPDATE ?= false
deps:
@echo "+++ $@ +++"
cd $(SRCDIR) && go mod tidy && go mod download
cd $(SRCDIR)/cmd/gguf-parser && go mod tidy && go mod download
if [[ "$(DEPS_UPDATE)" == "true" ]]; then \
cd $(SRCDIR) && go get -u -v ./...; \
cd $(SRCDIR)/cmd/gguf-parser && go get -u -v ./...; \
fi
@echo "--- $@ ---"
generate:
@echo "+++ $@ +++"
cd $(SRCDIR) && go generate ./...
cd $(SRCDIR)/cmd/gguf-parser && go generate ./...
@echo "--- $@ ---"
lint:
@echo "+++ $@ +++"
if [[ "$(LINT_DIRTY)" == "true" ]]; then \
if [[ -n $$(git status --porcelain) ]]; then \
echo "Code tree is dirty."; \
exit 1; \
fi; \
fi
[[ -d "$(SRCDIR)/.sbin" ]] || mkdir -p "$(SRCDIR)/.sbin"
[[ -f "$(SRCDIR)/.sbin/goimports-reviser" ]] || \
curl --retry 3 --retry-all-errors --retry-delay 3 -sSfL "https://github.com/incu6us/goimports-reviser/releases/download/v3.6.5/goimports-reviser_3.6.5_$(GOOS)_$(GOARCH).tar.gz" \
| tar -zxvf - --directory "$(SRCDIR)/.sbin" --no-same-owner --exclude ./LICENSE --exclude ./README.md && chmod +x "$(SRCDIR)/.sbin/goimports-reviser"
cd $(SRCDIR) && \
go list -f "{{.Dir}}" ./... | xargs -I {} find {} -maxdepth 1 -type f -name '*.go' ! -name 'gen.*' ! -name 'zz_generated.*' \
| xargs -I {} "$(SRCDIR)/.sbin/goimports-reviser" -use-cache -imports-order=std,general,company,project,blanked,dotted -output=file {}
cd $(SRCDIR)/cmd/gguf-parser && \
go list -f "{{.Dir}}" ./... | xargs -I {} find {} -maxdepth 1 -type f -name '*.go' ! -name 'gen.*' ! -name 'zz_generated.*' \
| xargs -I {} "$(SRCDIR)/.sbin/goimports-reviser" -use-cache -imports-order=std,general,company,project,blanked,dotted -output=file {}
[[ -f "$(SRCDIR)/.sbin/golangci-lint" ]] || \
curl --retry 3 --retry-all-errors --retry-delay 3 -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
| sh -s -- -b "$(SRCDIR)/.sbin" "v1.59.0"
cd $(SRCDIR) && \
"$(SRCDIR)/.sbin/golangci-lint" run --fix ./...
cd $(SRCDIR)/cmd/gguf-parser && \
"$(SRCDIR)/.sbin/golangci-lint" run --fix ./...
@echo "--- $@ ---"
test:
@echo "+++ $@ +++"
go test -v -failfast -race -cover -timeout=30m $(SRCDIR)/...
@echo "--- $@ ---"
benchmark:
@echo "+++ $@ +++"
go test -v -failfast -run="^Benchmark[A-Z]+" -bench=. -benchmem -timeout=30m $(SRCDIR)/...
@echo "--- $@ ---"
gguf-parser:
[[ -d "$(SRCDIR)/.dist" ]] || mkdir -p "$(SRCDIR)/.dist"
cd "$(SRCDIR)/cmd/gguf-parser" && for os in darwin linux windows; do \
tags="netgo"; \
if [[ $$os == "windows" ]]; then \
suffix=".exe"; \
tags="netcgo"; \
else \
suffix=""; \
fi; \
for arch in amd64 arm64; do \
echo "Building gguf-parser for $$os-$$arch $(VERSION)"; \
GOOS="$$os" GOARCH="$$arch" CGO_ENABLED=1 go build \
-trimpath \
-ldflags="-w -s -X main.Version=$(VERSION)" \
-tags="urfave_cli_no_docs $$tags" \
-o $(SRCDIR)/.dist/gguf-parser-$$os-$$arch$$suffix; \
done; \
if [[ $$os == "darwin" ]]; then \
[[ -d "$(SRCDIR)/.sbin" ]] || mkdir -p "$(SRCDIR)/.sbin"; \
[[ -f "$(SRCDIR)/.sbin/lipo" ]] || \
GOBIN="$(SRCDIR)/.sbin" go install github.com/konoui/[email protected]; \
"$(SRCDIR)/.sbin/lipo" -create -output $(SRCDIR)/.dist/gguf-parser-darwin-universal $(SRCDIR)/.dist/gguf-parser-darwin-amd64 $(SRCDIR)/.dist/gguf-parser-darwin-arm64; \
fi;\
if [[ $$os == "$(GOOS)" ]] && [[ $$arch == "$(GOARCH)" ]]; then \
cp -rf $(SRCDIR)/.dist/gguf-parser-$$os-$$arch$$suffix $(SRCDIR)/.dist/gguf-parser$$suffix; \
fi; \
done
build: gguf-parser
PACKAGE_PUBLISH ?= false
PACKAGE_REGISTRY ?= "gpustack"
PACKAGE_IMAGE ?= "gguf-parser"
package: build
@echo "+++ $@ +++"
if [[ -z $$(command -v docker) ]]; then \
echo "Docker is not installed."; \
exit 1; \
fi; \
platform="linux/amd64,linux/arm64"; \
image="$(PACKAGE_IMAGE):$(VERSION)"; \
if [[ -n "$(PACKAGE_REGISTRY)" ]]; then \
image="$(PACKAGE_REGISTRY)/$$image"; \
fi; \
if [[ "$(PACKAGE_PUBLISH)" == "true" ]]; then \
if [[ -z $$(docker buildx inspect --builder "gguf-parser") ]]; then \
docker run --rm --privileged tonistiigi/binfmt:qemu-v7.0.0 --install $$platform; \
docker buildx create --name "gguf-parser" --driver "docker-container" --buildkitd-flags "--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host" --bootstrap; \
fi; \
docker buildx build --progress=plain --platform=$$platform --builder="gguf-parser" --output="type=image,name=$$image,push=true" "$(SRCDIR)"; \
else \
platform="linux/$(GOARCH)"; \
docker buildx build --progress=plain --platform=$$platform --output="type=docker,name=$$image" "$(SRCDIR)"; \
fi
@echo "--- $@ ---"
ci: deps generate test lint build