[Bf-blender-cvs] [fb94343f128] mac_arm64: macOS: Enabled ctypes, numpy, etc on arm64.

Stefan Werner noreply at git.blender.org
Tue Jul 14 10:31:54 CEST 2020


Commit: fb94343f12854235f350a806379a209e107d8231
Author: Stefan Werner
Date:   Tue Jul 14 10:30:39 2020 +0200
Branches: mac_arm64
https://developer.blender.org/rBfb94343f12854235f350a806379a209e107d8231

macOS: Enabled ctypes, numpy, etc on arm64.

This is a backport of the PR for getting the latest Python to macOS/arm64:
https://github.com/python/cpython/pull/21249

===================================================================

M	build_files/build_environment/CMakeLists.txt
M	build_files/build_environment/cmake/numpy.cmake
M	build_files/build_environment/cmake/python.cmake
A	build_files/build_environment/patches/numpy.diff
M	build_files/build_environment/patches/python_linux.diff
A	build_files/build_environment/patches/python_macos.diff
M	build_files/cmake/platform/platform_apple.cmake

===================================================================

diff --git a/build_files/build_environment/CMakeLists.txt b/build_files/build_environment/CMakeLists.txt
index d1c71230779..276311fe2d8 100644
--- a/build_files/build_environment/CMakeLists.txt
+++ b/build_files/build_environment/CMakeLists.txt
@@ -85,12 +85,9 @@ include(cmake/osl.cmake)
 include(cmake/tbb.cmake)
 include(cmake/openvdb.cmake)
 include(cmake/python.cmake)
-# Temporarily disabled until we get a full python building on macOS/arm64
-if((NOT APPLE) OR ("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64"))
-  include(cmake/python_site_packages.cmake)
-  include(cmake/package_python.cmake)
-  include(cmake/numpy.cmake)
-endif()
+include(cmake/python_site_packages.cmake)
+include(cmake/package_python.cmake)
+include(cmake/numpy.cmake)
 include(cmake/usd.cmake)
 if(UNIX)
   # Rely on PugiXML compiled with OpenImageIO
diff --git a/build_files/build_environment/cmake/numpy.cmake b/build_files/build_environment/cmake/numpy.cmake
index abf2464e88c..03316a8fc63 100644
--- a/build_files/build_environment/cmake/numpy.cmake
+++ b/build_files/build_environment/cmake/numpy.cmake
@@ -38,6 +38,7 @@ ExternalProject_Add(external_numpy
   PREFIX ${BUILD_DIR}/numpy
   PATCH_COMMAND ${NUMPY_PATCH}
   CONFIGURE_COMMAND ""
+  PATCH_COMMAND COMMAND ${PATCH_CMD} -p 1 -d ${BUILD_DIR}/numpy/src/external_numpy < ${PATCH_DIR}/numpy.diff
   LOG_BUILD 1
   BUILD_COMMAND ${PYTHON_BINARY} ${BUILD_DIR}/numpy/src/external_numpy/setup.py build ${NUMPY_BUILD_OPTION} install --old-and-unmanageable
   INSTALL_COMMAND ""
diff --git a/build_files/build_environment/cmake/python.cmake b/build_files/build_environment/cmake/python.cmake
index e852d2c1d09..9cd56423941 100644
--- a/build_files/build_environment/cmake/python.cmake
+++ b/build_files/build_environment/cmake/python.cmake
@@ -74,10 +74,12 @@ else()
     endif()
     set(PYTHON_CONFIGURE_ENV ${CONFIGURE_ENV} && ${PYTHON_FUNC_CONFIGS})
     set(PYTHON_BINARY ${BUILD_DIR}/python/src/external_python/python.exe)
+    set(PYTHON_PATCH ${PATCH_CMD} --verbose -p1 -d ${BUILD_DIR}/python/src/external_python < ${PATCH_DIR}/python_macos.diff)
   else()
     set(PYTHON_CONFIGURE_ENV ${CONFIGURE_ENV})
     set(PYTHON_BINARY ${BUILD_DIR}/python/src/external_python/python)
-  endif()
+    set(PYTHON_PATCH ${PATCH_CMD} --verbose -p1 -d ${BUILD_DIR}/python/src/external_python < ${PATCH_DIR}/python_linux.diff)
+ endif()
 
   set(PYTHON_CONFIGURE_EXTRA_ARGS "--with-openssl=${LIBDIR}/ssl")
   set(PYTHON_CFLAGS "-I${LIBDIR}/sqlite/include -I${LIBDIR}/bzip2/include -I${LIBDIR}/lzma/include -I${LIBDIR}/zlib/include")
@@ -87,7 +89,6 @@ else()
     export CPPFLAGS=${PYTHON_CFLAGS} &&
     export LDFLAGS=${PYTHON_LDFLAGS} &&
     export PKG_CONFIG_PATH=${LIBDIR}/ffi/lib/pkgconfig)
