Skip to content

Commit

Permalink
wheel.mk: Enable compile and install steps for wheel building
Browse files Browse the repository at this point in the history
  • Loading branch information
th0ma7 committed Jan 15, 2025
1 parent 59482d7 commit 4c50a76
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 44 deletions.
148 changes: 148 additions & 0 deletions mk/spksrc.wheel-compile.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
### Wheel rules
# Compile wheels for modules listed in WHEELS.
#
# Targets are executed in the following order:
# wheel_compile_msg_target
# pre_wheel_compile_target (override with PRE_WHEEL_COMPILE_TARGET)
# wheel_compile_target (override with WHEEL_COMPILE_TARGET)
# post_wheel_compile_target (override with POST_WHEEL_COMPILE_TARGET)
# Variables:
# REQUIREMENT Requirement formatted wheel information
# WHEEL_NAME Name of wheel to process
# WHEEL_VERSION Version of wheel to process (can be empty)
# WHEEL_TYPE Type of wheel to process (abi3, crossenv, pure)

ifeq ($(WHEEL_VERSION),)
WHEEL_COMPILE_COOKIE = $(WORK_DIR)/.$(COOKIE_PREFIX)wheel_compile-$(WHEEL_NAME)_done
else
WHEEL_COMPILE_COOKIE = $(WORK_DIR)/.$(COOKIE_PREFIX)wheel_compile-$(WHEEL_NAME)-$(WHEEL_VERSION)_done
endif

##

ifeq ($(strip $(PRE_WHEEL_COMPILE_TARGET)),)
PRE_WHEEL_COMPILE_TARGET = pre_wheel_compile_target
else
$(PRE_WHEEL_COMPILE_TARGET): wheel_compile_msg_target
endif
ifeq ($(strip $(WHEEL_COMPILE_TARGET)),)
WHEEL_COMPILE_TARGET = wheel_compile_target
else
$(WHEEL_COMPILE_TARGET): $(BUILD_WHEEL_COMPILE_TARGET)
endif
ifeq ($(strip $(POST_WHEEL_COMPILE_TARGET)),)
POST_WHEEL_COMPILE_TARGET = post_wheel_compile_target
else
$(POST_WHEEL_COMPILE_TARGET): $(WHEEL_COMPILE_TARGET)
endif

wheel_compile_msg_target:
@$(MSG) "Processing wheels of $(NAME)"

pre_wheel_compile_target: wheel_compile_msg_target

