Skip to content

Commit cd6d257

Browse files
authored
[3.9] bpo-45881: Use CC from env first for cross building (GH-29752) (GH-29754)
Co-authored-by: Christian Heimes <[email protected]>. Co-authored-by: Christian Heimes <[email protected]>
1 parent 71b4147 commit cd6d257

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed
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

+8-8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def get_platform():
6565
MACOS = (HOST_PLATFORM == 'darwin')
6666
AIX = (HOST_PLATFORM.startswith('aix'))
6767
VXWORKS = ('vxworks' in HOST_PLATFORM)
68+
CC = os.environ.get("CC")
69+
if not CC:
70+
CC = sysconfig.get_config_var("CC")
6871

6972

7073
SUMMARY = """
@@ -443,6 +446,9 @@ def set_compiler_executables(self):
443446

444447
def build_extensions(self):
445448
self.set_srcdir()
449+
self.set_compiler_executables()
450+
self.configure_compiler()
451+
self.init_inc_lib_dirs()
446452

447453
# Detect which modules should be compiled
448454
self.detect_modules()
@@ -451,7 +457,6 @@ def build_extensions(self):
451457

452458
self.update_sources_depends()
453459
mods_built, mods_disabled = self.remove_configured_extensions()
454-
self.set_compiler_executables()
455460

456461
build_ext.build_extensions(self)
457462

@@ -631,12 +636,11 @@ def check_extension_import(self, ext):
631636
def add_multiarch_paths(self):
632637
# Debian/Ubuntu multiarch support.
633638
# https://wiki.ubuntu.com/MultiarchSpec
634-
cc = sysconfig.get_config_var('CC')
635639
tmpfile = os.path.join(self.build_temp, 'multiarch')
636640
if not os.path.exists(self.build_temp):
637641
os.makedirs(self.build_temp)
638642
ret = run_command(
639-
'%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
643+
'%s -print-multiarch > %s 2> /dev/null' % (CC, tmpfile))
640644
multiarch_path_component = ''
641645
try:
642646
if ret == 0:
@@ -675,11 +679,10 @@ def add_multiarch_paths(self):
675679
os.unlink(tmpfile)
676680

677681
def add_cross_compiling_paths(self):
678-
cc = sysconfig.get_config_var('CC')
679682
tmpfile = os.path.join(self.build_temp, 'ccpaths')
680683
if not os.path.exists(self.build_temp):
681684
os.makedirs(self.build_temp)
682-
ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc, tmpfile))
685+
ret = run_command('%s -E -v - </dev/null 2>%s 1>/dev/null' % (CC, tmpfile))
683686
is_gcc = False
684687
is_clang = False
685688
in_incdirs = False
@@ -1783,9 +1786,6 @@ def detect_uuid(self):
17831786
self.missing.append('_uuid')
17841787

17851788
def detect_modules(self):
1786-
self.configure_compiler()
1787-
self.init_inc_lib_dirs()
1788-
17891789
self.detect_simple_extensions()
17901790
if TEST_EXTENSIONS:
17911791
self.detect_test_extensions()

0 commit comments

Comments
 (0)