Building PyPy for M1 Macs (ARM64)
Check out PyPy source code using git like this: git clone https://github.com/mozillazg/pypy
Start at fede2fb234278db2ef4938e4b9b68a2328585faf:
git reset --hard fede2fb234278db2ef4938e4b9b68a2328585faf
Apply these patches:
- git am Add-functions-darwin_get_cpu_arch-and-darwin_get_dep.patch
- git am Improve-detection-of-computer-s-CPU-architecture-for.patch
- git am Fix-platform-detection-for-Apple-devices.patch
- git am Enough-macarm-to-start-failing-somewhere-interesting.patch
- git am Whoops-fix-Darwin_arm64-s-name.patch
- git am Fix-label-issue.patch
Install Python2 via MacPorts.
- sudo port install python2
Make sure that the python2 command points to a ARM64 version of Python 2.
Run this code to see if it is an ARM64 version:
import platform platform.machine()
What should be printed is: arm64
If you you see something else then building an ARM64 version of PyPy will not work.
cd to the goal directory. It's path looks like this: pypy/pypy/goal
run: python2 ../../rpython/bin/rpython --opt=jit
Running the binary:
The program will be called pypy-c. It will be located in the goal folder. Currently it quits with this error message:
Got an unexpected error trying to allocate some memory for the JIT (tried to do mmap() with PROT_EXEC|PROT_READ|PROT_WRITE). This can be caused by a system policy like PAX. You need to find how to work around the policy on your system. Abort trap: 6
This is still a work in progress so any help would be appreciated.
Note: If you can't apply a patch using 'git am', try using 'patch -p1 < file.patch'.