wheel_compile_target: SHELL:=/bin/bash
wheel_compile_target:
ifeq ($(wildcard $(WHEELHOUSE)),)
@$(MSG) Creating wheelhouse directory: $(WHEELHOUSE)
@mkdir -p $(WHEELHOUSE)
endif
@$(MSG) Compiling wheel [$(WHEEL_NAME)], version [$(WHEEL_VERSION)], type [$(WHEEL_TYPE)]
ifneq ($(WHEEL_TYPE),pure)
@$(MSG) $(MAKE) WHEEL=$(WHEEL_NAME)==$(WHEEL_VERSION) crossenv-$(ARCH)-$(TCVERSION) ; \
MAKEFLAGS= $(MAKE) WHEEL=$(WHEEL_NAME)==$(WHEEL_VERSION) crossenv-$(ARCH)-$(TCVERSION) --no-print-directory ; \
[ "$(WHEEL_TYPE)" = "$(WHEELS_LIMITED_API)" ] && abi3="--build-option=--py-limited-api=$(PYTHON_LIMITED_API)" || abi3="" ; \
global_options=$$(echo $(WHEELS_BUILD_ARGS) | sed -e 's/ \[/\n\[/g' | grep -i $(WHEEL_NAME) | cut -f2 -d] | xargs) ; \
localCFLAGS=($$(echo $(WHEELS_CFLAGS) | sed -e 's/ \[/\n\[/g' | grep -i $(WHEEL_NAME) | cut -f2 -d] | xargs)) ; \
localLDFLAGS=($$(echo $(WHEELS_LDFLAGS) | sed -e 's/ \[/\n\[/g' | grep -i $(WHEEL_NAME) | cut -f2 -d] | xargs)) ; \
localCPPFLAGS=($$(echo $(WHEELS_CPPFLAGS) | sed -e 's/ \[/\n\[/g' | grep -i $(WHEEL_NAME) | cut -f2 -d] | xargs)) ; \
localCXXFLAGS=($$(echo $(WHEELS_CXXFLAGS) | sed -e 's/ \[/\n\[/g' | grep -i $(WHEEL_NAME) | cut -f2 -d] | xargs)) ; \
$(MSG) pip build [$(WHEEL_NAME)], version: [$(WHEEL_VERSION)] \
$$([ "$$(echo $${localCFLAGS[@]})" ] && echo "CFLAGS=\"$${localCFLAGS[@]}\" ") \
$$([ "$$(echo $${localCPPFLAGS[@]})" ] && echo "CPPFLAGS=\"$${localCPPFLAGS[@]}\" ") \
$$([ "$$(echo $${localCXXFLAGS[@]})" ] && echo "CXXFLAGS=\"$${localCXXFLAGS[@]}\" ") \
$$([ "$$(echo $${localLDFLAGS[@]})" ] && echo "LDFLAGS=\"$${localLDFLAGS[@]}\" ") \
$$([ "$$(echo $${abi3})" ] && echo "$${abi3} ")" \
$${global_options}" ; \
REQUIREMENT=$(REQUIREMENT) \
WHEEL_NAME=$(WHEEL_NAME) \
WHEEL_VERSION=$(WHEEL_VERSION) \
ADDITIONAL_CFLAGS="-I$(STAGING_INSTALL_PREFIX)/$(PYTHON_INC_DIR) $${localCFLAGS[@]}" \
ADDITIONAL_CPPFLAGS="-I$(STAGING_INSTALL_PREFIX)/$(PYTHON_INC_DIR) $${localCPPFLAGS[@]}" \
ADDITIONAL_CXXFLAGS="-I$(STAGING_INSTALL_PREFIX)/$(PYTHON_INC_DIR) $${localCXXFLAGS[@]}" \
ADDITIONAL_LDFLAGS="$${localLDFLAGS[@]}" \
ABI3="$${abi3}" \
PIP_GLOBAL_OPTION="$${global_options}" \
$(MAKE) --no-print-directory \
cross-compile-wheel-$(WHEEL_NAME) || exit 1
else ifneq ($(filter 1 ON TRUE,$(WHEELS_PURE_PYTHON_PACKAGING_ENABLE)),)
@if [ -s "$(WHEELHOUSE)/$(WHEELS_PURE_PYTHON)" ]; then \
export LD= LDSHARED= CPP= NM= CC= AS= RANLIB= CXX= AR= STRIP= OBJDUMP= OBJCOPY= READELF= CFLAGS= CPPFLAGS= CXXFLAGS= LDFLAGS= && \
$(RUN) \
PATH="$(abspath $(WORK_DIR)/../../../native/$(PYTHON_PKG_NAME)/work-native/install/usr/local/bin):$(PATH)" \
LD_LIBRARY_PATH="$(abspath $(WORK_DIR)/../../../native/$(PYTHON_PKG_NAME)/work-native/install/usr/local/lib):$(LD_LIBRARY_PATH)" \
$(MSG) $(PIP_NATIVE) $(PIP_WHEEL_ARGS) $(REQUIREMENT) ; \
$(PIP_NATIVE) $(PIP_WHEEL_ARGS) $(REQUIREMENT) ; \
fi
endif

