-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
184 lines (151 loc) · 5.2 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
SHELL := /bin/bash
# Disable built-in rules and variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
NETWORK := local
###########################################################################
# OS we're running on
ifeq ($(OS),Windows_NT)
detected_OS := Windows
else
detected_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
endif
ifeq ($(detected_OS),Darwin) # Mac OS X (Intel)
OS += macos
DIDC += didc-macos
endif
ifeq ($(detected_OS),Linux) # Ubuntu
OS += linux
DIDC += didc-linux64
endif
ifeq ($(detected_OS),Windows_NT) # Windows (icpp supports it but you cannot run this Makefile)
OS += windows_cannot_run_make
endif
ifeq ($(detected_OS),Unknown) # Unknown
OS += unknown
endif
###########################################################################
# latest release of didc
VERSION_DIDC := $(shell curl --silent "https://api.github.com/repos/dfinity/candid/releases/latest" | grep -e '"tag_name"' | cut -c 16-25)
# version to install for clang
VERSION_CLANG := $(shell cat version_clang.txt)
###########################################################################
# Use some clang tools that come with wasi-sdk
ICPP_COMPILER_ROOT := $(HOME)/.icpp/wasi-sdk/wasi-sdk-22.0
CLANG_FORMAT = $(ICPP_COMPILER_ROOT)/bin/clang-format
CLANG_TIDY = $(ICPP_COMPILER_ROOT)/bin/clang-tidy
###########################################################################
# CI/CD - Phony Makefile targets
#
.PHONY: all-tests
all-tests: all-static test-llm-wasm test-llm-native
.PHONY: build-info-cpp-wasm
build-info-cpp-wasm:
@echo "--"
@echo "Creating src/llama_cpp_onicai_fork/common/build-info.cpp for build-wasm"
sh src/llama_cpp_onicai_fork/scripts/build-info.sh $(ICPP_COMPILER_ROOT)/bin/clang > src/llama_cpp_onicai_fork/common/build-info.cpp
@echo "Content of src/llama_cpp_onicai_fork/common/build-info.cpp:"
@echo " "
@cat src/llama_cpp_onicai_fork/common/build-info.cpp
.PHONY: build-info-cpp-native
build-info-cpp-native:
@echo "--"
@echo "Creating src/llama_cpp_onicai_fork/common/build-info.cpp for build-native"
sh src/llama_cpp_onicai_fork/scripts/build-info.sh clang > src/llama_cpp_onicai_fork/common/build-info.cpp
@echo "Content of src/llama_cpp_onicai_fork/common/build-info.cpp:"
@echo " "
@cat src/llama_cpp_onicai_fork/common/build-info.cpp
.PHONY: summary
summary:
@echo "-------------------------------------------------------------"
@echo OS=$(OS)
@echo VERSION_DIDC=$(VERSION_DIDC)
@echo VERSION_CLANG=$(VERSION_CLANG)
@echo CLANG_FORMAT=$(CLANG_FORMAT)
@echo CLANG_TIDY=$(CLANG_TIDY)
@echo ICPP_COMPILER_ROOT=$(ICPP_COMPILER_ROOT)
@echo "-------------------------------------------------------------"
.PHONY: test-llm-native
test-llm-native:
dfx identity use default
icpp build-native
./build-native/mockic.exe
.PHONY: test-llm-wasm
test-llm-wasm:
dfx identity use default
python -m scripts.qa_deploy_and_pytest
.PHONY: all-static
all-static: \
cpp-format cpp-lint \
python-format python-lint python-type
CPP_AND_H_FILES = $(shell ls \
src/*.cpp src/*.h \
native/*.cpp native/*.h \
| grep -v "src/main_\.cpp")
.PHONY: cpp-format
cpp-format:
@echo "---"
@echo "cpp-format"
$(CLANG_FORMAT) --style=file --verbose -i $(CPP_AND_H_FILES)
.PHONY: cpp-lint
cpp-lint:
@echo "---"
@echo "cpp-lint"
@echo "TO IMPLEMENT with clang-tidy"
PYTHON_DIRS ?= scripts
.PHONY: python-format
python-format:
@echo "---"
@echo "python-format"
python -m black $(PYTHON_DIRS)
.PHONY: python-lint
python-lint:
@echo "---"
@echo "python-lint"
python -m pylint --jobs=0 --rcfile=.pylintrc $(PYTHON_DIRS)
.PHONY: python-type
python-type:
@echo "---"
@echo "python-type"
python -m mypy --config-file .mypy.ini --show-column-numbers --strict --explicit-package-bases $(PYTHON_DIRS)
###########################################################################
# Toolchain installation for .github/workflows
.PHONY: install-clang-ubuntu
install-clang-ubuntu:
@echo "Installing clang-$(VERSION_CLANG) compiler"
# sudo apt-get remove python3-lldb-14
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
echo | sudo ./llvm.sh $(VERSION_CLANG)
rm llvm.sh
@echo "Creating soft links for compiler executables"
sudo ln --force -s /usr/bin/clang-$(VERSION_CLANG) /usr/bin/clang
sudo ln --force -s /usr/bin/clang++-$(VERSION_CLANG) /usr/bin/clang++
# This installs ~/bin/dfx
# Make sure to source ~/.profile afterwards -> it adds ~/bin to the path if it exists
.PHONY: install-dfx
install-dfx:
DFXVM_INIT_YES=true sh -ci "$$(curl -fsSL https://sdk.dfinity.org/install.sh)"
.PHONY: install-didc
install-didc:
@echo "Installing didc $(VERSION_DIDC) ..."
sudo rm -rf /usr/local/bin/didc
wget https://github.com/dfinity/candid/releases/download/${VERSION_DIDC}/$(DIDC)
sudo mv $(DIDC) /usr/local/bin/didc
chmod +x /usr/local/bin/didc
@echo " "
@echo "Installed successfully in:"
@echo /usr/local/bin/didc
.PHONY: install-jp-ubuntu
install-jp-ubuntu:
sudo apt-get update && sudo apt-get install jp
.PHONY: install-jp-mac
install-jp-mac:
brew install jp
.PHONY: install-homebrew-mac
install-homebrew-mac:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
.PHONY: install-python
install-python:
pip install --upgrade pip
pip install -r requirements.txt