-
Notifications
You must be signed in to change notification settings - Fork 57
/
Makefile
208 lines (168 loc) · 6.83 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# Heap space for QVM in MiB.
QVM_WORKSPACE ?= 4096
THIS_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST))))
LISP_CACHE ?= `sbcl --noinform --non-interactive --eval '(princ asdf:*user-cache*)'`
QVM_LISP_CACHE ?= $(LISP_CACHE)$(THIS_DIR)
# QVM feature flags (in QVM_FEATURES)
QVM_FEATURE_FLAGS=$(foreach feature,$(QVM_FEATURES),--eval '(pushnew :$(feature) *features*)')
COMMIT_HASH=$(shell git rev-parse --short HEAD)
RIGETTI_LISP_LIBRARY_HOME=../
SBCL_BIN=sbcl
SBCL=$(SBCL_BIN) --dynamic-space-size $(QVM_WORKSPACE) --noinform --non-interactive --no-userinit --no-sysinit
QUICKLISP_HOME ?= $(HOME)/quicklisp
QUICKLISP_SETUP=$(QUICKLISP_HOME)/setup.lisp
QUICKLISP=$(SBCL) --load $(QUICKLISP_HOME)/setup.lisp \
--eval '(push (truename ".") asdf:*central-registry*)' \
--eval '(push :hunchentoot-no-ssl *features*)' \
--eval "(push (truename \"$(RIGETTI_LISP_LIBRARY_HOME)\") ql:*local-project-directories*)" \
$(QVM_FEATURE_FLAGS)
QUICKLISP_BOOTSTRAP_URL=https://beta.quicklisp.org/quicklisp.lisp
PREFIX ?= /usr/local
all: qvm
###############################################################################
# SETUP
###############################################################################
$(QUICKLISP_SETUP):
mkdir -p $(QUICKLISP_HOME)
curl -o $(QUICKLISP_HOME)/quicklisp-bootstrap.lisp \
$(QUICKLISP_BOOTSTRAP_URL)
$(SBCL) --load $(QUICKLISP_HOME)/quicklisp-bootstrap \
--eval "(quicklisp-quickstart:install :path \"$(QUICKLISP_HOME)\")"
system-index.txt: $(QUICKLISP_SETUP)
$(QUICKLISP) \
$(FOREST_SDK_FEATURE) \
--eval '(ql:quickload "cffi-grovel")' \
--eval '(ql:quickload "qvm-app")' \
--eval '(ql:write-asdf-manifest-file "system-index.txt")'
###############################################################################
# DEPENDENCIES
###############################################################################
install-test-deps:
ifeq ($(UNAME_S),Linux)
ifeq ($(shell sed -n "s/^ID=//p" /etc/os-release),debian)
apt-get update && apt-get install -y git libblas-dev libffi-dev liblapack-dev libzmq3-dev
else ifeq ($(shell sed -n "s/^ID=//p" /etc/os-release),ubuntu)
apt update && apt install -y git libblas-dev libffi-dev liblapack-dev libzmq3-dev
else
echo "Centos-based platforms unsupported"
endif
else
echo "Non-Linux-based platforms unsupported"
endif
dump-version-info:
$(QUICKLISP) \
--eval '(format t "~A ~A" (lisp-implementation-type) (lisp-implementation-version))' \
--eval '(print (ql-dist:find-system "magicl"))' \
--eval '(print (ql-dist:find-system "rpcq"))' \
--eval '(print (ql-dist:find-system "quilc"))' \
--eval '(terpri)' --quit
###############################################################################
# BUILD
###############################################################################
# FOREST_SDK_OPTION *must* come last - it triggers the end of normal
# SBCL option processing
qvm: system-index.txt
$(SBCL) $(FOREST_SDK_FEATURE) \
--eval "(setf sb-ext:\*on-package-variance\* '(:warn (:swank :swank-backend :swank-repl) :error t))" \
--eval '(push :hunchentoot-no-ssl *features*)' \
$(QVM_FEATURE_FLAGS) \
--load build-app.lisp \
$(FOREST_SDK_OPTION)
qvm-sdk-base: FOREST_SDK_FEATURE=--eval '(pushnew :forest-sdk *features*)' \
--eval '(push :drakma-no-ssl *features*)'
qvm-sdk-base: QVM_WORKSPACE=10240
qvm-sdk-base: clean clean-cache qvm
# By default, relocate shared libraries on SDK builds
qvm-sdk: FOREST_SDK_OPTION=--qvm-sdk
qvm-sdk: qvm-sdk-base
# Don't relocate shared libraries on barebones SDK builds
qvm-sdk-barebones: qvm-sdk-base
DOCKER_BUILD_TARGET=all
DOCKER_TAG=rigetti/qvm:$(COMMIT_HASH)
.PHONY: docker
docker: Dockerfile
docker build --build-arg build_target=$(DOCKER_BUILD_TARGET) \
-t $(DOCKER_TAG) .
docker-sdk: DOCKER_BUILD_TARGET=qvm-sdk
docker-sdk: DOCKER_TAG=qvm-sdk
docker-sdk: docker
docker-sdk-barebones: DOCKER_BUILD_TARGET=qvm-sdk-barebones
docker-sdk-barebones: DOCKER_TAG=qvm-sdk-barebones
docker-sdk-barebones: docker
###############################################################################
# INSTALL/UNINSTALL
###############################################################################
.PHONY: install
install: qvm
install -d $(DESTDIR)$(PREFIX)/bin/
install qvm $(DESTDIR)$(PREFIX)/bin/
.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/qvm
###############################################################################
# TEST
###############################################################################
testsafe:
sbcl --dynamic-space-size $(QVM_WORKSPACE) \
--noinform --non-interactive \
--eval "(sb-ext:restrict-compiler-policy 'safety 3)" \
--eval "(sb-ext:restrict-compiler-policy 'debug 3)" \
--eval '(ql:quickload :qvm-tests)' \
--eval '(asdf:test-system :qvm)'
test: test-lib test-app
test-lib: QVM_FEATURES=qvm-intrinsics
test-lib:
$(QUICKLISP) \
--eval '(ql:quickload :qvm-tests)' \
--eval '(asdf:test-system :qvm)'
test-app: QVM_FEATURES=qvm-intrinsics
test-app:
$(QUICKLISP) \
--eval '(ql:quickload :qvm-app-tests)' \
--eval '(asdf:test-system :qvm-app)'
test-ccl:
ccl --batch --eval '(ql:quickload :qvm)' --eval '(quit)'
coverage: QVM_FEATURES=qvm-intrinsics
coverage:
$(QUICKLISP) --load coverage-report/coverage-report.lisp
###############################################################################
# CLEAN
###############################################################################
# Clean the executables
clean:
rm -f qvm build-output.log system-index.txt
# Clean the Lisp cache, reindex local projects.
clean-cache:
@echo "Deleting $(LISP_CACHE)"
$(QUICKLISP) \
--eval "(ql:register-local-projects)"
rm -rf "$(LISP_CACHE)"
clean-qvm-cache:
@echo "Deleting $(QVM_LISP_CACHE)"
$(QUICKLISP) \
--eval "(ql:register-local-projects)"
rm -rf $(QVM_LISP_CACHE)
clean-quicklisp:
@echo "Cleaning up old projects in Quicklisp"
$(QUICKLISP) \
--eval '(ql-dist:clean (ql-dist:dist "quicklisp"))'
cleanall: clean clean-cache clean-quicklisp
@echo "All cleaned and reindexed."
###############################################################################
# QUICKLISP UTILITES
###############################################################################
# Download and install Quicklisp.
quicklisp:
curl -o /tmp/quicklisp.lisp "http://beta.quicklisp.org/quicklisp.lisp"
sbcl --noinform --non-interactive \
--load /tmp/quicklisp.lisp \
--eval '(quicklisp-quickstart:install)'
echo >> ~/.sbclrc
echo '#-quicklisp(let ((i(merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname))))(when(probe-file i)(load i)))' >> ~/.sbclrc
echo "#+quicklisp(push \"$(shell pwd | xargs dirname)/\" ql:*local-project-directories*)" >> ~/.sbclrc
rm -f /tmp/quicklisp.lisp
# Update Quicklisp.
deps: $(QUICKLISP_SETUP)
rm -f system-index.txt
$(QUICKLISP) --eval '(ql:update-client :prompt nil)'
$(QUICKLISP) --eval '(ql:update-dist "quicklisp" :prompt nil)'