##
## crossenv PATH environment requires a combination of:
## 1) unique PATH variable from $(ENV) -> using merge + dedup macros
## Note: Multiple declarations of ENV += PATH=bla creates confusion in its interpretation.
## Solution implemented fetches all PATH from ENV and combine them in reversed order.
## 2) access to maturin from native/python<version>/.../bin -> ${PYTHON_NATIVE_PATH}/bin
## 3) access to crossenv/bin/cross* tools, mainly cross-pip -> ${CROSSENV_PATH}/bin
##
cross-compile-wheel-%: SHELL:=/bin/bash
cross-compile-wheel-%:
@for crossenv in $(WORK_DIR)/crossenv-$(WHEEL_NAME)-$(WHEEL_VERSION) $(WORK_DIR)/crossenv-$(WHEEL_NAME) $(WORK_DIR)/crossenv ; do \
[ -d $${crossenv} ] && . $${crossenv}/build/python-cc.mk && break ; \
done ; \
if [ -d "$${CROSSENV_PATH}" ] ; then \
PATH=$(call dedup, $(call merge, $(ENV), PATH, :), :):$${PYTHON_NATIVE_PATH}:$${CROSSENV_PATH}/bin:$${PATH} ; \
$(MSG) "crossenv: [$${CROSSENV_PATH}]" ; \
$(MSG) "pip: [$$(which cross-pip)]" ; \
$(MSG) "maturin: [$$(which maturin)]" ; \
else \
echo "ERROR: crossenv not found!" ; \
exit 2 ; \
fi ; \
if [ "$(PIP_GLOBAL_OPTION)" ]; then \
pip_global_option=$$(echo $(PIP_GLOBAL_OPTION) | sed 's/=\([^ ]*\)/="\1"/g; s/[^ ]*/--global-option=&/g') ; \
pip_global_option=$${pip_global_option}" --no-use-pep517" ; \
fi ; \
$(RUN) $(MSG) \
_PYTHON_HOST_PLATFORM=\"$(TC_TARGET)\" \
PATH=$${PATH} \
CMAKE_TOOLCHAIN_FILE=$${CMAKE_TOOLCHAIN_FILE} \
MESON_CROSS_FILE=$${MESON_CROSS_FILE} \
cross-pip \
$(PIP_WHEEL_ARGS_CROSSENV) \
$${pip_global_option} \
--no-build-isolation \
$(ABI3) \
$(REQUIREMENT) ; \
$(RUN) \
_PYTHON_HOST_PLATFORM="$(TC_TARGET)" \
PATH=$${PATH} \
CMAKE_TOOLCHAIN_FILE=$${CMAKE_TOOLCHAIN_FILE} \
MESON_CROSS_FILE=$${MESON_CROSS_FILE} \
cross-pip \
$(PIP_WHEEL_ARGS_CROSSENV) \
$${pip_global_option} \
--no-build-isolation \
$(ABI3) \
$(REQUIREMENT)

post_wheel_compile_target: $(WHEEL_COMPILE_TARGET)

ifeq ($(wildcard $(WHEEL_COMPILE_COOKIE)),)
wheel_compile: $(WHEEL_COMPILE_COOKIE)

$(WHEEL_COMPILE_COOKIE): $(POST_WHEEL_COMPILE_TARGET)
$(create_target_dir)
@touch -f $@
else
wheel_compile: ;
endif
32 changes: 4 additions & 28 deletions mk/spksrc.wheel-download.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
### Wheel rules
# Create wheels for modules listed in WHEELS.
# If CROSS_COMPILE_WHEELS is set via python-cc.mk,
# wheels are cross-compiled. If not, pure-python
# wheels are created.

