This repository has been archived by the owner on May 9, 2023. It is now read-only.
forked from pypyjs/pypyjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
159 lines (120 loc) · 5.79 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
#
# Makefile for building various parts of pypyjs.
#
# Note that the pypyjs build environment is very particular - emscripten
# produces 32-bit code, so pypy must be translated using a 32-bit python
# interpreter with various 32-bit support libraries.
#
# The recommended approach is to use the pre-built docker image for the
# build environment, available via:
#
# docker pull rfkelly/pypyjs-build
#
# If you'd like to use your own versions of these dependencies you
# will need to install:
#
# * a working emscripten build environment
# * a 32-bit pypy interpreter, for running the build
# * a 32-bit cpython intereter, for running the tests
# * 32-bit development libraries for "libffi" and "libgc"
#
# You can tweak the makefile variables below to point to such an environment.
#
# This runs the dockerized build commands as if they were in the current
# directory, with write access to the current directory. For linux we
# can mount /etc/passwd and actually run as the current user. For OSX
# we run as root, assuming the curdir is under /Users, and hence that
# boot2docker will automagically share it with appropriate permissions.
DOCKER_IMAGE = rfkelly/pypyjs-build
DOCKER_ARGS = -ti --rm -v /tmp:/tmp -v $(CURDIR):$(CURDIR) -w $(CURDIR) -e "CFLAGS=$$CFLAGS" -e "LDFLAGS=$$LDFLAGS" -e "IN_DOCKER=1"
ifeq ($(shell uname -s),Linux)
# For linux, we can mount /etc/passwd and actually run as the current
# user, making permissions work nicely on created build artifacts.
# For other platforms we just run as the default docker user, assume
# that the current directory is somewhere boot2docker can automagically
# mount it, and hence build artifacts will get sensible permissions.
DOCKER_ARGS += -v /etc/passwd:/etc/passwd -u $(USER)
endif
ifeq ($(IN_DOCKER), 1)
DOCKER =
else
DOCKER = docker run $(DOCKER_ARGS) $(DOCKER_IMAGE)
endif
# Change these variables if you want to use a custom build environment.
# They must point to the emscripten compiler, a 32-bit python executable
# and a 32-bit pypy executable.
EMCC = $(DOCKER) emcc
PYTHON = $(DOCKER) python
PYPY = $(DOCKER) pypy
# The default target puts a built interpreter locally in ./lib.
.PHONY: lib
lib: ./lib/pypy.vm.js
./lib/pypy.vm.js: ./build/pypy.vm.js
cp ./build/pypy.vm.js ./lib/
python ./tools/extract_memory_initializer.py ./lib/pypy.vm.js
rm -rf ./lib/modules/
python tools/module_bundler.py init ./lib/modules/
# This makes a releasable tarball containing the compiled pypy interpreter,
# supporting javascript code, and the python stdlib modules and tooling.
VERSION = 0.3.0
.PHONY: release
release: ./build/pypy.js-$(VERSION).tar.gz
.PHONY: release-nojit
release-nojit: ./build/pypy-nojit.js-$(VERSION).tar.gz
.PHONY: release-debug
release-debug: ./build/pypy-debug.js-$(VERSION).tar.gz
./build/%.js-$(VERSION).tar.gz: RELNAME = $*.js-$(VERSION)
./build/%.js-$(VERSION).tar.gz: RELDIR = ./build/$(RELNAME)
./build/%.js-$(VERSION).tar.gz: ./build/%.vm.js
mkdir -p $(RELDIR)/lib
# Copy the compiled VM and massage it into the expected shape.
cp ./build/$*.vm.js $(RELDIR)/lib/pypy.vm.js
python ./tools/extract_memory_initializer.py $(RELDIR)/lib/pypy.vm.js
python ./tools/cromulate.py -w 1000 $(RELDIR)/lib/pypy.vm.js
# Copy the supporting JS library code.
cp ./lib/pypy.js ./lib/README.txt ./lib/Promise.min.js $(RELDIR)/lib/
python tools/module_bundler.py init $(RELDIR)/lib/modules/
# Copy tools for managing the distribution.
mkdir -p $(RELDIR)/tools
cp ./tools/module_bundler.py $(RELDIR)/tools/
# Copy release distribution metadata.
cp ./package.json $(RELDIR)/package.json
cp ./README.dist.rst $(RELDIR)/README.rst
# Tar it up, and we're done.
cd ./build && tar -czf $(RELNAME).tar.gz $(RELNAME)
rm -rf $(RELDIR)
# This is the necessary incantation to build the PyPy js backend
# in "release mode", optimized for deployment to the web. It trades
# off some debuggability in exchange for reduced code size.
./build/pypy.vm.js:
mkdir -p build
$(PYPY) ./deps/pypy/rpython/bin/rpython --backend=js --opt=jit --translation-backendopt-remove_asserts --inline-threshold=25 --output=./build/pypy.vm.js ./deps/pypy/pypy/goal/targetpypystandalone.py
# This builds a debugging-friendly version that is bigger but has e.g.
# more asserts and better traceback information.
./build/pypy-debug.vm.js:
mkdir -p build
export LDFLAGS="$$LDFLAGS -g2 -s ASSERTIONS=1" && $(PYPY) ./deps/pypy/rpython/bin/rpython --backend=js --opt=jit --inline-threshold=25 --output=./build/pypy-debug.vm.js ./deps/pypy/pypy/goal/targetpypystandalone.py
# This builds a version of pypy.js without its JIT, which is useful for
# investigating the size or performance of the core interpreter.
./build/pypy-nojit.vm.js:
mkdir -p build
$(PYPY) ./deps/pypy/rpython/bin/rpython --backend=js --opt=2 --translation-backendopt-remove_asserts --inline-threshold=25 --output=./build/pypy-nojit.vm.js ./deps/pypy/pypy/goal/targetpypystandalone.py
# This builds a smaller test program.
./build/rematcher.js:
mkdir -p build
$(PYPY) ./deps/pypy/rpython/bin/rpython --backend=js --opt=jit --translation-backendopt-remove_asserts --inline-threshold=25 --output=./build/rematcher.js ./tools/rematcher.py
./build/rematcher-nojit.js:
mkdir -p build
$(PYPY) ./deps/pypy/rpython/bin/rpython --backend=js --opt=2 --translation-backendopt-remove_asserts --inline-threshold=25 --output=./build/rematcher-nojit.js ./tools/rematcher.py
# Convenience target to launch a shell in the dockerized build environment.
shell:
$(DOCKER) /bin/bash
# Convenience targets for running the tests.
.PHONY: test
test: test-js-module test-jit-backend
.PHONY: test-jit-backend
test-jit-backend:
$(PYTHON) $(CURDIR)/deps/pypy/pytest.py --platform=emscripten -vx ./deps/pypy/rpython/jit/backend/asmjs
.PHONY: test-js-module
test-js-module:
$(PYTHON) $(CURDIR)/deps/pypy/pytest.py -vx ./deps/pypy/pypy/module/js