forked from facebookresearch/CompilerGym
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
275 lines (199 loc) · 7.77 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
define HELP
CompilerGym $(VERSION). Available targets:
Setting up
----------
make init
Install the build and runtime python dependencies. This should be run
once before any other targets.
Testing
-------
make test
Run the test suite. Test results are cached so that incremental test
runs are minimal and fast. Use this as your go-to target for testing
modifications to the codebase.
make itest
Run the test suite continuously on change. This is equivalent to
manually running `make test` when a source file is modified. Note that
`make install-test` tests are not run. This requires bazel-watcher.
See: https://github.com/bazelbuild/bazel-watcher#installation
Post-installation Tests
-----------------------
make install-test
Run the full test suite against an installed CompilerGym package. This
requires that the CompilerGym package has been installed (`make
install`). This is useful for checking the package contents but is
usually not needed for interactive development since `make test` runs
the same tests without having to install anything.
make install-fuzz
Run the fuzz testing suite against an installed CompilerGym package.
Fuzz tests are tests that generate their own inputs and run in a loop
until an error has been found, or until a minimum number of seconds have
elapsed. This minimum time is controlled using a FUZZ_SECONDS variable.
The default is 300 seconds (5 minutes). Override this value at the
command line, for example `FUZZ_SECONDS=60 make install-fuzz` will run
the fuzz tests for a minimum of one minute. This requires that the
CompilerGym package has been installed (`make install`).
Documentation
-------------
make docs
Build the HTML documentation using Sphinx. This is the documentation
site that is hosted at <https://facebookresearch.github.io/CompilerGym>.
The generated HTML files are in docs/build/html.
make livedocs
Build the HTML documentation and serve them on localhost:8000. Changes
to the documentation will automatically trigger incremental rebuilds
and reload the changes.
Deployment
----------
make bdist_wheel
Build an optimized python wheel. The generated file is in
dist/compiler_gym-<version>-<platform_tags>.whl
make install
Build and install the python wheel.
make bdist_wheel-linux
Use a docker container to build a python wheel for linux. This is only
used for making release builds. This requires docker.
Tidying up
-----------
make clean
Remove build artifacts.
make distclean
Clean up all build artifacts, including the build cache.
make uninstall
Uninstall the python package.
make purge
Uninstall the python package and completely remove all datasets, logs,
and cached files. Any experimental data or generated logs will be
irreversibly deleted!
endef
export HELP
# Configurable paths to binaries.
CC ?= clang
CXX ?= clang++
BAZEL ?= bazel
IBAZEL ?= ibazel
PANDOC ?= pandoc
PYTHON ?= python3
# Bazel build options.
BAZEL_OPTS ?=
BAZEL_BUILD_OPTS ?= -c opt
BAZEL_TEST_OPTS ?=
# The path of the repository reoot.
ROOT := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
VERSION := $(shell cat VERSION)
OS := $(shell uname)
##############
# Setting up #
##############
.DEFAULT_GOAL := help
.PHONY: help init
help:
@echo "$$HELP"
init:
$(PYTHON) -m pip install -r requirements.txt
############
# Building #
############
# Files and directories generated by python disttools.
DISTTOOLS_OUTS := dist build compiler_gym.egg-info
# Post-build shenanigans to ship libLLVMPolly.so and patch the RPATH.
LLVM_SERVICE_DIR := $(ROOT)/bazel-bin/package.runfiles/CompilerGym/compiler_gym/envs/llvm/service
LLVM_POLLY_SO := $(ROOT)/bazel-bin/external/clang-llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/libLLVMPolly.so
bazel-build-pkg:
$(BAZEL) $(BAZEL_OPTS) build $(BAZEL_BUILD_OPTS) //:package
bazel-build: bazel-build-pkg
ifeq ($(OS),Linux)
cp -f $(LLVM_POLLY_SO) $(LLVM_SERVICE_DIR)/libLLVMPolly.so
chmod 666 $(LLVM_SERVICE_DIR)/compiler_gym-llvm-service
patchelf --set-rpath '$$ORIGIN' $(LLVM_SERVICE_DIR)/compiler_gym-llvm-service ; \
chmod 555 $(LLVM_SERVICE_DIR)/compiler_gym-llvm-service
endif
bdist_wheel: bazel-build
$(PYTHON) setup.py bdist_wheel
bdist_wheel-linux:
rm -rf build
docker build -t chriscummins/compiler_gym-linux-build packaging
docker run -v $(ROOT):/CompilerGym --rm chriscummins/compiler_gym-linux-build:latest /bin/sh -c 'cd /CompilerGym && make bdist_wheel'
mv dist/compiler_gym-$(VERSION)-py3-none-linux_x86_64.whl dist/compiler_gym-$(VERSION)-py3-none-manylinux2014_x86_64.whl
rm -rf build
all: docs bdist_wheel bdist_wheel-linux
.PHONY: bazel-build-pkg bazel-build bdist_wheel bdist_wheel-linux
#################
# Documentation #
#################
docs/source/changelog.rst: CHANGELOG.md
echo "..\n Generated from $<. Do not edit!\n" > $@
echo "Changelog\n=========\n" >> $@
$(PANDOC) --from=markdown --to=rst $< >> $@
docs/source/contributing.rst: CONTRIBUTING.md
echo "..\n Generated from $<. Do not edit!\n" > $@
$(PANDOC) --from=markdown --to=rst $< >> $@
docs/source/installation.rst: README.md
echo "..\n Generated from $<. Do not edit!\n" > $@
sed -n '/^## Installation/,$$p' $< | sed -n '/^## Trying/q;p' | $(PANDOC) --from=markdown --to=rst >> $@
GENERATED_DOCS := \
docs/source/changelog.rst \
docs/source/contributing.rst \
docs/source/installation.rst \
$(NULL)
gendocs: $(GENERATED_DOCS)
docs: gendocs bazel-build
PYTHONPATH=$(ROOT)/bazel-bin/package.runfiles/CompilerGym $(MAKE) -C docs html
livedocs: gendocs
PYTHONPATH=$(ROOT)/bazel-bin/package.runfiles/CompilerGym $(MAKE) -C docs livehtml
###########
# Testing #
###########
COMPILER_GYM_SITE_DATA ?= "/tmp/compiler_gym/tests/site_data"
COMPILER_GYM_CACHE ?= "/tmp/compiler_gym/tests/cache"
test:
$(BAZEL) $(BAZEL_OPTS) test $(BAZEL_TEST_OPTS) //...
itest:
$(IBAZEL) $(BAZEL_OPTS) test $(BAZEL_TEST_OPTS) //...
install-test-datasets:
cd .. && python -m compiler_gym.bin.datasets --env=llvm-v0 --download=cBench-v0 >/dev/null
install-test: install-test-datasets
mkdir -p /tmp/compiler_gym/wheel_tests
rm -f /tmp/compiler_gym/wheel_tests/tests
ln -s $(ROOT)/tests /tmp/compiler_gym/wheel_tests
cd /tmp/compiler_gym/wheel_tests && pytest -n auto tests -k "not fuzz"
# The minimum number of seconds to run the fuzz tests in a loop for. Override
# this at the commandline, e.g. `FUZZ_SECONDS=1800 make fuzz`.
FUZZ_SECONDS ?= 300
install-fuzz: install-test-datasets
mkdir -p /tmp/compiler_gym/wheel_fuzz_tests
rm -f /tmp/compiler_gym/wheel_fuzz_tests/tests
ln -s $(ROOT)/tests /tmp/compiler_gym/wheel_fuzz_tests
cd /tmp/compiler_gym/wheel_fuzz_tests && pytest tests -p no:sugar -x -vv -k fuzz --seconds=$(FUZZ_SECONDS)
post-install-test:
$(MAKE) -C examples/makefile_integration clean
SEARCH_TIME=3 $(MAKE) -C examples/makefile_integration test
.PHONY: test post-install-test
################
# Installation #
################
install: bazel-build
$(PYTHON) setup.py install
.PHONY: install
##############
# Tidying up #
##############
# A list of all filesystem locations that CompilerGym may use for storing
# files and data.
COMPILER_GYM_DATA_FILE_LOCATIONS = \
$(HOME)/.cache/compiler_gym \
$(HOME)/.local/share/compiler_gym \
$(HOME)/logs/compiler_gym \
/dev/shm/compiler_gym \
/tmp/compiler_gym \
$(NULL)
.PHONY: clean distclean uninstall purge
clean:
$(MAKE) -C docs clean || true
rm -rf $(GENERATED_DOCS) $(DISTTOOLS_OUTS)
distclean: clean
bazel clean --expunge
uninstall:
$(PYTHON) -m pip uninstall -y compiler_gym
purge: distclean uninstall
rm -rf $(COMPILER_GYM_DATA_FILE_LOCATIONS)