Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpython: several fixes #10795

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions recipes/cpython/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"3.10.3":
url: "https://www.python.org/ftp/python/3.10.3/Python-3.10.3.tgz"
sha256: "5a3b029bad70ba2a019ebff08a65060a8b9b542ffc1a83c697f1449ecca9813b"
"3.10.0":
url: "https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz"
sha256: "c4e0cbad57c90690cb813fb4663ef670b4d0f587d8171e2c42bd4c9245bd2758"
Expand All @@ -11,20 +14,37 @@ sources:
"3.7.12":
url: "https://www.python.org/ftp/python/3.7.12/Python-3.7.12.tgz"
sha256: "33b4daaf831be19219659466d12645f87ecec6eb21d4d9f9711018a7b66cce46"
"2.7.18":
url: "https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz"
sha256: "da3080e3b488f648a3d7a4560ddee895284c3380b11d6de75edb986526b9a814"
# "2.7.18":
# url: "https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz"
# sha256: "da3080e3b488f648a3d7a4560ddee895284c3380b11d6de75edb986526b9a814"
patches:
"3.10.3":
- patch_file: "patches/3.10.3-0001-msvc.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.9.7-0002-_msi-vcxproj.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.10.3-0003-_ctypes-ffi.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.10.3-0004-setup.py-pass-CFLAGS-CPPFLAGS.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.10.3-0005-do-not-search-for-system-tkinter.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.10.3-0006-restore-support-for-windows-7.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.x-0001-relocatable-python-config.patch"
base_path: "source_subfolder"
"3.10.0":
- patch_file: "patches/3.10.0-0001-msvc.patch"
- patch_file: "patches/3.10.3-0001-msvc.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.9.7-0002-_msi-vcxproj.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.10.0-0003-_ctypes-ffi.patch"
- patch_file: "patches/3.10.3-0003-_ctypes-ffi.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.10.0-0004-setup.py-pass-CFLAGS-CPPFLAGS.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.10.0-0005-disable-macos-tcltk.patch"
- patch_file: "patches/3.10.0-0005-do-not-search-for-system-tkinter.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.10.0-0006-restore-support-for-windows-7.patch"
base_path: "source_subfolder"
- patch_file: "patches/3.x-0001-relocatable-python-config.patch"
base_path: "source_subfolder"
Expand Down
67 changes: 57 additions & 10 deletions recipes/cpython/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from conans import AutoToolsBuildEnvironment, ConanFile, MSBuild, tools
from conans.errors import ConanInvalidConfiguration
from conans.errors import ConanInvalidConfiguration, ConanException
from io import StringIO
import os
import re
Expand Down Expand Up @@ -36,6 +36,7 @@ class CPythonConan(ConanFile):
"with_bsddb": [True, False],
# Python 3 options
"with_lzma": [True, False],
"win7_support": [True, False],

# options that don't change package id
"env_vars": [True, False], # set environment variables
Expand All @@ -59,6 +60,7 @@ class CPythonConan(ConanFile):
"with_bsddb": False, # True, # FIXME: libdb package missing (#5309/#5392)
# Python 3 options
"with_lzma": True,
"win7_support": False,

# options that don't change package id
"env_vars": True,
Expand Down Expand Up @@ -111,10 +113,13 @@ def config_options(self):
if self._is_py2:
# Python 2.xx does not support following options
del self.options.with_lzma
del self.options.win7_support
elif self._is_py3:
# Python 3.xx does not support following options
del self.options.with_bsddb
del self.options.unicode
if self.version < "3.10.0":
del self.options.win7_support

del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
Expand All @@ -134,6 +139,10 @@ def configure(self):
self.generators.append("MSBuildDeps")

def validate(self):
# FIXME
if self.settings.os == "Macos":
raise ConanInvalidConfiguration("XXX")

if self.options.shared:
if self.settings.compiler == "Visual Studio" and "MT" in self.settings.compiler.runtime:
raise ConanInvalidConfiguration("cpython does not support MT(d) runtime when building a shared cpython library")
Expand Down Expand Up @@ -178,7 +187,7 @@ def requirements(self):
self.requires("openssl/1.1.1l")
self.requires("expat/2.4.1")
if self._with_libffi:
self.requires("libffi/3.2.1")
self.requires("libffi/3.4.2")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to make the libffi version dependent of the python version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor

@madebr madebr May 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's working, then it's fine.
But in my experience with cpython + libffi, there is some coupling with libffi versioning and cpython versions.

if tools.Version(self._version_number_only) < "3.8":
self.requires("mpdecimal/2.4.2")
elif tools.Version(self._version_number_only) < "3.10":
Expand Down Expand Up @@ -263,8 +272,17 @@ def _configure_autotools(self):
return self._autotools

def _patch_sources(self):
for patch in self.conan_data.get("patches",{}).get(self.version, []):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
if "restore-support-for-windows-7" in patch["patch_file"] \
and not self.options.get_safe("win7_support", False):
continue
tools.patch(**patch)
if self.settings.compiler == "apple-clang":
# https://bugs.python.org/issue45405
tools.replace_in_file(os.path.join(self._source_subfolder, "configure"),
"MULTIARCH=$($CC --print-multiarch 2>/dev/null)",
"MULTIARCH=")

