heroku / heroku-buildpack-python

Heroku's buildpack for Python applications.
https://www.heroku.com/python
MIT License
973 stars 1.83k forks source link

Adjust compiler options used to build Python #1566

Closed edmorley closed 3 months ago

edmorley commented 3 months ago

In order to improve parity with the upstream Docker Hub Python image builds, the build scripts used for our Python binary builds have been adjusted as follows:

After these changes, our compiler/linker options are now closer to: https://github.com/docker-library/python/blob/330331fbe3c8d19befaba10ee329c5bf3a9dc225/3.12/slim-bookworm/Dockerfile#L70-L89

These changes are being made now since we'll soon be generating new Python binaries/archives under a new URL structure, which will provide a safer/more convenient transition point to switching to these new compiler options (vs overwriting the existing archives on S3, or only making this change for new Python releases onwards).

GUS-W-14217295.


For reference, using Ubuntu 22.04 dpkg-buildflags --get CFLAGS currently returns: -g -O2 -ffile-prefix-map=/=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security

And dpkg-buildflags --get LDFLAGS returns: -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro

edmorley commented 3 months ago

An example build using these new options (it's based on a branch for a later PR, but uses these new options): https://github.com/heroku/heroku-buildpack-python/actions/runs/8703318932