Heroku Python Buildpack with LuaJIT and libffi
A fork of Heroku's 2013 Python buildpack that also builds LuaJIT, for lupa, and libffi, for pyOpenSSL. Fixed in 2026.
A fork of Heroku's buildpack as it was in 2013. Its two steps were fixed in 2026 but have not been run since: the rest of the buildpack still expects Heroku's 2013 stack, long retired. On a current stack the official Python buildpack installs lupa and pyOpenSSL as they are.
The Python service I made this fork for needed two C libraries that Heroku's stack did not have. It used Lua for scripting on the server, through lupa, the Python binding for Lua, and lupa needs LuaJIT. It also validated Apple in-app purchase receipts, which are signed PKCS #7 containers, with pyOpenSSL; pyOpenSSL needs cryptography, cryptography needs cffi, and cffi needs libffi. The fork builds both libraries into the application before pip installs the packages that link against them.
Why a fork
A Heroku buildpack is three scripts. bin/detect says whether it recognises the application, bin/compile installs everything into the build directory, and bin/release says how to start the result. In 2013 an application got exactly one buildpack, so when the language buildpack did not install something you needed, the way out was to fork it and add a step. This is that fork, of Heroku's Python buildpack as it was on 14 November 2013.
How it works
bin/compile is upstream's, with two steps sourced after its pylibmc step and before pip install, so the libraries and their pkg-config files are in place by the time pip builds lupa or cffi. The 2013 buildpack moves the build directory to /app for the length of the compile, so .heroku/vendor during the build is /app/.heroku/vendor at run time, and the compiled extensions find their libraries at the path they were linked against. .heroku is also what the buildpack caches between builds, so each library is built once.
| Step | Runs when requirements.txt names | Builds | Found by |
|---|---|---|---|
bin/steps/luajit | lupa | LuaJIT 2.0.2, with make install | lupa's setup.py, through pkg-config luajit |
bin/steps/libffi | cffi, cryptography or pyOpenSSL | libffi 3.1, with configure and make | cffi's setup.py, through pkg-config libffi |
Both download from Fedora's source archive, which files each tarball under its MD5, and check the download against a SHA-256 before building. The libffi step, trimmed:
LIBFFI_URL="https://src.fedoraproject.org/repo/pkgs/libffi/libffi-$LIBFFI_VERSION.tar.gz/f5898b29bbfd70502831a212d9249d10/libffi-$LIBFFI_VERSION.tar.gz"
LIBFFI_SHA256="97feeeadca5e21870fa4433bc953d1b3af3f698d5df8a428f68b73cd60aef6eb"
LIBFFI_PREFIX=/app/.heroku/vendor
if (grep -Eiq "^\s*(cffi|cryptography|pyopenssl)" requirements.txt) then
if [ -f "$LIBFFI_PREFIX/lib/pkgconfig/libffi.pc" ]; then
puts-step "Noticed cffi. Using cached libffi ($LIBFFI_VERSION)."
else
curl -s -f -L -o "$LIBFFI_TMP/libffi.tar.gz" "$LIBFFI_URL"
echo "$LIBFFI_SHA256 $LIBFFI_TMP/libffi.tar.gz" | sha256sum -c - > /dev/null
tar -zxf "$LIBFFI_TMP/libffi.tar.gz" -C "$LIBFFI_TMP"
(
cd "$LIBFFI_TMP/libffi-$LIBFFI_VERSION"
./configure --prefix="$LIBFFI_PREFIX" --libdir="$LIBFFI_PREFIX/lib" --disable-static
make
make install
) 2>&1 | indent
fi
fiHistory
- 25 November 2013. 25 commits between 13:00 and 19:31, nine of them called “added luajit”: every attempt was a push to GitHub and a push of a test application to Heroku. What finally made lupa build was the commit at 19:18, which corrected upstream's
PKG_CONFIG_PATHfromlib/pkg-config, a directory nothing creates, tolib/pkgconfig. - 18 January 2015. The libffi step: a script that was going around in other forks at the time, which unpacked a pre-compiled libffi 3.0 from an Amazon S3 bucket into
/app/vendor. - 25 February 2015. “replaced libffi”: the binary was swapped for Fedora's libffi 3.1 source tarball, which the step only unpacked. From then on it built nothing.
- 29 October 2026. Both steps fixed.
Fixed in 2026
- libffi is built and installed into
.heroku/vendor, which is on the run-time library path. The 2015 location,/app/vendor/libffi-3.0, only ever was during the build. - The downloads moved from luajit.org (404 today) and the S3 bucket (403) to Fedora's archive, with a SHA-256 check, and
curl -f, so a missing file stops the build instead of being unpacked as an error page. - Each step runs only when the requirements need it (the 2015 libffi step announced “Noticed cffi” on every build), and reuses a cached copy.
PKG_CONFIG_PATHnameslib/pkgconfig, where LuaJIT and libffi install their files, instead of upstream'slib/pkg-configwith the right directory appended in 2013.vendor/lupa-0.20, a copy of the lupa source with LuaJIT inside it (207 files, 138,275 lines), was removed. No script ever referenced it.
The rest of the buildpack is upstream's 2013 code and was left alone. Its build tooling needs Python 2 and it downloads Python 2.7 runtimes from a bucket that no longer serves them, so it does not build on any current stack.
Today
There is nothing to fork. lupa, cffi and cryptography install as manylinux wheels that carry LuaJIT, libffi and OpenSSL inside them, so the official Python buildpack builds a requirements.txt with lupa and pyOpenSSL as it is. On heroku-24, in October 2026, the whole build took 24 seconds and compiled nothing (the build log and a check script, trimmed):
Successfully installed cffi-2.1.1 cryptography-50.0.2 lupa-2.8 pyOpenSSL-26.4.0 pycparser-3.12 lupa 2.8 | LuaJIT 2.1.1774896198 | Lua 5.1 pyOpenSSL 26.4.0 | cryptography 50.0.2
Apple has moved on too. Its verifyReceipt endpoint was deprecated in June 2023, StoreKit 2 delivers transactions signed as JWS (JSON Web Signature), and Apple's App Store Server Library, which has a Python version, verifies them.