Skip to content

Commit 32f5fdd

Browse files
pxinwrvstinner
authored andcommitted
bpo-31904: Add cross-build support for VxWorks RTOS (GH-11968)
1 parent 53b9e1a commit 32f5fdd

File tree

5 files changed

+75
-18
lines changed

5 files changed

+75
-18
lines changed

Include/osdefs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ extern "C" {
1414
#define DELIM L';'
1515
#endif
1616

17+
#ifdef __VXWORKS__
18+
#define DELIM L';'
19+
#endif
20+
1721
/* Filename separator */
1822
#ifndef SEP
1923
#define SEP L'/'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enable build system to cross-build for VxWorks RTOS.

configure

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3268,6 +3268,9 @@ then
32683268
*-*-cygwin*)
32693269
ac_sys_system=Cygwin
32703270
;;
3271+
*-*-vxworks*)
3272+
ac_sys_system=VxWorks
3273+
;;
32713274
*)
32723275
# for now, limit cross builds to known configurations
32733276
MACHDEP="unknown"
@@ -3312,6 +3315,9 @@ if test "$cross_compiling" = yes; then
33123315
*-*-cygwin*)
33133316
_host_cpu=
33143317
;;
3318+
*-*-vxworks*)
3319+
_host_cpu=$host_cpu
3320+
;;
33153321
*)
33163322
# for now, limit cross builds to known configurations
33173323
MACHDEP="unknown"
@@ -3399,6 +3405,11 @@ $as_echo "#define _BSD_SOURCE 1" >>confdefs.h
33993405
QNX/6.3.2)
34003406
define_xopen_source=no
34013407
;;
3408+
# On VxWorks, defining _XOPEN_SOURCE causes compile failures
3409+
# in network headers still using system V types.
3410+
VxWorks/*)
3411+
define_xopen_source=no
3412+
;;
34023413

34033414
esac
34043415

@@ -5283,6 +5294,8 @@ cat >> conftest.c <<EOF
52835294
i386-gnu
52845295
#elif defined(__APPLE__)
52855296
darwin
5297+
#elif defined(__VXWORKS__)
5298+
vxworks
52865299
#else
52875300
# error unknown platform triplet
52885301
#endif
@@ -9391,7 +9404,7 @@ then
93919404
BLDSHARED="$LDSHARED"
93929405
fi
93939406
;;
9394-
Linux*|GNU*|QNX*)
9407+
Linux*|GNU*|QNX*|VxWorks*)
93959408
LDSHARED='$(CC) -shared'
93969409
LDCXXSHARED='$(CXX) -shared';;
93979410
FreeBSD*)
@@ -9472,6 +9485,8 @@ then
94729485
then CCSHARED="-fPIC"
94739486
else CCSHARED="-Kpic -belf"
94749487
fi;;
9488+
VxWorks*)
9489+
CCSHARED="-fpic -D__SO_PICABILINUX__ -ftls-model=global-dynamic"
94759490
esac
94769491
fi
94779492
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CCSHARED" >&5
@@ -9530,6 +9545,8 @@ then
95309545
# to 2048 kilobytes so that the stack doesn't overflow
95319546
# when running test_compile.py.
95329547
LINKFORSHARED='-Wl,-E -N 2048K';;
9548+
VxWorks*)
9549+
LINKFORSHARED='--export-dynamic';;
95339550
esac
95349551
fi
95359552
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LINKFORSHARED" >&5
@@ -15079,7 +15096,7 @@ $as_echo "$SOABI" >&6; }
1507915096

1508015097

1508115098
case $ac_sys_system in
15082-
Linux*|GNU*|Darwin)
15099+
Linux*|GNU*|Darwin|VxWorks)
1508315100
EXT_SUFFIX=.${SOABI}${SHLIB_SUFFIX};;
1508415101
*)
1508515102
EXT_SUFFIX=${SHLIB_SUFFIX};;

configure.ac

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ then
379379
*-*-cygwin*)
380380
ac_sys_system=Cygwin
381381
;;
382+
*-*-vxworks*)
383+
ac_sys_system=VxWorks
384+
;;
382385
*)
383386
# for now, limit cross builds to known configurations
384387
MACHDEP="unknown"
@@ -423,6 +426,9 @@ if test "$cross_compiling" = yes; then
423426
*-*-cygwin*)
424427
_host_cpu=
425428
;;
429+
*-*-vxworks*)
430+
_host_cpu=$host_cpu
431+
;;
426432
*)
427433
# for now, limit cross builds to known configurations
428434
MACHDEP="unknown"
@@ -507,6 +513,11 @@ case $ac_sys_system/$ac_sys_release in
507513
QNX/6.3.2)
508514
define_xopen_source=no
509515
;;
516+
# On VxWorks, defining _XOPEN_SOURCE causes compile failures
517+
# in network headers still using system V types.
518+
VxWorks/*)
519+
define_xopen_source=no
520+
;;
510521

511522
esac
512523

@@ -829,6 +840,8 @@ cat >> conftest.c <<EOF
829840
i386-gnu
830841
#elif defined(__APPLE__)
831842
darwin
843+
#elif defined(__VXWORKS__)
844+
vxworks
832845
#else
833846
# error unknown platform triplet
834847
#endif
@@ -2555,7 +2568,7 @@ then
25552568
BLDSHARED="$LDSHARED"
25562569
fi
25572570
;;
2558-
Linux*|GNU*|QNX*)
2571+
Linux*|GNU*|QNX*|VxWorks*)
25592572
LDSHARED='$(CC) -shared'
25602573
LDCXXSHARED='$(CXX) -shared';;
25612574
FreeBSD*)
@@ -2634,6 +2647,8 @@ then
26342647
then CCSHARED="-fPIC"
26352648
else CCSHARED="-Kpic -belf"
26362649
fi;;
2650+
VxWorks*)
2651+
CCSHARED="-fpic -D__SO_PICABILINUX__ -ftls-model=global-dynamic"
26372652
esac
26382653
fi
26392654
AC_MSG_RESULT($CCSHARED)
@@ -2690,6 +2705,8 @@ then
26902705
# to 2048 kilobytes so that the stack doesn't overflow
26912706
# when running test_compile.py.
26922707
LINKFORSHARED='-Wl,-E -N 2048K';;
2708+
VxWorks*)
2709+
LINKFORSHARED='--export-dynamic';;
26932710
esac
26942711
fi
26952712
AC_MSG_RESULT($LINKFORSHARED)
@@ -4578,7 +4595,7 @@ AC_MSG_RESULT($SOABI)
45784595

45794596
AC_SUBST(EXT_SUFFIX)
45804597
case $ac_sys_system in
4581-
Linux*|GNU*|Darwin)
4598+
Linux*|GNU*|Darwin|VxWorks)
45824599
EXT_SUFFIX=.${SOABI}${SHLIB_SUFFIX};;
45834600
*)
45844601
EXT_SUFFIX=${SHLIB_SUFFIX};;

setup.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def get_platform():
4444
return sys.platform
4545
host_platform = get_platform()
4646

47+
VXWORKS = ('vxworks' in host_platform)
48+
4749
# Were we compiled --with-pydebug or with #define Py_DEBUG?
4850
COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS"))
4951

@@ -509,13 +511,14 @@ def add_multiarch_paths(self):
509511
finally:
510512
os.unlink(tmpfile)
511513

512-
def add_gcc_paths(self):
513-
gcc = sysconfig.get_config_var('CC')
514-
tmpfile = os.path.join(self.build_temp, 'gccpaths')
514+
def add_cross_compiling_paths(self):
515+
cc = sysconfig.get_config_var('CC')
516+
tmpfile = os.path.join(self.build_temp, 'ccpaths')
515517
if not os.path.exists(self.build_temp):
516518
os.makedirs(self.build_temp)
517-
ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (gcc, tmpfile))
519+
ret = os.system('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
518520
is_gcc = False
521+
is_clang = False
519522
in_incdirs = False
520523
inc_dirs = []
521524
lib_dirs = []
@@ -525,17 +528,19 @@ def add_gcc_paths(self):
525528
for line in fp.readlines():
526529
if line.startswith("gcc version"):
527530
is_gcc = True
531+
elif line.startswith("clang version"):
532+
is_clang = True
528533
elif line.startswith("#include <...>"):
529534
in_incdirs = True
530535
elif line.startswith("End of search list"):
531536
in_incdirs = False
532-
elif is_gcc and line.startswith("LIBRARY_PATH"):
537+
elif (is_gcc or is_clang) and line.startswith("LIBRARY_PATH"):
533538
for d in line.strip().split("=")[1].split(":"):
534539
d = os.path.normpath(d)
535540
if '/gcc/' not in d:
536541
add_dir_to_list(self.compiler.library_dirs,
537542
d)
538-
elif is_gcc and in_incdirs and '/gcc/' not in line:
543+
elif (is_gcc or is_clang) and in_incdirs and '/gcc/' not in line and '/clang/' not in line:
539544
add_dir_to_list(self.compiler.include_dirs,
540545
line.strip())
541546
finally:
@@ -550,7 +555,7 @@ def detect_modules(self):
550555
add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
551556
# only change this for cross builds for 3.3, issues on Mageia
552557
if cross_compiling:
553-
self.add_gcc_paths()
558+
self.add_cross_compiling_paths()
554559
self.add_multiarch_paths()
555560

556561
# Add paths specified in the environment variables LDFLAGS and
@@ -722,7 +727,8 @@ def detect_modules(self):
722727
# pwd(3)
723728
exts.append( Extension('pwd', ['pwdmodule.c']) )
724729
# grp(3)
725-
exts.append( Extension('grp', ['grpmodule.c']) )
730+
if not VXWORKS:
731+
exts.append( Extension('grp', ['grpmodule.c']) )
726732
# spwd, shadow passwords
727733
if (config_h_vars.get('HAVE_GETSPNAM', False) or
728734
config_h_vars.get('HAVE_GETSPENT', False)):
@@ -859,7 +865,12 @@ def detect_modules(self):
859865
libs = ['crypt']
860866
else:
861867
libs = []
862-
exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) )
868+
869+
if not VXWORKS:
870+
exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) )
871+
elif self.compiler.find_library_file(lib_dirs, 'OPENSSL'):
872+
libs = ['OPENSSL']
873+
exts.append( Extension('_crypt', ['_cryptmodule.c'], libraries=libs) )
863874

864875
# CSV files
865876
exts.append( Extension('_csv', ['_csv.c']) )
@@ -868,8 +879,14 @@ def detect_modules(self):
868879
exts.append( Extension('_posixsubprocess', ['_posixsubprocess.c']) )
869880

870881
# socket(2)
871-
exts.append( Extension('_socket', ['socketmodule.c'],
872-
depends = ['socketmodule.h']) )
882+
if not VXWORKS:
883+
exts.append( Extension('_socket', ['socketmodule.c'],
884+
depends = ['socketmodule.h']) )
885+
elif self.compiler.find_library_file(lib_dirs, 'net'):
886+
libs = ['net']
887+
exts.append( Extension('_socket', ['socketmodule.c'],
888+
depends = ['socketmodule.h'], libraries=libs) )
889+
873890
# Detect SSL support for the socket module (via _ssl)
874891
ssl_ext, hashlib_ext = self._detect_openssl(inc_dirs, lib_dirs)
875892
if ssl_ext is not None:
@@ -1319,9 +1336,10 @@ class db_found(Exception): pass
13191336

13201337
# Unix-only modules
13211338
if host_platform != 'win32':
1322-
# Steen Lumholt's termios module
1323-
exts.append( Extension('termios', ['termios.c']) )
1324-
# Jeremy Hylton's rlimit interface
1339+
if not VXWORKS:
1340+
# Steen Lumholt's termios module
1341+
exts.append( Extension('termios', ['termios.c']) )
1342+
# Jeremy Hylton's rlimit interface
13251343
exts.append( Extension('resource', ['resource.c']) )
13261344
else:
13271345
missing.extend(['resource', 'termios'])

0 commit comments

Comments
 (0)