Skip to content

Commit 97920ff

Browse files
committed
Tweak the handling of macOS libs to ensure non-macOS Pythons aren't empty.
1 parent 724d023 commit 97920ff

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

Makefile

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,14 @@ endif
438438
# macOS builds are compiled as a single universal2 build. As a result,
439439
# the macOS Python build is configured in the `build` macro, rather than the
440440
# `build-target` macro.
441-
ifneq ($(os),macOS)
441+
ifeq ($(os),macOS)
442+
443+
# These constants will be the same for all macOS targets
444+
PYTHON_DIR-$(target)=build/$(os)/Python-$(PYTHON_VERSION)-$(os)
445+
PYTHON_LIB-$(target)=$$(PYTHON_DIR-$(target))/_install/lib/libpython$(PYTHON_VER).a
446+
# PYCONFIG_H-$(target) not defined, as there's no header shim needed
447+
448+
else
442449

443450
PYTHON_DIR-$(target)=build/$(os)/Python-$(PYTHON_VERSION)-$(target)
444451
PYTHON_LIB-$(target)=$$(PYTHON_DIR-$(target))/_install/lib/libpython$(PYTHON_VER).a
@@ -518,7 +525,8 @@ vars-$(target):
518525
@echo "LIBFFI_DIR-$(target): $$(LIBFFI_DIR-$(target))"
519526
@echo "LIBFFI_LIB-$(target): $$(LIBFFI_LIB-$(target))"
520527
@echo "PYTHON_DIR-$(target): $$(PYTHON_DIR-$(target))"
521-
@echo "pyconfig.h-$(target): $$(pyconfig.h-$(target))"
528+
@echo "PYTHON_LIB-$(target): $$(PYTHON_LIB-$(target))"
529+
@echo "PYCONFIG_H-$(target): $$(PYCONFIG_H-$(target))"
522530
@echo
523531

524532
endef # build-target
@@ -603,17 +611,23 @@ $$(LIBFFI_FATLIB-$(sdk)): $$(foreach target,$$(SDK_TARGETS-$(sdk)),$$(LIBFFI_LIB
603611
# SDK: Python
604612
###########################################################################
605613

614+
PYTHON_DIR-$(sdk)=build/$(os)/python/$(sdk)
615+
PYTHON_FATLIB-$(sdk)=$$(PYTHON_DIR-$(sdk))/lib/libPython.a
616+
606617
ifeq ($(os),macOS)
618+
# There's a single OS-level build for macOS; the fat library is a direct copy of
619+
# OS build, and the headers are the unmodifed headers produced by the OS build.
607620

608-
# There's no SDK-level build; redirect some constants to the OS-level build
609-
PYTHON_DIR-$(sdk)=build/$(os)/Python-$(PYTHON_VERSION)-$(os)
610-
PYTHON_FATLIB-$(sdk)=$$(PYTHON_DIR-$(sdk))/_install/lib/libpython$(PYTHON_VER).a
621+
$$(PYTHON_FATLIB-$(sdk)): $$(PYTHON_LIB-$$(firstword $$(SDK_TARGETS-$(sdk))))
622+
@echo ">>> Build Python fat library for $(sdk)"
623+
# Copy the OS-level library
624+
mkdir -p build/$(os)/python/$(sdk)/lib
625+
cp $$(PYTHON_LIB-$$(firstword $$(SDK_TARGETS-$(sdk)))) $$(PYTHON_FATLIB-$(sdk))
626+
# Copy headers from the OS-level build
627+
cp -r $$(PYTHON_DIR-$$(firstword $$(SDK_TARGETS-$(sdk))))/_install/include build/$(os)/python/$(sdk)
611628

612629
else
613630

614-
PYTHON_DIR-$(sdk)=build/$(os)/python/$(sdk)
615-
PYTHON_FATLIB-$(sdk)=$$(PYTHON_DIR-$(sdk))/lib/libPython.a
616-
617631
$$(PYTHON_FATLIB-$(sdk)): $$(foreach target,$$(SDK_TARGETS-$(sdk)),$$(PYTHON_LIB-$$(target)))
618632
@echo ">>> Build Python fat library for $(sdk)"
619633
mkdir -p build/$(os)/python/$(sdk)/lib
@@ -764,7 +778,12 @@ ifeq ($(os),macOS)
764778
# On macOS, there's a single target and a single output dir,
765779
# rather than a target for each architecture.
766780
PYTHON_TARGETS-$(os)=macOS
767-
PYTHON_DIR-$(os)=build/$(os)/Python-$(PYTHON_VERSION)-$(os)
781+
782+
# For convenience on macOS, define an OS-level PYTHON_DIR and PYTHON_LIB.
783+
# They are proxies of the values set for the first target, since all target
784+
# constants should have the same value for macOS builds
785+
PYTHON_DIR-$(os)=$$(PYTHON_DIR-$$(firstword $$(TARGETS-$(os))))
786+
PYTHON_LIB-$(os)=$$(PYTHON_LIB-$$(firstword $$(TARGETS-$(os))))
768787

769788
$$(PYTHON_DIR-$(os))/Makefile: \
770789
$$(BZIP2_XCFRAMEWORK-$(os)) \
@@ -798,7 +817,7 @@ $$(PYTHON_DIR-$(os))/python.exe: \
798817
make all \
799818
2>&1 | tee -a ../python-$(os).build.log
800819

801-
$$(PYTHON_FATLIB-macosx): $$(PYTHON_DIR-$(os))/python.exe
820+
$$(PYTHON_LIB-$(os)): $$(PYTHON_DIR-$(os))/python.exe
802821
@echo ">>> Install Python for $(os)"
803822
cd $$(PYTHON_DIR-$(os)) && \
804823
PATH="$(PROJECT_DIR)/$(PYTHON_DIR-$(os))/_install/bin:$(PATH)" \
@@ -817,7 +836,7 @@ $$(PYTHON_XCFRAMEWORK-$(os)): $$(foreach sdk,$$(SDKS-$(os)),$$(PYTHON_FATLIB-$$(
817836
@echo ">>> Create Python.XCFramework on $(os)"
818837
mkdir -p $$(PYTHON_XCFRAMEWORK-$(os))
819838
xcodebuild -create-xcframework \
820-
-output $$@ $$(foreach sdk,$$(SDKS-$(os)),-library $$(PYTHON_FATLIB-$$(sdk)) -headers $$(PYTHON_DIR-$$(sdk))/_install/include/python$(PYTHON_VER)) \
839+
-output $$@ $$(foreach sdk,$$(SDKS-$(os)),-library $$(PYTHON_FATLIB-$$(sdk)) -headers $$(PYTHON_DIR-$$(sdk))/include/python$(PYTHON_VER)) \
821840
2>&1 | tee -a build/$(os)/python-$(os).xcframework.log
822841
# Copy the standard library from the first target listed
823842
mkdir -p $$(PYTHON_RESOURCES-$(os))
@@ -877,6 +896,7 @@ vars-$(os): $$(foreach target,$$(TARGETS-$(os)),vars-$$(target)) $$(foreach sdk,
877896
@echo "PYTHON_RESOURCES-$(os): $$(PYTHON_RESOURCES-$(os))"
878897
@echo "PYTHON_TARGETS-$(os): $$(PYTHON_TARGETS-$(os))"
879898
@echo "PYTHON_DIR-$(os): $$(PYTHON_DIR-$(os))"
899+
@echo "PYTHON_LIB-$(os): $$(PYTHON_LIB-$(os))"
880900
@echo
881901

882902
endef # build

0 commit comments

Comments
 (0)