if self._is_py3 and tools.Version(self._version_number_only) < "3.10":
tools.replace_in_file(os.path.join(self._source_subfolder, "setup.py"),
":libmpdec.so.2", "mpdec")
Expand All @@ -290,6 +308,24 @@ def _patch_sources(self):
tools.replace_in_file(os.path.join(self._source_subfolder, "setup.py"),
"curses_libs = ",
"curses_libs = {} #".format(repr(self.deps_cpp_info["ncurses"].libs + self.deps_cpp_info["ncurses"].system_libs)))
else:
tools.replace_in_file(
os.path.join(self._source_subfolder, "setup.py"),
"curses_library.startswith('ncurses')",
"False"
)
try:
tools.replace_in_file(
os.path.join(self._source_subfolder, "setup.py"),
"curses_library == 'curses' and not MACOS",
"False"
)
except ConanException:
tools.replace_in_file(
os.path.join(self._source_subfolder, "setup.py"),
"curses_library == 'curses' and host_platform != 'darwin'",
"False"
)

# Enable static MSVC cpython
if not self.options.shared:
Expand Down Expand Up @@ -402,7 +438,8 @@ def _msvc_build(self):
for project_i, project in enumerate(projects, 1):
self.output.info("[{}/{}] Building project '{}'...".format(project_i, len(projects), project))
project_file = os.path.join(self._source_subfolder, "PCbuild", project + ".vcxproj")
self._upgrade_single_project_file(project_file)
if not tools.get_env("CONAN_SKIP_VS_PROJECTS_UPGRADE", False):
self._upgrade_single_project_file(project_file)
msbuild.build(project_file, upgrade_project=False, build_type="Debug" if self.settings.build_type == "Debug" else "Release",
platforms=self._msvc_archs, properties=msbuild_properties)

Expand All @@ -416,16 +453,22 @@ def build(self):
if tools.Version(self.deps_cpp_info["mpdecimal"].version) < "2.5.0":
raise ConanInvalidConfiguration("cpython 3.9.0 (and newer) requires (at least) mpdecimal 2.5.0")

if self._with_libffi:
if tools.Version(self.deps_cpp_info["libffi"].version) >= "3.3" and self.settings.compiler == "Visual Studio" and "d" in str(self.settings.compiler.runtime):
raise ConanInvalidConfiguration("libffi versions >= 3.3 cause 'read access violations' when using a debug runtime (MTd/MDd)")

self._patch_sources()
if self.settings.compiler == "Visual Studio":
self._msvc_build()
else:
autotools = self._configure_autotools()
autotools.make()
env = {}
if self.settings.compiler == "apple-clang": # how to compute the right value?
env["MACOSX_DEPLOYMENT_TARGET"] = "10.3" # FIXME : clang: error: invalid version number in 'MACOSX_DEPLOYMENT_TARGET=11.6'
with tools.environment_append(env):
try:
autotools = self._configure_autotools()
autotools.make()
except Exception as e:
config_log = os.path.join(self.build_folder, "config.log")
if os.path.isfile:
self.run('cat %s' % config_log)
raise e

@property
def _msvc_artifacts_path(self):
Expand Down Expand Up @@ -659,16 +702,19 @@ def package_info(self):
self.cpp_info.components["_python_copy"].names["pkg_config"] = "python{}".format(py_version.major)
self.cpp_info.components["_python_copy"].requires = ["python"]
self.cpp_info.components["_python_copy"].libdirs = []
self.cpp_info.components["_python_copy"].includedirs = []

# embed component: "Embed Python into an application"
self.cpp_info.components["embed"].libs = [self._lib_name]
self.cpp_info.components["embed"].libdirs = [libdir]
self.cpp_info.components["embed"].includedirs = []
self.cpp_info.components["embed"].names["pkg_config"] = "python-{}.{}-embed".format(py_version.major, py_version.minor)
self.cpp_info.components["embed"].requires = ["python"]

self.cpp_info.components["_embed_copy"].requires = ["embed"]
self.cpp_info.components["_embed_copy"].names["pkg_config"] = ["python{}-embed".format(py_version.major)]
self.cpp_info.components["_embed_copy"].libdirs = []
self.cpp_info.components["_embed_copy"].includedirs = []

if self._supports_modules:
# hidden components: the C extensions of python are built as dynamically loaded shared libraries.
Expand Down Expand Up @@ -699,6 +745,7 @@ def package_info(self):
if self.options.get_safe("with_tkinter"):
self.cpp_info.components["_hidden"].requires.append("tk::tk")
self.cpp_info.components["_hidden"].libdirs = []
self.cpp_info.components["_hidden"].includedirs = []

if self.options.env_vars:
bindir = os.path.join(self.package_folder, "bin")
Expand Down
13 changes: 0 additions & 13 deletions recipes/cpython/all/patches/3.10.0-0005-disable-macos-tcltk.patch

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- setup.py
+++ setup.py
@@ -2090,7 +2090,7 @@
# and _TCLTK_LIBS environment variables.
if self.detect_tkinter_fromenv():
return True
-
+ return False
# Rather than complicate the code below, detecting and building
# AquaTk is a separate method. Only one Tkinter will be built on
# Darwin - either AquaTk, if it is found, or X11 based Tk.
Loading