-  set(PYTHON_PATCH ${PATCH_CMD} --verbose -p1 -d ${BUILD_DIR}/python/src/external_python < ${PATCH_DIR}/python_linux.diff)
 
   ExternalProject_Add(external_python
     URL ${PYTHON_URI}
diff --git a/build_files/build_environment/patches/numpy.diff b/build_files/build_environment/patches/numpy.diff
new file mode 100644
index 00000000000..a9b783dd856
--- /dev/null
+++ b/build_files/build_environment/patches/numpy.diff
@@ -0,0 +1,27 @@
+diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py
+index ba2b1f4..b10f7df 100644
+--- a/numpy/distutils/system_info.py
++++ b/numpy/distutils/system_info.py
+@@ -2164,8 +2164,8 @@ class accelerate_info(system_info):
+                     'accelerate' in libraries):
+                 if intel:
+                     args.extend(['-msse3'])
+-                else:
+-                    args.extend(['-faltivec'])
++#                else:
++#                    args.extend(['-faltivec'])
+                 args.extend([
+                     '-I/System/Library/Frameworks/vecLib.framework/Headers'])
+                 link_args.extend(['-Wl,-framework', '-Wl,Accelerate'])
+@@ -2174,8 +2174,8 @@ class accelerate_info(system_info):
+                       'veclib' in libraries):
+                 if intel:
+                     args.extend(['-msse3'])
+-                else:
+-                    args.extend(['-faltivec'])
++#                else:
++#                    args.extend(['-faltivec'])
+                 args.extend([
+                     '-I/System/Library/Frameworks/vecLib.framework/Headers'])
+                 link_args.extend(['-Wl,-framework', '-Wl,vecLib'])
+
diff --git a/build_files/build_environment/patches/python_linux.diff b/build_files/build_environment/patches/python_linux.diff
index 8d1c250f1ca..24d625c7ceb 100644
--- a/build_files/build_environment/patches/python_linux.diff
+++ b/build_files/build_environment/patches/python_linux.diff
@@ -1,42 +1,8 @@
-diff -ru external_python_orig/configure external_python/configure
---- external_python_orig/configure	2020-03-10 07:11:12.000000000 +0100
-+++ external_python/configure	2020-07-10 00:31:38.000000000 +0200
-@@ -3374,7 +3374,7 @@
-   # has no effect, don't bother defining them
-   Darwin/[6789].*)
-     define_xopen_source=no;;
--  Darwin/1[0-9].*)
-+  Darwin/[12][0-9].*)
-     define_xopen_source=no;;
-   # On AIX 4 and 5.1, mbstate_t is defined only when _XOPEN_SOURCE == 500 but
-   # used in wcsnrtombs() and mbsnrtowcs() even if _XOPEN_SOURCE is not defined
-@@ -9251,6 +9251,9 @@
-     	ppc)
-     		MACOSX_DEFAULT_ARCH="ppc64"
-     		;;
-+        arm64)
-+            MACOSX_DEFAULT_ARCH="arm64"
-+            ;;
-     	*)
-     		as_fn_error $? "Unexpected output of 'arch' on OSX" "$LINENO" 5
-     		;;
-diff -ru external_python_orig/configure.ac external_python/configure.ac
---- external_python_orig/configure.ac	2020-03-10 07:11:12.000000000 +0100
-+++ external_python/configure.ac	2020-07-10 00:33:49.000000000 +0200
-@@ -2456,6 +2456,9 @@
-     	ppc)
-     		MACOSX_DEFAULT_ARCH="ppc64"
-     		;;
-+        arm64)
-+            MACOSX_DEFAULT_ARCH="arm64"
-+            ;;
-     	*)
-     		AC_MSG_ERROR([Unexpected output of 'arch' on OSX])
-     		;;
-diff -ru external_python_orig/setup.py external_python/setup.py
---- external_python_orig/setup.py	2020-03-10 07:11:12.000000000 +0100
-+++ external_python/setup.py	2020-07-10 00:29:49.000000000 +0200
-@@ -1466,13 +1466,13 @@
+diff --git a/setup.py.orig b/setup.py
+index a97a755..07ce853 100644
+--- a/setup.py.orig
++++ b/setup.py
+@@ -1422,13 +1422,13 @@ class PyBuildExt(build_ext):
                          version = line.split()[2]
                          break
              if version >= version_req:
