From 4a82b7fc6f2e3d862508e7674973811afe22f759 Mon Sep 17 00:00:00 2001 From: swnf <50806201+swnf@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:54:49 +0100 Subject: [PATCH] Set EM_PKG_CONFIG_PATH to correctly configure pkg-config (#52) Closes #51 --------- --- CHANGELOG.md | 9 ++++++++- pyodide_build/buildpkg.py | 25 +++++++++++++++++-------- pyodide_build/tests/test_buildpkg.py | 3 +++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b53a709..d7e750c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,13 +5,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [0.29.1] ### Added - Add `skip_emscripten_version_check` flag and SKIP_EMSCRIPTEN_VERSION_CHECK environment variable to skip emscripten version check. [#53](https://github.com/pyodide/pyodide-build/pull/53) +- Set the `EM_PKG_CONFIG_PATH` environment variable used by emscripten/`pkg-config` to discover dependencies + [#52](https://github.com/pyodide/pyodide-build/pull/52) + +### Changed + +- Source tar files are now extracted with python's [data filter](https://docs.python.org/3/library/tarfile.html#tarfile.data_filter) + [#52](https://github.com/pyodide/pyodide-build/pull/52) - The `pyodide build` command will now raise an error if the local Python version has been changed, after the cross-build environment has been set up. diff --git a/pyodide_build/buildpkg.py b/pyodide_build/buildpkg.py index 2baf09f..0567f51 100755 --- a/pyodide_build/buildpkg.py +++ b/pyodide_build/buildpkg.py @@ -10,7 +10,6 @@ import shutil import subprocess import sys -import warnings from collections.abc import Iterator from datetime import datetime from email.message import Message @@ -356,12 +355,18 @@ def _download_and_extract(self) -> None: shutil.copy(tarballpath, self.src_dist_dir) return - with warnings.catch_warnings(): - # Python 3.12-3.13 emits a DeprecationWarning when using shutil.unpack_archive without a filter, - # but filter doesn't work well for zip files, so we suppress the warning until we find a better solution. - # https://github.com/python/cpython/issues/112760 - warnings.simplefilter("ignore") - shutil.unpack_archive(tarballpath, self.build_dir) + # Use a Python 3.14-like filter (see https://github.com/python/cpython/issues/112760) + # Can be removed once we use Python 3.14 + # The "data" filter will reset ownership but preserve permissions and modification times + # Without it, permissions and modification times will be silently skipped if the uid/git + # is too large for the chown() call. This behavior can lead to "Permission denied" errors + # (missing x bit) or random strange `make` behavior (due to wrong mtime order) in the CI + # pipeline. + shutil.unpack_archive( + tarballpath, + self.build_dir, + filter=None if tarballpath.suffix == ".zip" else "data", + ) extract_dir_name = self.source_metadata.extract_dir if extract_dir_name is None: @@ -556,7 +561,11 @@ def _get_helper_vars(self) -> dict[str, str]: "DISTDIR": str(self.src_dist_dir), # TODO: rename this to something more compatible with Makefile or CMake conventions "WASM_LIBRARY_DIR": str(self.library_install_prefix), - # Using PKG_CONFIG_LIBDIR instead of PKG_CONFIG_PATH, + # Emscripten will use this variable to configure pkg-config in emconfigure + "EM_PKG_CONFIG_PATH": str(self.library_install_prefix / "lib/pkgconfig"), + # This variable is usually overwritten by emconfigure + # The value below will only be used if pkg-config is called without emconfigure + # We use PKG_CONFIG_LIBDIR instead of PKG_CONFIG_PATH, # so pkg-config will not look in the default system directories "PKG_CONFIG_LIBDIR": str(self.library_install_prefix / "lib/pkgconfig"), } diff --git a/pyodide_build/tests/test_buildpkg.py b/pyodide_build/tests/test_buildpkg.py index ead13b2..2eaf3fa 100644 --- a/pyodide_build/tests/test_buildpkg.py +++ b/pyodide_build/tests/test_buildpkg.py @@ -126,6 +126,9 @@ def test_get_helper_vars(tmp_path): tmp_path / "pkg_1" / "build" / "pkg_1-1.0.0" / "dist" ) assert helper_vars["WASM_LIBRARY_DIR"] == str(tmp_path / ".libs") + assert helper_vars["EM_PKG_CONFIG_PATH"] == str( + tmp_path / ".libs" / "lib" / "pkgconfig" + ) assert helper_vars["PKG_CONFIG_LIBDIR"] == str( tmp_path / ".libs" / "lib" / "pkgconfig" )