# Download wheels for modules listed in WHEELS.
#
# Targets are executed in the following order:
# wheel_download_msg_target
# pre_wheel_download_target (override with PRE_WHEEL_DOWNLOAD_TARGET)
Expand Down Expand Up @@ -53,10 +50,6 @@ endif
ifeq ($(wildcard $(PIP_CACHE_DIR)),)
@$(MSG) Creating pip caching directory: $(PIP_CACHE_DIR)
@mkdir -p $(PIP_CACHE_DIR)
endif
ifeq ($(wildcard $(WHEELHOUSE)),)
@$(MSG) Creating wheelhouse directory: $(WHEELHOUSE)
@mkdir -p $(WHEELHOUSE)
endif
@$(MSG) Downloading wheel [$(WHEEL_NAME)], version [$(WHEEL_VERSION)] ; \
# $(MSG) requirement: [$(REQUIREMENT)] ; \
Expand All @@ -67,7 +60,7 @@ endif
# $(MSG) type: [$(WHEEL_TYPE)] ; \
if [ "$$(grep -s egg <<< $(REQUIREMENT))" ] ; then \
echo "WARNING: Skipping download URL - Downloaded at build time" ; \
elif [ "$(WHEEL_TYPE)" = "pure" ] && [ "$(WHEELS_PURE_PYTHON_PACKAGING_ENABLE)" = "1" ]; then \
elif [ "$(WHEEL_TYPE)" = "pure" ] && [ ! "$(WHEELS_PURE_PYTHON_PACKAGING_ENABLE)" = "1" ]; then \
echo "WARNING: Skipping download - pure python packaging disabled" ; \
else \
query="curl -s https://pypi.org/pypi/$(WHEEL_NAME)/json" ; \
Expand All @@ -84,27 +77,10 @@ endif
wget --secure-protocol=TLSv1_2 -nv -O $(PIP_DISTRIB_DIR)/$${outFile}.part -nc $$(eval $${query}) ; \
mv $(PIP_DISTRIB_DIR)/$${outFile}.part $(PIP_DISTRIB_DIR)/$${outFile} ; \
fi ; \
fi ; \
case $(WHEEL_TYPE) in \
abi3) $(MSG) Adding $(WHEEL_NAME)==$$(WHEEL_VERSION) to wheelhouse/$(WHEELS_LIMITED_API) ; \
echo $(WHEEL_NAME)==$(WHEEL_VERSION) | sed -e '/^[[:blank:]]*$$\|^#/d' >> $(WHEELHOUSE)/$(WHEELS_LIMITED_API) ; \
;; \
crossenv) $(MSG) Adding $(WHEEL_NAME)==$(WHEEL_VERSION) to wheelhouse/$(WHEELS_CROSSENV_COMPILE) ; \
echo $(WHEEL_NAME)==$(WHEEL_VERSION) | sed -e '/^[[:blank:]]*$$\|^#/d' >> $(WHEELHOUSE)/$(WHEELS_CROSSENV_COMPILE) ; \
;; \
pure) $(MSG) Adding $(WHEEL_NAME)==$(WHEEL_VERSION) to wheelhouse/$(WHEELS_PURE_PYTHON) ; \
echo $(WHEEL_NAME)==$(WHEEL_VERSION) | sed -e '/^[[:blank:]]*$$\|^#/d' >> $(WHEELHOUSE)/$(WHEELS_PURE_PYTHON) ; \
;; \
*) $(MSG) No type found for wheel [$(REQUIREMENT)] ; \
;; \
esac
@for file in $$(ls -1 $(WHEELHOUSE)/requirements-*.txt) ; do \
sort -u -o $${file}{,} ; \
done
fi

post_wheel_download_target: $(WHEEL_DOWNLOAD_TARGET)


ifeq ($(wildcard $(WHEEL_DOWNLOAD_COOKIE)),)
wheel_download: $(WHEEL_DOWNLOAD_COOKIE)

Expand Down
78 changes: 78 additions & 0 deletions mk/spksrc.wheel-install.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
### Wheel rules
# Install wheels for modules listed in WHEELS.
#
# Targets are executed in the following order:
# wheel_install_msg_target
# pre_wheel_install_target (override with PRE_WHEEL_INSTALL_TARGET)
# wheel_install_target (override with WHEEL_INSTALL_TARGET)
# post_wheel_install_target (override with POST_WHEEL_INSTALL_TARGET)
# Variables:
# REQUIREMENT Requirement formatted wheel information
# WHEEL_NAME Name of wheel to process
# WHEEL_VERSION Version of wheel to process (can be empty)
# WHEEL_TYPE Type of wheel to process (abi3, crossenv, pure)

ifeq ($(WHEEL_VERSION),)
WHEEL_INSTALL_COOKIE = $(WORK_DIR)/.$(COOKIE_PREFIX)wheel_install-$(WHEEL_NAME)_done
else
WHEEL_INSTALL_COOKIE = $(WORK_DIR)/.$(COOKIE_PREFIX)wheel_install-$(WHEEL_NAME)-$(WHEEL_VERSION)_done
endif

##

ifeq ($(strip $(PRE_WHEEL_INSTALL_TARGET)),)
PRE_WHEEL_INSTALL_TARGET = pre_wheel_install_target
else
$(PRE_WHEEL_INSTALL_TARGET): wheel_install_msg_target
endif
ifeq ($(strip $(WHEEL_INSTALL_TARGET)),)
WHEEL_INSTALL_TARGET = wheel_install_target
else
$(WHEEL_INSTALL_TARGET): $(BUILD_WHEEL_INSTALL_TARGET)
endif
ifeq ($(strip $(POST_WHEEL_INSTALL_TARGET)),)
POST_WHEEL_INSTALL_TARGET = post_wheel_install_target
else
$(POST_WHEEL_INSTALL_TARGET): $(WHEEL_INSTALL_TARGET)
endif

