Skip to content

Commit b30bf45

Browse files
authored
bpo-45881: Use CC from env first for cross building (GH-29752)
1 parent 64c3807 commit b30bf45

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``setup.py`` now uses ``CC`` from environment first to discover multiarch
2+
and cross compile paths.

setup.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ def get_platform():
8484
MACOS = (HOST_PLATFORM == 'darwin')
8585
AIX = (HOST_PLATFORM.startswith('aix'))
8686
VXWORKS = ('vxworks' in HOST_PLATFORM)
87+
CC = os.environ.get("CC")
88+
if not CC:
89+
CC = sysconfig.get_config_var("CC")
8790

8891

8992
SUMMARY = """
@@ -556,6 +559,9 @@ def set_compiler_executables(self):
556559

557560
def build_extensions(self):
558561
self.set_srcdir()
562+
self.set_compiler_executables()
563+
self.configure_compiler()
564+
self.init_inc_lib_dirs()
559565

560566
# Detect which modules should be compiled
561567
self.detect_modules()
@@ -565,7 +571,6 @@ def build_extensions(self):
565571

566572
self.update_sources_depends()
567573
mods_built, mods_disabled = self.handle_configured_extensions()
568-
self.set_compiler_executables()
569574

570575
if LIST_MODULE_NAMES:
571576
for ext in self.extensions:
@@ -751,12 +756,11 @@ def check_extension_import(self, ext):
751756
def add_multiarch_paths(self):
752757
# Debian/Ubuntu multiarch support.
753758
# https://wiki.ubuntu.com/MultiarchSpec
754-
cc = sysconfig.get_config_var('CC')
755759
tmpfile = os.path.join(self.build_temp, 'multiarch')
756760
if not os.path.exists(self.build_temp):
757761
os.makedirs(self.build_temp)
758762
ret = run_command(
759-
'%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
763+
'%s -print-multiarch > %s 2> /dev/null' % (CC, tmpfile))
760764
multiarch_path_component = ''
761765
try:
762766
if ret == 0:
@@ -818,11 +822,10 @@ def add_search_path(line):
818822
d = os.path.normpath(d)
819823
add_dir_to_list(self.compiler.library_dirs, d)
820824

821-
cc = sysconfig.get_config_var('CC')
822825
tmpfile = os.path.join(self.build_temp, 'wrccpaths')
823826
os.makedirs(self.build_temp, exist_ok=True)
824827
try:
825-
ret = run_command('%s --print-search-dirs >%s' % (cc, tmpfile))
828+
ret = run_command('%s --print-search-dirs >%s' % (CC, tmpfile))
826829
if ret:
827830
return
828831
with open(tmpfile) as fp:
@@ -840,11 +843,10 @@ def add_search_path(line):
840843
pass
841844

842845
def add_cross_compiling_paths(self):
843-
cc = sysconfig.get_config_var('CC')
844846
tmpfile = os.path.join(self.build_temp, 'ccpaths')
845847
if not os.path.exists(self.build_temp):
846848
os.makedirs(self.build_temp)
847-
ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
849+
ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (CC, tmpfile))
848850
is_gcc = False
849851
is_clang = False
850852
in_incdirs = False
@@ -1407,9 +1409,6 @@ def detect_modules(self):
14071409
# remove dummy extension
14081410
self.extensions = []
14091411

1410-
self.configure_compiler()
1411-
self.init_inc_lib_dirs()
1412-
14131412
# Some C extensions are built by entries in Modules/Setup.bootstrap.
14141413
# These are extensions are required to bootstrap the interpreter or
14151414
# build process.

0 commit comments

Comments
 (0)