Skip to content

Commit

Permalink
build: android reprod: "pip install" needs "--no-build-isolation"
Browse files Browse the repository at this point in the history
maybe fixes spesmilo#7640

Looks like by default pip is ignoring the locally available setuptools and wheel,
and downloading the latest ones from the internet at build time...

https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/?highlight=no-build-isolation#disabling-build-isolation
https://stackoverflow.com/a/62889268

> When making build requirements available, pip does so in an isolated environment. That is, pip does not install those requirements into the user’s site-packages, but rather installs them in a temporary directory which it adds to the user’s sys.path for the duration of the build. This ensures that build requirements are handled independently of the user’s runtime environment. For example, a project that needs a recent version of setuptools to build can still be installed, even if the user has an older version installed (and without silently replacing that version).
>
> In certain cases, projects (or redistributors) may have workflows that explicitly manage the build environment. For such workflows, build isolation can be problematic. If this is the case, pip provides a --no-build-isolation flag to disable build isolation. Users supplying this flag are responsible for ensuring the build environment is managed appropriately (including ensuring that all required build dependencies are installed).

If only it were that easy!
However, if we add the "--no-build-isolation" flag, it becomes our responsibility to install *all* build time deps,
hence we now have "requirements-build-makepackages.txt".
  • Loading branch information
SomberNight committed Jan 21, 2022
1 parent d8d2c18 commit 09fabe9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 20 deletions.
6 changes: 1 addition & 5 deletions contrib/build-linux/sdist/make_sdist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ python3 --version || fail "python interpreter not found"
break_legacy_easy_install

# upgrade to modern pip so that it knows the flags we need.
# we will then install a pinned version of pip as part of requirements-build-sdist
# (make_packages will later install a pinned version of pip in a venv)
python3 -m pip install --upgrade pip

info "Installing pinned requirements."
python3 -m pip install --no-dependencies --no-warn-script-location -r "$CONTRIB"/deterministic-build/requirements-build-sdist.txt


"$CONTRIB"/make_packages || fail "make_packages failed"

git submodule update --init
Expand Down
21 changes: 21 additions & 0 deletions contrib/deterministic-build/requirements-build-makepackages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
packaging==21.3 \
--hash=sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb \
--hash=sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522
pip==21.1 \
--hash=sha256:a810bf07c3723a28621c29abe8e34429fa082c337f89aea9a795865416b66d3e \
--hash=sha256:ea9f2668484893e90149fd5a6124e04651ffedd67203a8aaf030d31406b937a4
pyparsing==3.0.7 \
--hash=sha256:18ee9022775d270c55187733956460083db60b37d0d0fb357445f3094eed3eea \
--hash=sha256:a6c06a88f252e6c322f65faf8f418b16213b51bdfaece0524c1c1bc30c63c484
setuptools==56.0.0 \
--hash=sha256:08a1c0f99455307c48690f00d5c2ac2c1ccfab04df00454fef854ec145b81302 \
--hash=sha256:7430499900e443375ba9449a9cc5d78506b801e929fef4a186496012f93683b5
setuptools-scm==6.4.2 \
--hash=sha256:6833ac65c6ed9711a4d5d2266f8024cfa07c533a0e55f4c12f6eff280a5a9e30 \
--hash=sha256:acea13255093849de7ccb11af9e1fb8bde7067783450cee9ef7a93139bddf6d4
tomli==1.2.3 \
--hash=sha256:05b6166bff487dc068d322585c7ea4ef78deed501cc124060e0f238e89a9231f \
--hash=sha256:e3069e4be3ead9668e21cb9b074cd948f7b3113fd9c8bba083f48247aab8b11c
wheel==0.36.2 \
--hash=sha256:78b5b185f0e5763c26ca1e324373aadd49182ca90e825f7853f4b2509215dc0e \
--hash=sha256:e11eefd162658ea59a60a0f6c7d493a7190ea4b9a85e335b33489d9f17e0245e
9 changes: 0 additions & 9 deletions contrib/deterministic-build/requirements-build-sdist.txt

This file was deleted.

2 changes: 1 addition & 1 deletion contrib/freeze_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ which virtualenv > /dev/null 2>&1 || { echo "Please install virtualenv" && exit

${SYSTEM_PYTHON} -m hashin -h > /dev/null 2>&1 || { ${SYSTEM_PYTHON} -m pip install hashin; }

for i in '' '-hw' '-binaries' '-binaries-mac' '-build-wine' '-build-mac' '-build-sdist' '-build-appimage' '-build-android'; do
for i in '' '-hw' '-binaries' '-binaries-mac' '-build-wine' '-build-mac' '-build-makepackages' '-build-appimage' '-build-android'; do
rm -rf "$venv_dir"
virtualenv -p ${SYSTEM_PYTHON} $venv_dir

Expand Down
16 changes: 15 additions & 1 deletion contrib/make_packages
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ if [ -d "$PACKAGES" ]; then
rm -r "$PACKAGES"
fi

# create virtualenv
which virtualenv > /dev/null 2>&1 || { echo "Please install virtualenv" && exit 1; }
venv_dir="$(mktemp -d -t electrum_mkpkgs_venv-XXXXXXXXXX)"
virtualenv -p python3 "$venv_dir"
source "$venv_dir"/bin/activate

# installing pinned build-time requirements, such as pip/wheel/setuptools
python -m pip install --no-dependencies --no-warn-script-location -r "$CONTRIB"/deterministic-build/requirements-build-makepackages.txt

# opt out of compiling C extensions
# FIXME aiohttp opt-out is not released yet: https://github.com/aio-libs/aiohttp/pull/3828
export AIOHTTP_NO_EXTENSIONS=1
Expand All @@ -34,6 +43,11 @@ export BUILD_TIME="$(LC_ALL=C TZ=UTC date +'%H:%M:%S' -d @$SOURCE_DATE_EPOCH)"
# Hence "aiohttp-*.dist-info/" is not reproducible either.
# All this means that downstream users of this script, such as the sdist build
# and the android apk build need to make sure these files get excluded.
python3 -m pip install --no-compile --no-dependencies --no-binary :all: \
# note: --no-build-isolation is needed so that pip uses the locally available setuptools and wheel,
# instead of downloading the latest ones
python3 -m pip install --no-build-isolation --no-compile --no-dependencies --no-binary :all: \
-r "$CONTRIB"/deterministic-build/requirements.txt -t "$CONTRIB"/../packages

# clean-up
deactivate
rm -rf "$venv_dir"
14 changes: 14 additions & 0 deletions contrib/requirements/requirements-build-makepackages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file contains build-time dependencies needed to be able to build our pure python dependencies.
# For reproducibility, some build-time deps, most notably "wheel", need to be pinned. (see #7640)
# By default, when doing e.g. "pip install", pip downloads the latest version of wheel (and setuptools, etc),
# regardless whether a sufficiently recent version of wheel is already installed locally...
# The only way I have found to avoid this, is to use the "--no-build-isolation" flag,
# in which case it becomes our responsibility to install *all* build time deps...

pip
setuptools
wheel

# importlib_metadata also needs:
# https://github.com/python/importlib_metadata/blob/1e2381fe101fd70742a0171e51c1be82aedf519b/pyproject.toml#L2
setuptools_scm[toml]>=3.4.1
4 changes: 0 additions & 4 deletions contrib/requirements/requirements-build-sdist.txt

This file was deleted.

0 comments on commit 09fabe9

Please sign in to comment.