From 041ac36df950bf19e3476a09e2c2a455bfd03353 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Sun, 12 Jun 2022 13:46:36 +0800 Subject: [PATCH] fix build failure on python3.10 Signed-off-by: Zhipeng Xie --- ...ctions-has-no-attribute-MutableSeque.patch | 26 ++++++++++ ...-to-cope-with-const-ness-change-of-N.patch | 48 +++++++++++++++++++ ...s-is-deprecated-in-Python-3.10-51776.patch | 30 ++++++++++++ tensorflow.spec | 10 +++- 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 0001-Fix-module-collections-has-no-attribute-MutableSeque.patch create mode 100644 0001-Provide-overload-to-cope-with-const-ness-change-of-N.patch create mode 100644 0001-distutils-is-deprecated-in-Python-3.10-51776.patch diff --git a/0001-Fix-module-collections-has-no-attribute-MutableSeque.patch b/0001-Fix-module-collections-has-no-attribute-MutableSeque.patch new file mode 100644 index 0000000..2508899 --- /dev/null +++ b/0001-Fix-module-collections-has-no-attribute-MutableSeque.patch @@ -0,0 +1,26 @@ +From 4a8f3c9bd69320359d3b7f83f8849d54d8b68f94 Mon Sep 17 00:00:00 2001 +From: Zhipeng Xie +Date: Sun, 12 Jun 2022 23:14:49 +0800 +Subject: [PATCH] Fix module 'collections' has no attribute 'MutableSequence' + +Signed-off-by: Zhipeng Xie +--- + com_google_protobuf/python/google/protobuf/pyext/message.cc | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/com_google_protobuf/python/google/protobuf/pyext/message.cc b/com_google_protobuf/python/google/protobuf/pyext/message.cc +index 3530a9b37..1c4f33fcd 100755 +--- a/com_google_protobuf/python/google/protobuf/pyext/message.cc ++++ b/com_google_protobuf/python/google/protobuf/pyext/message.cc +@@ -2992,7 +2992,7 @@ bool InitProto2MessageModule(PyObject *m) { + &RepeatedCompositeContainer_Type)); + + // Register them as collections.Sequence +- ScopedPyObjectPtr collections(PyImport_ImportModule("collections")); ++ ScopedPyObjectPtr collections(PyImport_ImportModule("collections.abc")); + if (collections == NULL) { + return false; + } +-- +2.27.0 + diff --git a/0001-Provide-overload-to-cope-with-const-ness-change-of-N.patch b/0001-Provide-overload-to-cope-with-const-ness-change-of-N.patch new file mode 100644 index 0000000..b92e410 --- /dev/null +++ b/0001-Provide-overload-to-cope-with-const-ness-change-of-N.patch @@ -0,0 +1,48 @@ +From 75ea0b31477d6ba9e990e296bbbd8ca4e7eebadf Mon Sep 17 00:00:00 2001 +From: Christian Sigg +Date: Fri, 26 Jun 2020 05:08:10 -0700 +Subject: [PATCH] Provide overload to cope with const-ness change of NumPy's + PyUFuncGenericFunction. + +See https://github.com/tensorflow/tensorflow/issues/40688, https://github.com/tensorflow/tensorflow/pull/40654. + +PiperOrigin-RevId: 318452381 +Change-Id: Icc5152f2b020ef19882a49e3c86ac80bbe048d64 +--- + tensorflow/python/lib/core/bfloat16.cc | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/tensorflow/python/lib/core/bfloat16.cc b/tensorflow/python/lib/core/bfloat16.cc +index feb01f11a1a..bb6b720febe 100644 +--- a/tensorflow/python/lib/core/bfloat16.cc ++++ b/tensorflow/python/lib/core/bfloat16.cc +@@ -517,7 +517,7 @@ bool RegisterBfloat16Cast(int numpy_type, bool cast_is_safe) { + } + + template +-void BinaryUFunc(char** args, npy_intp* dimensions, npy_intp* steps, ++void BinaryUFunc(char** args, const npy_intp* dimensions, const npy_intp* steps, + void* data) { + const char* i0 = args[0]; + const char* i1 = args[1]; +@@ -532,11 +532,17 @@ void BinaryUFunc(char** args, npy_intp* dimensions, npy_intp* steps, + } + } + ++// Numpy changed const-ness of PyUFuncGenericFunction, provide overload. + template + void CompareUFunc(char** args, npy_intp* dimensions, npy_intp* steps, + void* data) { + BinaryUFunc(args, dimensions, steps, data); + } ++template ++void CompareUFunc(char** args, const npy_intp* dimensions, ++ const npy_intp* steps, void* data) { ++ BinaryUFunc(args, dimensions, steps, data); ++} + + struct Bfloat16EqFunctor { + npy_bool operator()(bfloat16 a, bfloat16 b) { return a == b; } +-- +2.27.0 + diff --git a/0001-distutils-is-deprecated-in-Python-3.10-51776.patch b/0001-distutils-is-deprecated-in-Python-3.10-51776.patch new file mode 100644 index 0000000..4452842 --- /dev/null +++ b/0001-distutils-is-deprecated-in-Python-3.10-51776.patch @@ -0,0 +1,30 @@ +From 178fa5e11b78cf0900ab4a42a81807858c6a1f15 Mon Sep 17 00:00:00 2001 +From: KumaTea +Date: Wed, 1 Sep 2021 18:31:38 +0800 +Subject: [PATCH] `distutils` is deprecated in Python 3.10 #51776 + +The `distutils` is deprecated in Python 3.10. + +As of #51776, In `python_configure.bzl`, the deprecation message will be printed prior to the include path, causing error on return. +--- + third_party/py/python_configure.bzl | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/third_party/py/python_configure.bzl b/third_party/py/python_configure.bzl +index 2f75262ea9f..b41f422e9bd 100644 +--- a/third_party/py/python_configure.bzl ++++ b/third_party/py/python_configure.bzl +@@ -155,8 +155,8 @@ def _get_python_include(repository_ctx, python_bin): + python_bin, + "-c", + "from __future__ import print_function;" + +- "from distutils import sysconfig;" + +- "print(sysconfig.get_python_inc())", ++ "import sysconfig;" + ++ "print(sysconfig.get_path('include'))", + ], + error_msg = "Problem getting python include path.", + error_details = ("Is the Python binary path set up right? " + +-- +2.27.0 + diff --git a/tensorflow.spec b/tensorflow.spec index b77f7e0..5da9a4a 100644 --- a/tensorflow.spec +++ b/tensorflow.spec @@ -1,13 +1,14 @@ %global _empty_manifest_terminate_build 0 Name: tensorflow Version: 2.3.1 -Release: 13 +Release: 14 Summary: An Open Source Machine Learning Framework for Everyone License: Apache License 2.0 URL: https://www.tensorflow.org/ Source0: https://github.com/tensorflow/tensorflow/archive/v%{version}.tar.gz#/tensorflow-%{version}.tar.gz #sh -x updateSource1.sh Source1: external-%{_arch}.tar.bz2 +Source2: 0001-Fix-module-collections-has-no-attribute-MutableSeque.patch Patch0001: 0001-Add-arm-source-file-into-aws-checksums.patch Patch0002: CVE-2021-29538.patch @@ -191,6 +192,9 @@ Patch0179: CVE-2021-37690-3.patch Patch0180: CVE-2021-41210.patch Patch0181: CVE-2021-41219.patch Patch0182: CVE-2021-41223.patch +Patch0183: 0001-distutils-is-deprecated-in-Python-3.10-51776.patch +Patch0184: 0001-Provide-overload-to-cope-with-const-ness-change-of-N.patch + Requires: python3-future Requires: python3-numpy @@ -221,6 +225,7 @@ TensorFlow provides stable Python and C++ APIs, as well as non-guaranteed backwa extdir=$(bazel --output_user_root=`pwd`/../output_user_root info output_base) mkdir -p ${extdir} tar xf %{SOURCE1} -C ${extdir} +patch -p1 -d ${extdir}/external < %{SOURCE2} ln -sfn $(find ${extdir}/../install -name embedded_tools) ${extdir}/external/bazel_tools ln -sfn $(find ${extdir}/../install -maxdepth 2 -name platforms) ${extdir}/external/platforms rm -rf ${extdir}/external/local_config* @@ -237,6 +242,9 @@ bazel --output_user_root=`pwd`/../output_user_root build --host_copt=-Wno-string %{_bindir}/* %changelog +* Sun Jun 12 2022 Zhipeng Xie - 2.3.1-14 +- backport patch to fix build failure on python3.10 + * Wed Nov 10 2021 houyingchao - 2.3.1-13 - Fix CVE-2021-41210 CVE-2021-41219 CVE-2021-41223 -- Gitee