From 06aeb0603257d9664e05b008abd6d38e3b048b75 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 3 Oct 2024 11:43:09 +0300 Subject: [PATCH 1/5] cpython: enable macOS x86_64 by disabling broken deps --- recipes/cpython/all/conanfile.py | 5 +++++ recipes/cpython/all/test_package/conanfile.py | 1 + 2 files changed, 6 insertions(+) diff --git a/recipes/cpython/all/conanfile.py b/recipes/cpython/all/conanfile.py index c98c3381c1c65..00795d0a2dbbc 100644 --- a/recipes/cpython/all/conanfile.py +++ b/recipes/cpython/all/conanfile.py @@ -5,6 +5,7 @@ from conan import ConanFile from conan.errors import ConanInvalidConfiguration from conan.tools.apple import is_apple_os, fix_apple_shared_install_name +from conan.tools.build import cross_building from conan.tools.env import VirtualRunEnv from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, load, mkdir, replace_in_file, rm, rmdir, save, unzip from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps, PkgConfigDeps @@ -86,6 +87,10 @@ def config_options(self): del self.options.with_curses del self.options.with_gdbm del self.options.with_nis + if is_apple_os(self) and cross_building(self): + # FIXME: The corresponding recipes currently don't support cross building + self.options.with_tkinter = False + self.options.with_curses = False self.settings.compiler.rm_safe("libcxx") self.settings.compiler.rm_safe("cppstd") diff --git a/recipes/cpython/all/test_package/conanfile.py b/recipes/cpython/all/test_package/conanfile.py index 6f20bfa199e7a..4d6f067c9bc90 100644 --- a/recipes/cpython/all/test_package/conanfile.py +++ b/recipes/cpython/all/test_package/conanfile.py @@ -80,6 +80,7 @@ def generate(self): # The build also needs access to the run environment to run the python executable VirtualRunEnv(self).generate(scope="run") + # Required for find_package() work with shared=True VirtualRunEnv(self).generate(scope="build") if self._test_setuptools: From 1e83747eac83fef8535667488554d228a24f83af Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 3 Oct 2024 11:47:19 +0300 Subject: [PATCH 2/5] cpython: mark package_type as static-library for MSVC --- recipes/cpython/all/conanfile.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/recipes/cpython/all/conanfile.py b/recipes/cpython/all/conanfile.py index 00795d0a2dbbc..6e9a68a7d95ed 100644 --- a/recipes/cpython/all/conanfile.py +++ b/recipes/cpython/all/conanfile.py @@ -66,7 +66,7 @@ class CPythonConan(ConanFile): @property def _supports_modules(self): - return not is_msvc(self) or self.options.shared + return not is_msvc(self) or self.options.get_safe("shared") @property def _version_suffix(self): @@ -103,6 +103,12 @@ def configure(self): self.options.rm_safe("with_sqlite3") self.options.rm_safe("with_tkinter") self.options.rm_safe("with_lzma") + if is_msvc and Version(self.version) >= "3.10": + # Static CPython on Windows is only loosely supported, see https://github.com/python/cpython/issues/110234 + # 3.10 fails during the test, 3.11 fails during the build (missing symbol that seems to be DLL specific: PyWin_DLLhModule) + # Disabling static MSVC builds (>=3.10) due to "AttributeError: module 'sys' has no attribute 'winver'" + self.package_type = "static-library" + del self.options.shared def layout(self): basic_layout(self, src_folder="src") @@ -153,7 +159,7 @@ def package_id(self): del self.info.options.env_vars def validate(self): - if self.options.shared: + if self.options.get_safe("shared"): if is_msvc_static_runtime(self): raise ConanInvalidConfiguration( "cpython does not support MT(d) runtime when building a shared cpython library" @@ -175,10 +181,6 @@ def validate(self): ) if str(self.settings.arch) not in self._msvc_archs: raise ConanInvalidConfiguration("Visual Studio does not support this architecture") - if not self.options.shared and Version(self.version) >= "3.10": - # Static CPython on Windows is only loosely supported, see https://github.com/python/cpython/issues/110234 - # 3.10 fails during the test, 3.11 fails during the build (missing symbol that seems to be DLL specific: PyWin_DLLhModule) - raise ConanInvalidConfiguration("Static msvc build disabled (>=3.10) due to \"AttributeError: module 'sys' has no attribute 'winver'\"") if self.options.get_safe("with_curses", False) and not self.dependencies["ncurses"].options.with_widec: raise ConanInvalidConfiguration("cpython requires ncurses with wide character support") @@ -441,7 +443,7 @@ def _patch_sources(self): "$(RUNSHARED) CC='$(CC) $(CONFIGURE_CFLAGS) $(CONFIGURE_CPPFLAGS)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)'") # Enable static MSVC cpython - if not self.options.shared: + if not self.options.get_safe("shared"): replace_in_file(self, os.path.join(self.source_folder, "PCbuild", "pythoncore.vcxproj"), "", "Py_NO_BUILD_SHARED;") @@ -478,7 +480,7 @@ def _patch_sources(self): @property def _solution_projects(self): - if self.options.shared: + if self.options.get_safe("shared"): solution_path = os.path.join(self.source_folder, "PCbuild", "pcbuild.sln") projects = set(m.group(1) for m in re.finditer('"([^"]+)\\.vcxproj"', open(solution_path).read())) @@ -658,7 +660,7 @@ def _exact_lib_name(self): prefix = "" if self.settings.os == "Windows" else "lib" if self.settings.os == "Windows": extension = "lib" - elif not self.options.shared: + elif not self.options.get_safe("shared"): extension = "a" elif is_apple_os(self): extension = "dylib" @@ -722,7 +724,7 @@ def _write_cmake_findpython_wrapper_file(self): def package(self): copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) if is_msvc(self): - if self.options.shared: + if self.options.get_safe("shared"): self._msvc_package_layout() else: self._msvc_package_copy() @@ -820,7 +822,7 @@ def package_info(self): os.path.join("include", f"python{self._version_suffix}{self._abi_suffix}") ) libdir = "lib" - if self.options.shared: + if self.options.get_safe("shared"): self.cpp_info.components["python"].defines.append("Py_ENABLE_SHARED") else: self.cpp_info.components["python"].defines.append("Py_NO_ENABLE_SHARED") From 783662d82e196a7ec8825b461937615ed98e769e Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Fri, 4 Oct 2024 08:55:33 +0300 Subject: [PATCH 3/5] cpython: fix package type --- recipes/cpython/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/cpython/all/conanfile.py b/recipes/cpython/all/conanfile.py index 6e9a68a7d95ed..7e0612ff19da6 100644 --- a/recipes/cpython/all/conanfile.py +++ b/recipes/cpython/all/conanfile.py @@ -107,7 +107,7 @@ def configure(self): # Static CPython on Windows is only loosely supported, see https://github.com/python/cpython/issues/110234 # 3.10 fails during the test, 3.11 fails during the build (missing symbol that seems to be DLL specific: PyWin_DLLhModule) # Disabling static MSVC builds (>=3.10) due to "AttributeError: module 'sys' has no attribute 'winver'" - self.package_type = "static-library" + self.package_type = "shared-library" del self.options.shared def layout(self): From 4d5827560711bf9d10efc553871517b3f6bbb9e6 Mon Sep 17 00:00:00 2001 From: Alex Trotta Date: Sun, 6 Oct 2024 23:31:51 -0400 Subject: [PATCH 4/5] Act as if package is in shared mode if self.options.shared doesn't exist --- recipes/cpython/all/conanfile.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/recipes/cpython/all/conanfile.py b/recipes/cpython/all/conanfile.py index 7e0612ff19da6..90a91224e4d5b 100644 --- a/recipes/cpython/all/conanfile.py +++ b/recipes/cpython/all/conanfile.py @@ -66,7 +66,7 @@ class CPythonConan(ConanFile): @property def _supports_modules(self): - return not is_msvc(self) or self.options.get_safe("shared") + return not is_msvc(self) or self.options.get_safe("shared", default=True) @property def _version_suffix(self): @@ -159,7 +159,7 @@ def package_id(self): del self.info.options.env_vars def validate(self): - if self.options.get_safe("shared"): + if self.options.get_safe("shared", default=True): if is_msvc_static_runtime(self): raise ConanInvalidConfiguration( "cpython does not support MT(d) runtime when building a shared cpython library" @@ -443,7 +443,7 @@ def _patch_sources(self): "$(RUNSHARED) CC='$(CC) $(CONFIGURE_CFLAGS) $(CONFIGURE_CPPFLAGS)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)'") # Enable static MSVC cpython - if not self.options.get_safe("shared"): + if not self.options.get_safe("shared", default=True): replace_in_file(self, os.path.join(self.source_folder, "PCbuild", "pythoncore.vcxproj"), "", "Py_NO_BUILD_SHARED;") @@ -480,7 +480,7 @@ def _patch_sources(self): @property def _solution_projects(self): - if self.options.get_safe("shared"): + if self.options.get_safe("shared", default=True): solution_path = os.path.join(self.source_folder, "PCbuild", "pcbuild.sln") projects = set(m.group(1) for m in re.finditer('"([^"]+)\\.vcxproj"', open(solution_path).read())) @@ -660,7 +660,7 @@ def _exact_lib_name(self): prefix = "" if self.settings.os == "Windows" else "lib" if self.settings.os == "Windows": extension = "lib" - elif not self.options.get_safe("shared"): + elif not self.options.get_safe("shared", default=True): extension = "a" elif is_apple_os(self): extension = "dylib" @@ -724,7 +724,7 @@ def _write_cmake_findpython_wrapper_file(self): def package(self): copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) if is_msvc(self): - if self.options.get_safe("shared"): + if self.options.get_safe("shared", default=True): self._msvc_package_layout() else: self._msvc_package_copy() @@ -822,7 +822,7 @@ def package_info(self): os.path.join("include", f"python{self._version_suffix}{self._abi_suffix}") ) libdir = "lib" - if self.options.get_safe("shared"): + if self.options.get_safe("shared", default=True): self.cpp_info.components["python"].defines.append("Py_ENABLE_SHARED") else: self.cpp_info.components["python"].defines.append("Py_NO_ENABLE_SHARED") From 6d8d46c6c3abe10494f4fa56db94c34e3544df2a Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sat, 12 Oct 2024 20:43:21 +0300 Subject: [PATCH 5/5] cpython: add cross-building support --- recipes/cpython/all/conanfile.py | 16 ++++++++++++++-- recipes/cpython/all/test_package/CMakeLists.txt | 10 +++++++--- recipes/cpython/all/test_package/conanfile.py | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/recipes/cpython/all/conanfile.py b/recipes/cpython/all/conanfile.py index 90a91224e4d5b..6bdd1d4241560 100644 --- a/recipes/cpython/all/conanfile.py +++ b/recipes/cpython/all/conanfile.py @@ -5,12 +5,12 @@ from conan import ConanFile from conan.errors import ConanInvalidConfiguration from conan.tools.apple import is_apple_os, fix_apple_shared_install_name -from conan.tools.build import cross_building +from conan.tools.build import cross_building, can_run from conan.tools.env import VirtualRunEnv from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, load, mkdir, replace_in_file, rm, rmdir, save, unzip from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps, PkgConfigDeps from conan.tools.layout import basic_layout -from conan.tools.microsoft import MSBuildDeps, MSBuildToolchain, MSBuild, is_msvc, is_msvc_static_runtime, msvc_runtime_flag, msvs_toolset +from conan.tools.microsoft import MSBuildDeps, MSBuildToolchain, MSBuild, is_msvc, is_msvc_static_runtime, msvc_runtime_flag, msvs_toolset, unix_path from conan.tools.scm import Version required_conan_version = ">=1.58.0" @@ -116,6 +116,8 @@ def layout(self): def build_requirements(self): if Version(self.version) >= "3.11" and not is_msvc(self) and not self.conf.get("tools.gnu:pkg_config", check_type=str): self.tool_requires("pkgconf/2.1.0") + if not can_run(self) and not is_msvc(self): + self.build_requires(f"cpython/{self.version}") def requirements(self): self.requires("zlib/[>=1.2.11 <2]") @@ -238,6 +240,16 @@ def _generate_autotools(self): if not is_apple_os(self): tc.extra_ldflags.append('-Wl,--as-needed') + if not can_run(self): + build_python = unix_path(self, os.path.join(self.dependencies.build["cpython"].package_folder, "bin", "python")) + tc.configure_args.append(f"--with-build-python={build_python}") + # The following are required only when cross-building, but set for all cases for consistency + tc.configure_args.append("--enable-ipv6") # enabled by default, but skip the check + dev_ptmx_exists = os.path.exists("/dev/ptmx") + dev_ptc_exists = os.path.exists("/dev/ptc") + tc.configure_args.append(f"ac_cv_file__dev_ptmx={yes_no(dev_ptmx_exists)}") + tc.configure_args.append(f"ac_cv_file__dev_ptc={yes_no(dev_ptc_exists)}") + tc.generate() deps = AutotoolsDeps(self) diff --git a/recipes/cpython/all/test_package/CMakeLists.txt b/recipes/cpython/all/test_package/CMakeLists.txt index 68886bdf4d074..e00e444ca5179 100644 --- a/recipes/cpython/all/test_package/CMakeLists.txt +++ b/recipes/cpython/all/test_package/CMakeLists.txt @@ -1,14 +1,18 @@ cmake_minimum_required(VERSION 3.15) project(test_package C) -find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module Development.Embed) +find_package(Python3 REQUIRED COMPONENTS Development.Module Development.Embed) -message("Python3_EXECUTABLE: ${Python3_EXECUTABLE}") -message("Python3_INTERPRETER_ID: ${Python3_INTERPRETER_ID}") message("Python3_VERSION: ${Python3_VERSION}") message("Python3_INCLUDE_DIRS: ${Python3_INCLUDE_DIRS}") message("Python3_LIBRARIES: ${Python3_LIBRARIES}") +if(CAN_RUN) + find_package(Python3 REQUIRED COMPONENTS Interpreter) + message("Python3_EXECUTABLE: ${Python3_EXECUTABLE}") + message("Python3_INTERPRETER_ID: ${Python3_INTERPRETER_ID}") +endif() + option(BUILD_MODULE "Build python module") if(BUILD_MODULE) python3_add_library(spam "test_module.c") diff --git a/recipes/cpython/all/test_package/conanfile.py b/recipes/cpython/all/test_package/conanfile.py index 4d6f067c9bc90..fc89b5a8b1686 100644 --- a/recipes/cpython/all/test_package/conanfile.py +++ b/recipes/cpython/all/test_package/conanfile.py @@ -66,6 +66,7 @@ def _supports_modules(self): def generate(self): tc = CMakeToolchain(self) tc.cache_variables["BUILD_MODULE"] = self._supports_modules + tc.cache_variables["CAN_RUN"] = can_run(self) tc.generate() deps = CMakeDeps(self)