wheel_install_msg_target:
@$(MSG) "Processing wheels of $(NAME)"

pre_wheel_install_target: wheel_install_msg_target

wheel_install_target: SHELL:=/bin/bash
wheel_install_target:
ifeq ($(wildcard $(WHEELHOUSE)),)
@$(MSG) Creating wheelhouse directory: $(WHEELHOUSE)
@mkdir -p $(WHEELHOUSE)
endif
@$(MSG) Installing wheel [$(WHEEL_NAME)], version [$(WHEEL_VERSION)], type [$(WHEEL_TYPE)] ; \
case $(WHEEL_TYPE) in \
abi3) $(MSG) Adding $(WHEEL_NAME)==$$(WHEEL_VERSION) to wheelhouse/$(WHEELS_LIMITED_API) ; \
echo $(WHEEL_NAME)==$(WHEEL_VERSION) | sed -e '/^[[:blank:]]*$$\|^#/d' >> $(WHEELHOUSE)/$(WHEELS_LIMITED_API) ; \
;; \
crossenv) $(MSG) Adding $(WHEEL_NAME)==$(WHEEL_VERSION) to wheelhouse/$(WHEELS_CROSSENV_COMPILE) ; \
echo $(WHEEL_NAME)==$(WHEEL_VERSION) | sed -e '/^[[:blank:]]*$$\|^#/d' >> $(WHEELHOUSE)/$(WHEELS_CROSSENV_COMPILE) ; \
;; \
pure) $(MSG) Adding $(WHEEL_NAME)==$(WHEEL_VERSION) to wheelhouse/$(WHEELS_PURE_PYTHON) ; \
echo $(WHEEL_NAME)==$(WHEEL_VERSION) | sed -e '/^[[:blank:]]*$$\|^#/d' >> $(WHEELHOUSE)/$(WHEELS_PURE_PYTHON) ; \
;; \
*) $(MSG) No type found for wheel [$(REQUIREMENT)] ; \
;; \
esac
@for file in $$(ls -1 $(WHEELHOUSE)/requirements-*.txt) ; do \
sort -u -o $${file}{,} ; \
done

post_wheel_install_target: $(WHEEL_INSTALL_TARGET)

ifeq ($(wildcard $(WHEEL_INSTALL_COOKIE)),)
wheel_install: $(WHEEL_INSTALL_COOKIE)

$(WHEEL_INSTALL_COOKIE): $(POST_WHEEL_INSTALL_TARGET)
$(create_target_dir)
@touch -f $@
else
wheel_install: ;
endif
27 changes: 11 additions & 16 deletions mk/spksrc.wheel.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
### Wheel rules
# Create wheels for modules listed in WHEELS.
# If CROSS_COMPILE_WHEELS is set via python-cc.mk,
# wheels are cross-compiled. If not, pure-python
# wheels are created.

# Process wheels for modules listed in WHEELS.
# 1. wheel_download
# 2. wheel_compile
# 3. wheel_install
#
# Targets are executed in the following order:
# wheel_msg_target
# pre_wheel_target (override with PRE_WHEEL_TARGET)
Expand All @@ -29,21 +29,16 @@ include ../../mk/spksrc.cross-meson-env.mk

include ../../mk/spksrc.wheel-download.mk

#wheel_configure: wheel_download
#include ../../mk/spksrc.wheel-configure.mk
#
#wheel_compile: wheel_configure
#include ../../mk/spksrc.wheel-compile.mk
#
#wheel_install: wheel_compile
#include ../../mk/spksrc.wheel-install.mk
#
#all: wheel_install
wheel_compile: wheel_download
include ../../mk/spksrc.wheel-compile.mk

wheel_install: wheel_compile
include ../../mk/spksrc.wheel-install.mk

##

ifneq ($(strip $(REQUIREMENT)),)
wheel: wheel_download
wheel: wheel_install
else

ifeq ($(strip $(PRE_WHEEL_TARGET)),)
Expand Down

0 comments on commit 4c50a76

Please sign in to comment.