Commit 398dac6c authored by Isuru Fernando's avatar Isuru Fernando
Browse files

use wrap_wheel_builder and factor out functionality

parent 66b61322
...@@ -270,77 +270,23 @@ function bdist_wheel_cmd { ...@@ -270,77 +270,23 @@ function bdist_wheel_cmd {
cp dist/*.whl $abs_wheelhouse cp dist/*.whl $abs_wheelhouse
} }
function run_command_universal2 { function wrap_wheel_builder {
if [[ "${PLAT:-}" == "universal2" ]]; then
export PLAT_BACKUP="universal2"
(
export PLAT="x86_64"
export _PYTHON_HOST_PLATFORM="macosx-10.9-x86_64"
export CFLAGS+=" -arch x86_64"
export CXXFLAGS+=" -arch x86_64"
export ARCHFLAGS+=" -arch x86_64"
export CPPFLAGS+=" -arch x86_64"
export LDFLAGS+=" -arch x86_64"
$@ $@
)
rm -rf *-stamp
fi
if [[ "${PLAT:-}" == "universal2" || "${PLAT:-}" == "arm64" ]]; then
(
export PLAT="arm64"
export BUILD_PREFIX=/opt/arm64-builds
sudo mkdir -p $BUILD_PREFIX
sudo chown -R $USER $BUILD_PREFIX
update_env_for_build_prefix
export _PYTHON_HOST_PLATFORM="macosx-11.0-arm64"
export CFLAGS+=" -arch arm64"
export CXXFLAGS+=" -arch arm64"
export CPPFLAGS+=" -arch arm64"
export ARCHFLAGS+=" -arch arm64"
export FCFLAGS+=" -arch arm64"
export FC=$FC_ARM64
export LDFLAGS+=" -arch arm64 -L$BUILD_PREFIX/lib -Wl,-rpath,$BUILD_PREFIX/lib ${FC_ARM64_LDFLAGS:-}"
# This would automatically let autoconf know that we are cross compiling for arm64 darwin
export host_alias="aarch64-apple-darwin20.0.0"
$@
)
local wheelhouse=$(abspath ${WHEEL_SDIR:-wheelhouse})
mkdir -p wheelhouse2
if [[ "${PLAT:-}" == "universal2" ]]; then
for whl in $wheelhouse/*.whl; do
if [[ "$whl" == *macosx_10_9_x86_64.whl ]]; then
whl_base=$(echo $whl | rev | cut -c 23- | rev)
echo $whl_base
if [[ -f "${whl_base}macosx_11_0_arm64.whl" ]]; then
delocate-fuse $whl "${whl_base}macosx_11_0_arm64.whl" -w wheelhouse2
mv wheelhouse2/$(basename $whl) $wheelhouse/$(basename ${whl_base})macosx_10_9_universal2.whl
# Since we want one wheel thats installable for testing we are deleting the 10_9_x86_64 wheel.
# We are not deleting arm64 wheel because the size is lower and homebrew/conda-forge python
# will use them by default
rm $whl
fi
fi
done
fi
else
$@
fi
} }
function build_pip_wheel { function build_pip_wheel {
# Standard wheel building command with pip wheel # Standard wheel building command with pip wheel
run_command_universal2 build_wheel_cmd "pip_wheel_cmd" $@ wrap_wheel_builder build_wheel_cmd "pip_wheel_cmd" $@
} }
function build_bdist_wheel { function build_bdist_wheel {
# Wheel building with bdist_wheel. See bdist_wheel_cmd # Wheel building with bdist_wheel. See bdist_wheel_cmd
run_command_universal2 build_wheel_cmd "bdist_wheel_cmd" $@ wrap_wheel_builder build_wheel_cmd "bdist_wheel_cmd" $@
} }
function build_wheel { function build_wheel {
# Set default building method to pip # Set default building method to pip
run_command_universal2 build_pip_wheel $@ wrap_wheel_builder build_pip_wheel $@
} }
function build_index_wheel_cmd { function build_index_wheel_cmd {
...@@ -375,7 +321,7 @@ function build_index_wheel_cmd { ...@@ -375,7 +321,7 @@ function build_index_wheel_cmd {
} }
function build_index_wheel { function build_index_wheel {
run_command_universal2 build_index_wheel_cmd $@ wrap_wheel_builder build_index_wheel_cmd $@
} }
function pip_opts { function pip_opts {
......
...@@ -423,3 +423,67 @@ function activate_ccache { ...@@ -423,3 +423,67 @@ function activate_ccache {
# Prove to the developer that ccache is activated # Prove to the developer that ccache is activated
echo "Using C compiler: $(which clang)" echo "Using C compiler: $(which clang)"
} }
function macos_intel_build_wrap {
export PLAT="x86_64"
export _PYTHON_HOST_PLATFORM="macosx-10.9-x86_64"
export CFLAGS+=" -arch x86_64"
export CXXFLAGS+=" -arch x86_64"
export ARCHFLAGS+=" -arch x86_64"
export CPPFLAGS+=" -arch x86_64"
export LDFLAGS+=" -arch x86_64"
$@
}
function macos_arm64_build_wrap {
export PLAT="arm64"
export BUILD_PREFIX=/opt/arm64-builds
sudo mkdir -p $BUILD_PREFIX
sudo chown -R $USER $BUILD_PREFIX
update_env_for_build_prefix
export _PYTHON_HOST_PLATFORM="macosx-11.0-arm64"
export CFLAGS+=" -arch arm64"
export CXXFLAGS+=" -arch arm64"
export CPPFLAGS+=" -arch arm64"
export ARCHFLAGS+=" -arch arm64"
export FCFLAGS+=" -arch arm64"
export FC=$FC_ARM64
export LDFLAGS+=" -arch arm64 -L$BUILD_PREFIX/lib -Wl,-rpath,$BUILD_PREFIX/lib ${FC_ARM64_LDFLAGS:-}"
# This would automatically let autoconf know that we are cross compiling for arm64 darwin
export host_alias="aarch64-apple-darwin20.0.0"
$@
}
function fuse_macos_intel_arm64 {
local wheelhouse=$(abspath ${WHEEL_SDIR:-wheelhouse})
mkdir -p wheelhouse2
for whl in $wheelhouse/*.whl; do
if [[ "$whl" == *macosx_10_9_x86_64.whl ]]; then
whl_base=$(echo $whl | rev | cut -c 23- | rev)
echo $whl_base
if [[ -f "${whl_base}macosx_11_0_arm64.whl" ]]; then
delocate-fuse $whl "${whl_base}macosx_11_0_arm64.whl" -w wheelhouse2
mv wheelhouse2/$(basename $whl) $wheelhouse/$(basename ${whl_base})macosx_10_9_universal2.whl
# Since we want one wheel thats installable for testing we are deleting the 10_9_x86_64 wheel.
# We are not deleting arm64 wheel because the size is lower and homebrew/conda-forge python
# will use them by default
rm $whl
fi
fi
done
}
function wrap_wheel_builder {
if [[ "${PLAT:-}" == "universal2" ]]; then
(macos_intel_build_wrap $@)
rm -rf *-stamp
fi
if [[ "${PLAT:-}" == "universal2" ]]; then
(macos_arm64_build_wrap $@)
fuse_macos_intel_arm64 $@
elif [[ "${PLAT:-}" == "arm64" ]]; then
(macos_arm64_build_wrap $@)
else
$@
fi
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment