Files
Julien Cristau 96e2a7c1c8 Bug 2055837 - fix Python.h discovery when building wheels against a fetched python. r=firefox-build-system-reviewers,bhearsum,ahochheiden
linux64-python3.9-dbus-python fetches the pinned python-3.9 toolchain
to build against, but building pycairo (a transitive build dependency
via meson-python for wheel_requirements.txt) failed:

  ../cairo/font.c:32:10: fatal error: Python.h: No such file or directory
  cc ... -I/python/include/python3.9 ...

build-cpython.sh makes the fetched python relocatable by patching
sysconfig's build_time_vars at extraction time, but its
python3.X-config script - which build backends like meson-python
consult to find headers - still has the unrelocated build-time prefix
baked in as plain text, since that script isn't Python code and never
gets patched. The headers do exist in the fetched toolchain, just not
where meson-python looked.

Add the real include directory to CPATH, which the compiler searches
regardless of what -I flags the build backend guessed.

Differential Revision: https://phabricator.services.mozilla.com/D312743
2026-07-24 08:07:31 +00:00

41 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This script builds the official interpreter for the python language,
# while also packing in a few default extra packages.
set -e
set -x
UPLOAD_DIR=$(pwd)/artifacts
mkdir -p "${UPLOAD_DIR}"
ls -hal "${MOZ_FETCHES_DIR}"
WHEEL_DIR=$(find "$MOZ_FETCHES_DIR/" -maxdepth 1 -mindepth 1 -type d -not -name "python")
export PATH="$MOZ_FETCHES_DIR/python/bin":/builds/worker/.local/bin:$PATH
# The fetched python toolchain is relocated at extraction time by patching
# sysconfig's build_time_vars, but its python3.X-config script still has the
# unrelocated build-time prefix (e.g. /python) baked in as plain text, which
# is what build backends like meson-python consult to find Python.h. Point
# the compiler at the real header location directly instead.
if [ -d "$MOZ_FETCHES_DIR/python/include" ]; then
python_include=$(find "$MOZ_FETCHES_DIR/python/include" -maxdepth 1 -name 'python3.*' -type d | head -n1)
if [ -n "$python_include" ]; then
export CPATH="$python_include${CPATH:+:$CPATH}"
fi
fi
python3 -m venv venv
. venv/bin/activate
python3 -m pip install -r "${GECKO_PATH}/build/wheel_requirements.txt"
cd "$WHEEL_DIR"
python3 -m build --no-isolation --wheel $@
whl=$(ls dist/*.whl)
cp "$whl" "$UPLOAD_DIR/"