forked from facebookresearch/CompilerGym
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
228 lines (161 loc) · 5.73 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
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 install-test
Build and install the python package (equivalent to 'make install'),
then run the full test suite against the installed package, and any
other tests that require the python package to be installed. This is
expensive and not typically required for local development.
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
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:
$(BAZEL) $(BAZEL_OPTS) build $(BAZEL_BUILD_OPTS) //:package
ifeq ($(OS),Linux)
cp -f $(LLVM_POLLY_SO) $(LLVM_SERVICE_DIR)/libLLVMPolly.so
chmod 666 $(LLVM_SERVICE_DIR)/service
patchelf --set-rpath '$$ORIGIN' $(LLVM_SERVICE_DIR)/service
chmod 555 $(LLVM_SERVICE_DIR)/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: 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)
docs: $(GENERATED_DOCS) install
$(MAKE) -C docs html
livedocs: $(GENERATED_DOCS) install
$(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) //...
tests-datasets:
cd .. && python -m compiler_gym.bin.datasets --env=llvm-v0 --download=cBench-v0 >/dev/null
pytest:
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 tests
install-test: | install tests-datasets pytest
post-install-test:
$(MAKE) -C examples/makefile_integration clean
SEARCH_TIME=3 $(MAKE) -C examples/makefile_integration test
.PHONY: test install-test post-install-test
################
# Installation #
################
install: bazel-build
$(PYTHON) setup.py install
.PHONY: install
##############
# Tidying up #
##############
.PHONY: clean distclean uninstall uninstall-purge
clean:
$(MAKE) -C docs clean
rm -rf $(GENERATED_DOCS) $(DISTTOOLS_OUTS)
distclean: clean
bazel clean --expunge
uninstall:
$(PYTHON) -m pip uninstall compiler_gym
uninstall-purge: uninstall
rm -rf $(HOME)/.cache/compiler_gym $(HOME)/logs/compiler_gym $(HOME)/.local/share/compiler_gym