@@ -52,7 +18,7 @@ diff -ru external_python_orig/setup.py external_python/setup.py
                                             extra_link_args = zlib_extra_link_args))
                      have_zlib = True
                  else:
-@@ -1486,7 +1486,7 @@
+@@ -1442,7 +1442,7 @@ class PyBuildExt(build_ext):
          # crc32 if we have it.  Otherwise binascii uses its own.
          if have_zlib:
              extra_compile_args = ['-DUSE_ZLIB_CRC32']
@@ -61,7 +27,7 @@ diff -ru external_python_orig/setup.py external_python/setup.py
              extra_link_args = zlib_extra_link_args
          else:
              extra_compile_args = []
-@@ -2035,7 +2035,7 @@
+@@ -1991,7 +1991,7 @@ class PyBuildExt(build_ext):
                  print('Header file {} does not exist'.format(ffi_h))
          ffi_lib = None
          if ffi_inc is not None:
diff --git a/build_files/build_environment/patches/python_macos.diff b/build_files/build_environment/patches/python_macos.diff
new file mode 100644
index 00000000000..22ccbebee2f
--- /dev/null
+++ b/build_files/build_environment/patches/python_macos.diff
@@ -0,0 +1,289 @@
+diff -ru a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst
+--- a/Doc/library/ctypes.rst	2020-03-10 07:11:12.000000000 +0100
++++ b/Doc/library/ctypes.rst	2020-07-14 08:10:10.000000000 +0200
+@@ -1551,6 +1551,13 @@
+       value usable as argument (integer, string, ctypes instance).  This allows
+       defining adapters that can adapt custom objects as function parameters.
+ 
++   .. attribute:: variadic
++
++      Assign a boolean to specify that the function takes a variable number of
++      arguments.   This does not matter on most platforms, but for Apple arm64
++      platforms variadic functions have a different calling convention than
++      normal functions.
++
+    .. attribute:: errcheck
+ 
+       Assign a Python function or another callable to this attribute. The
+diff -ru a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
+--- a/Modules/_ctypes/_ctypes.c	2020-03-10 07:11:12.000000000 +0100
++++ b/Modules/_ctypes/_ctypes.c	2020-07-14 08:14:41.000000000 +0200
+@@ -3175,6 +3175,35 @@
+ }
+ 
+ static int
++PyCFuncPtr_set_variadic(PyCFuncPtrObject *self, PyObject *ob, void *Py_UNUSED(ignored))
++{
++    StgDictObject *dict = PyObject_stgdict((PyObject *)self);
++    assert(dict);
++    int r = PyObject_IsTrue(ob);
++    if (r == 1) {
++        dict->flags |= FUNCFLAG_VARIADIC;
++        return 0;
++    } else if (r == 0) {
++        dict->flags &= ~FUNCFLAG_VARIADIC;
++        return 0;
++    } else {
++        return -1;
++    }
++}
++
++static PyObject *
++PyCFuncPtr_get_variadic(PyCFuncPtrObject *self, void *Py_UNUSED(ignored))
++{
++    StgDictObject *dict = PyObject_stgdict((PyObject *)self);
++    assert(dict); /* Cannot be NULL for PyCFuncPtrObject instances */
++    if (dict->flags & FUNCFLAG_VARIADIC)
++        Py_RETURN_TRUE;
++    else
++        Py_RETURN_FALSE;
++}
++
++
++static int
+ PyCFuncPtr_set_argtypes(PyCFuncPtrObject *self, PyObject *ob, void *Py_UNUSED(ignored))
+ {
+     PyObject *converters;
+@@ -5632,6 +5661,7 @@
+     PyModule_AddObject(m, "FUNCFLAG_USE_ERRNO", PyLong_FromLong(FUNCFLAG_USE_ERRNO));
+     PyModule_AddObject(m, "FUNCFLAG_USE_LASTERROR", PyLong_FromLong(FUNCFLAG_USE_LASTERROR));
+     PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyLong_FromLong(FUNCFLAG_PYTHONAPI));
++    PyModule_AddObject(m, "FUNCFLAG_VARIADIC", PyLong_FromLong(FUNCFLAG_VARIADIC));
+     PyModule_AddStringConstant(m, "__version__", "1.1.0");
+ 
+     PyModule_AddObject(m, "_memmove_addr", PyLong_FromVoidPtr(memmove));
+diff -ru a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
+--- a/Modules/_ctypes/callproc.c	2020-03-10 07:11:12.000000000 +0100
++++ b/Modules/_ctypes/cal

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list