From 721e8f53f6bceeb0ed1b397af5740002838e3aab Mon Sep 17 00:00:00 2001 From: pxin Date: Thu, 21 Feb 2019 11:42:49 +0800 Subject: [PATCH 1/7] enable cpython to cross-build on VxWorks RTOS --- Include/osdefs.h | 4 ++++ configure | 23 ++++++++++++++++++++--- configure.ac | 23 ++++++++++++++++++++--- pyconfig.h.in | 3 +++ setup.py | 39 +++++++++++++++++++++++++++++---------- 5 files changed, 76 insertions(+), 16 deletions(-) diff --git a/Include/osdefs.h b/Include/osdefs.h index bd84c1c12c19fd..3243944a1483e9 100644 --- a/Include/osdefs.h +++ b/Include/osdefs.h @@ -14,6 +14,10 @@ extern "C" { #define DELIM L';' #endif +#ifdef __VXWORKS__ +#define DELIM L';' +#endif + /* Filename separator */ #ifndef SEP #define SEP L'/' diff --git a/configure b/configure index 867e2fc28c4787..40b98eed97b6ce 100755 --- a/configure +++ b/configure @@ -3268,6 +3268,9 @@ then *-*-cygwin*) ac_sys_system=Cygwin ;; + *-*-vxworks*) + ac_sys_system=VxWorks + ;; *) # for now, limit cross builds to known configurations MACHDEP="unknown" @@ -3312,6 +3315,9 @@ if test "$cross_compiling" = yes; then *-*-cygwin*) _host_cpu= ;; + *-*-vxworks*) + _host_cpu=$host_cpu + ;; *) # for now, limit cross builds to known configurations MACHDEP="unknown" @@ -3399,6 +3405,11 @@ $as_echo "#define _BSD_SOURCE 1" >>confdefs.h QNX/6.3.2) define_xopen_source=no ;; + # On VxWorks, defining _XOPEN_SOURCE causes compile failures + # in network headers still using system V types. + VxWorks/*) + define_xopen_source=no + ;; esac @@ -5283,6 +5294,8 @@ cat >> conftest.c <&5 @@ -9530,6 +9545,8 @@ then # to 2048 kilobytes so that the stack doesn't overflow # when running test_compile.py. LINKFORSHARED='-Wl,-E -N 2048K';; + VxWorks*) + LINKFORSHARED='--export-dynamic';; esac fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LINKFORSHARED" >&5 @@ -11459,7 +11476,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy strsignal symlinkat sync \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \ - wcscoll wcsftime wcsxfrm wmemcmp writev _getpty + wcscoll wcsftime wcsxfrm wmemcmp writev _getpty rtpSpawn do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -15079,7 +15096,7 @@ $as_echo "$SOABI" >&6; } case $ac_sys_system in - Linux*|GNU*|Darwin) + Linux*|GNU*|Darwin|VxWorks) EXT_SUFFIX=.${SOABI}${SHLIB_SUFFIX};; *) EXT_SUFFIX=${SHLIB_SUFFIX};; diff --git a/configure.ac b/configure.ac index bb7861bc0daa83..bfc0dd48811cd9 100644 --- a/configure.ac +++ b/configure.ac @@ -379,6 +379,9 @@ then *-*-cygwin*) ac_sys_system=Cygwin ;; + *-*-vxworks*) + ac_sys_system=VxWorks + ;; *) # for now, limit cross builds to known configurations MACHDEP="unknown" @@ -423,6 +426,9 @@ if test "$cross_compiling" = yes; then *-*-cygwin*) _host_cpu= ;; + *-*-vxworks*) + _host_cpu=$host_cpu + ;; *) # for now, limit cross builds to known configurations MACHDEP="unknown" @@ -507,6 +513,11 @@ case $ac_sys_system/$ac_sys_release in QNX/6.3.2) define_xopen_source=no ;; + # On VxWorks, defining _XOPEN_SOURCE causes compile failures + # in network headers still using system V types. + VxWorks/*) + define_xopen_source=no + ;; esac @@ -829,6 +840,8 @@ cat >> conftest.c <%s 1>/dev/null' % (gcc, tmpfile)) is_gcc = False + is_clang = False in_incdirs = False inc_dirs = [] lib_dirs = [] @@ -525,17 +526,19 @@ def add_gcc_paths(self): for line in fp.readlines(): if line.startswith("gcc version"): is_gcc = True + if line.startswith("clang version"): + is_clang = True elif line.startswith("#include <...>"): in_incdirs = True elif line.startswith("End of search list"): in_incdirs = False - elif is_gcc and line.startswith("LIBRARY_PATH"): + elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"): for d in line.strip().split("=")[1].split(":"): d = os.path.normpath(d) if '/gcc/' not in d: add_dir_to_list(self.compiler.library_dirs, d) - elif is_gcc and in_incdirs and '/gcc/' not in line: + elif (is_gcc or is_clang) and in_incdirs and '/gcc/' not in line and '/clang/' not in line: add_dir_to_list(self.compiler.include_dirs, line.strip()) finally: @@ -722,7 +725,8 @@ def detect_modules(self): # pwd(3) exts.append( Extension('pwd', ['pwdmodule.c']) ) # grp(3) - exts.append( Extension('grp', ['grpmodule.c']) ) + if 'vxworks' not in host_platform: + exts.append( Extension('grp', ['grpmodule.c']) ) # spwd, shadow passwords if (config_h_vars.get('HAVE_GETSPNAM', False) or config_h_vars.get('HAVE_GETSPENT', False)): @@ -859,17 +863,31 @@ def detect_modules(self): libs = ['crypt'] else: libs = [] - exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) ) + + if 'vxworks' not in host_platform: + exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) ) + elif self.compiler.find_library_file(lib_dirs, 'OPENSSL'): + libs = ['OPENSSL'] + exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) ) # CSV files exts.append( Extension('_csv', ['_csv.c']) ) # POSIX subprocess module helper. - exts.append( Extension('_posixsubprocess', ['_posixsubprocess.c']) ) + if 'vxworks' in host_platform : + exts.append( Extension('_vxwapi', ['_vxwapi.c']) ) + else: + exts.append( Extension('_posixsubprocess', ['_posixsubprocess.c']) ) # socket(2) - exts.append( Extension('_socket', ['socketmodule.c'], - depends = ['socketmodule.h']) ) + if 'vxworks' not in host_platform : + exts.append( Extension('_socket', ['socketmodule.c'], + depends = ['socketmodule.h']) ) + elif self.compiler.find_library_file(lib_dirs, 'net'): + libs = ['net'] + exts.append( Extension('_socket', ['socketmodule.c'], + depends = ['socketmodule.h'], libraries=libs) ) + # Detect SSL support for the socket module (via _ssl) ssl_ext, hashlib_ext = self._detect_openssl(inc_dirs, lib_dirs) if ssl_ext is not None: @@ -1319,9 +1337,10 @@ class db_found(Exception): pass # Unix-only modules if host_platform != 'win32': - # Steen Lumholt's termios module - exts.append( Extension('termios', ['termios.c']) ) - # Jeremy Hylton's rlimit interface + if 'vxworks' not in host_platform : + # Steen Lumholt's termios module + exts.append( Extension('termios', ['termios.c']) ) + # Jeremy Hylton's rlimit interface exts.append( Extension('resource', ['resource.c']) ) else: missing.extend(['resource', 'termios']) From 09eafcca62445857b0be886d8ab38a4eddb92a27 Mon Sep 17 00:00:00 2001 From: pxin Date: Thu, 21 Feb 2019 15:02:15 +0800 Subject: [PATCH 2/7] add news file for cross-build support on VxWorks --- Misc/NEWS.d/next/Build/2019-02-21-14-48-31.bpo-31904.J82jY2.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Build/2019-02-21-14-48-31.bpo-31904.J82jY2.rst diff --git a/Misc/NEWS.d/next/Build/2019-02-21-14-48-31.bpo-31904.J82jY2.rst b/Misc/NEWS.d/next/Build/2019-02-21-14-48-31.bpo-31904.J82jY2.rst new file mode 100644 index 00000000000000..f54a0faec61259 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2019-02-21-14-48-31.bpo-31904.J82jY2.rst @@ -0,0 +1 @@ +Enable cpython build system to cross-build for VxWorks RTOS. From a59146b2b8f24d20c6b7e395aa805be51483c70f Mon Sep 17 00:00:00 2001 From: pxin Date: Fri, 22 Feb 2019 14:18:41 +0800 Subject: [PATCH 3/7] remove _vxwapi.c from extension module list --- setup.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 8b1a5a571bd317..70657eb4d1d9c4 100644 --- a/setup.py +++ b/setup.py @@ -874,10 +874,7 @@ def detect_modules(self): exts.append( Extension('_csv', ['_csv.c']) ) # POSIX subprocess module helper. - if 'vxworks' in host_platform : - exts.append( Extension('_vxwapi', ['_vxwapi.c']) ) - else: - exts.append( Extension('_posixsubprocess', ['_posixsubprocess.c']) ) + exts.append( Extension('_posixsubprocess', ['_posixsubprocess.c']) ) # socket(2) if 'vxworks' not in host_platform : From e4a6ac681c9a14019f9527c9f4217b9f3832f7c0 Mon Sep 17 00:00:00 2001 From: pxin Date: Mon, 25 Feb 2019 15:59:59 +0800 Subject: [PATCH 4/7] remove rtpSpawn from the library function checklist and regenerate configure --- configure | 2 +- configure.ac | 2 +- pyconfig.h.in | 27 ++++++++++++--------------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/configure b/configure index 40b98eed97b6ce..b0d2be6cb0b84d 100755 --- a/configure +++ b/configure @@ -11476,7 +11476,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy strsignal symlinkat sync \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \ - wcscoll wcsftime wcsxfrm wmemcmp writev _getpty rtpSpawn + wcscoll wcsftime wcsxfrm wmemcmp writev _getpty do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.ac b/configure.ac index bfc0dd48811cd9..ff84a3730e6df4 100644 --- a/configure.ac +++ b/configure.ac @@ -3534,7 +3534,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy strsignal symlinkat sync \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \ - wcscoll wcsftime wcsxfrm wmemcmp writev _getpty rtpSpawn) + wcscoll wcsftime wcsxfrm wmemcmp writev _getpty) # Force lchmod off for Linux. Linux disallows changing the mode of symbolic # links. Some libc implementations have a stub lchmod implementation that always diff --git a/pyconfig.h.in b/pyconfig.h.in index 88a731fb4b638a..d41d57932766be 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -144,18 +144,6 @@ /* Define to 1 if you have the `copysign' function. */ #undef HAVE_COPYSIGN -/* Define to 1 if you must link with -lrt for shm_open(). */ -#undef SHM_NEEDS_LIBRT - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_MMAN_H - -/* Define to 1 if you have the shm_open syscall */ -#undef HAVE_SHM_OPEN - -/* Define to 1 if you have the shm_unlink syscall */ -#undef HAVE_SHM_UNLINK - /* Define to 1 if you have the header file. */ #undef HAVE_CRYPT_H @@ -843,9 +831,6 @@ /* Define to 1 if you have the `round' function. */ #undef HAVE_ROUND -/* Define to 1 if you have the `rtpSpawn' function. */ -#undef HAVE_RTPSPAWN - /* Define to 1 if you have the `sched_get_priority_max' function. */ #undef HAVE_SCHED_GET_PRIORITY_MAX @@ -933,6 +918,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SHADOW_H +/* Define to 1 if you have the `shm_open' function. */ +#undef HAVE_SHM_OPEN + +/* Define to 1 if you have the `shm_unlink' function. */ +#undef HAVE_SHM_UNLINK + /* Define to 1 if you have the `sigaction' function. */ #undef HAVE_SIGACTION @@ -1112,6 +1103,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_MKDEV_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_MMAN_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_MODEM_H @@ -1386,6 +1380,9 @@ /* Define if setpgrp() must be called as setpgrp(0, 0). */ #undef SETPGRP_HAVE_ARG +/* Define to 1 if you must link with -lrt for shm_open(). */ +#undef SHM_NEEDS_LIBRT + /* Define if i>>j for signed int i does not extend the sign bit when i < 0 */ #undef SIGNED_RIGHT_SHIFT_ZERO_FILLS From a42825ec58785facef60aa2a86b1ce972903b557 Mon Sep 17 00:00:00 2001 From: pxin Date: Tue, 26 Feb 2019 14:42:22 +0800 Subject: [PATCH 5/7] clean up setup.py --- setup.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index 70657eb4d1d9c4..446b4e86135917 100644 --- a/setup.py +++ b/setup.py @@ -44,6 +44,8 @@ def get_platform(): return sys.platform host_platform = get_platform() +_vxworks = ('vxworks' in host_platform) + # Were we compiled --with-pydebug or with #define Py_DEBUG? COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS")) @@ -509,12 +511,12 @@ def add_multiarch_paths(self): finally: os.unlink(tmpfile) - def add_gcc_paths(self): - gcc = sysconfig.get_config_var('CC') - tmpfile = os.path.join(self.build_temp, 'gccpaths') + def add_cross_compiling_paths(self): + cc = sysconfig.get_config_var('CC') + tmpfile = os.path.join(self.build_temp, 'ccpaths') if not os.path.exists(self.build_temp): os.makedirs(self.build_temp) - ret = os.system('%s -E -v - %s 1>/dev/null' % (gcc, tmpfile)) + ret = os.system('%s -E -v - %s 1>/dev/null' % (cc, tmpfile)) is_gcc = False is_clang = False in_incdirs = False @@ -526,7 +528,7 @@ def add_gcc_paths(self): for line in fp.readlines(): if line.startswith("gcc version"): is_gcc = True - if line.startswith("clang version"): + elif line.startswith("clang version"): is_clang = True elif line.startswith("#include <...>"): in_incdirs = True @@ -553,7 +555,7 @@ def detect_modules(self): add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') # only change this for cross builds for 3.3, issues on Mageia if cross_compiling: - self.add_gcc_paths() + self.add_cross_compiling_paths() self.add_multiarch_paths() # Add paths specified in the environment variables LDFLAGS and @@ -725,7 +727,7 @@ def detect_modules(self): # pwd(3) exts.append( Extension('pwd', ['pwdmodule.c']) ) # grp(3) - if 'vxworks' not in host_platform: + if not _vxworks: exts.append( Extension('grp', ['grpmodule.c']) ) # spwd, shadow passwords if (config_h_vars.get('HAVE_GETSPNAM', False) or @@ -864,7 +866,7 @@ def detect_modules(self): else: libs = [] - if 'vxworks' not in host_platform: + if not _vxworks: exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) ) elif self.compiler.find_library_file(lib_dirs, 'OPENSSL'): libs = ['OPENSSL'] @@ -877,7 +879,7 @@ def detect_modules(self): exts.append( Extension('_posixsubprocess', ['_posixsubprocess.c']) ) # socket(2) - if 'vxworks' not in host_platform : + if not _vxworks: exts.append( Extension('_socket', ['socketmodule.c'], depends = ['socketmodule.h']) ) elif self.compiler.find_library_file(lib_dirs, 'net'): @@ -1334,7 +1336,7 @@ class db_found(Exception): pass # Unix-only modules if host_platform != 'win32': - if 'vxworks' not in host_platform : + if not _vxworks: # Steen Lumholt's termios module exts.append( Extension('termios', ['termios.c']) ) # Jeremy Hylton's rlimit interface From 694f01d4b6232a35cfd1d2de653bc69b327eb1c2 Mon Sep 17 00:00:00 2001 From: pxin Date: Wed, 27 Feb 2019 15:31:29 +0800 Subject: [PATCH 6/7] rename _vxworks to VXWORKS in setup.py --- setup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 446b4e86135917..bf593b7b9292f8 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,7 @@ def get_platform(): return sys.platform host_platform = get_platform() -_vxworks = ('vxworks' in host_platform) +VXWORKS = ('vxworks' in host_platform) # Were we compiled --with-pydebug or with #define Py_DEBUG? COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS")) @@ -727,7 +727,7 @@ def detect_modules(self): # pwd(3) exts.append( Extension('pwd', ['pwdmodule.c']) ) # grp(3) - if not _vxworks: + if not VXWORKS: exts.append( Extension('grp', ['grpmodule.c']) ) # spwd, shadow passwords if (config_h_vars.get('HAVE_GETSPNAM', False) or @@ -866,7 +866,7 @@ def detect_modules(self): else: libs = [] - if not _vxworks: + if not VXWORKS: exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) ) elif self.compiler.find_library_file(lib_dirs, 'OPENSSL'): libs = ['OPENSSL'] @@ -879,7 +879,7 @@ def detect_modules(self): exts.append( Extension('_posixsubprocess', ['_posixsubprocess.c']) ) # socket(2) - if not _vxworks: + if not VXWORKS: exts.append( Extension('_socket', ['socketmodule.c'], depends = ['socketmodule.h']) ) elif self.compiler.find_library_file(lib_dirs, 'net'): @@ -1336,7 +1336,7 @@ class db_found(Exception): pass # Unix-only modules if host_platform != 'win32': - if not _vxworks: + if not VXWORKS: # Steen Lumholt's termios module exts.append( Extension('termios', ['termios.c']) ) # Jeremy Hylton's rlimit interface From 156d8e60307932114b3e71ba79131d789735c141 Mon Sep 17 00:00:00 2001 From: pxin Date: Wed, 27 Feb 2019 15:33:49 +0800 Subject: [PATCH 7/7] refine the news text --- Misc/NEWS.d/next/Build/2019-02-21-14-48-31.bpo-31904.J82jY2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Build/2019-02-21-14-48-31.bpo-31904.J82jY2.rst b/Misc/NEWS.d/next/Build/2019-02-21-14-48-31.bpo-31904.J82jY2.rst index f54a0faec61259..1292193b729c4a 100644 --- a/Misc/NEWS.d/next/Build/2019-02-21-14-48-31.bpo-31904.J82jY2.rst +++ b/Misc/NEWS.d/next/Build/2019-02-21-14-48-31.bpo-31904.J82jY2.rst @@ -1 +1 @@ -Enable cpython build system to cross-build for VxWorks RTOS. +Enable build system to cross-build for VxWorks RTOS.