diff --git a/scripts/build_macos_wheels.sh b/scripts/build_macos_wheels.sh index 59c0c30f8..c701f6d8d 100755 --- a/scripts/build_macos_wheels.sh +++ b/scripts/build_macos_wheels.sh @@ -1,25 +1,94 @@ #!/usr/bin/env bash +# (c) 2017-2023 Tuplex team +# builds x86_64 (and arm64) wheels + +# add -x option for verbose output +set -euo pipefail + +function fail { + printf '%s\n' "$1" >&2 + exit "${2-1}" +} + +function detect_instruction_set() { + arch="$(uname -m)" # -i is only linux, -m is linux and apple + if [[ "$arch" = x86_64* ]]; then + if [[ "$(uname -a)" = *ARM64* ]]; then + echo 'arm64' + else + echo 'x86_64' + fi + elif [[ "$arch" = i*86 ]]; then + echo 'x86_32' + elif [[ "$arch" = arm* ]]; then + echo $arch + elif test "$arch" = aarch64; then + echo 'arm64' + else + exit 1 + fi +} # check from where script is invoked CWD="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" +echo " || Tuplex macOS wheel builder || " +echo "-- Executing buildwheel script located in $CWD" + +# check platform is darwin +if [ ! "$(uname -s)" = "Darwin" ]; then + fail "Error: Need to run script under macOS" +fi + +# check which tags are supported +arch=$(detect_instruction_set) +echo "-- Detected arch ${arch}" + +# try to extract version of compiler first via command-line tools or xcode +# either needs to be installed. +xcode_version_str=$(pkgutil --pkg-info=com.apple.pkg.CLTools_Executables 2>/dev/null | grep version || pkgutil --pkg-info=com.apple.pkg.Xcode | grep version) +echo "-- Detected Xcode ${xcode_version_str}" + +# if no param is given, use defaults to build all +if [ "${arch}" = "arm64" ]; then + # build Python 3.9 - 3.11 + CIBW_BUILD=${CIBW_BUILD-"cp3{9,10,11}-macosx_arm64"} +else + # build Python 3.8 - 3.11 + CIBW_BUILD=${CIBW_BUILD-"cp3{8,9,10,11}-macosx_x86_64"} +fi + +echo "-- Building wheels for ${CIBW_BUILD}" + +# if macOS is 10.x -> use this as minimum +MINIMUM_TARGET="10.13" + +MACOS_VERSION=$(sw_vers -productVersion) +echo "-- Processing on MacOS ${MACOS_VERSION}" +function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } + +MACOS_VERSION_MAJOR=`echo $MACOS_VERSION | cut -d . -f1` + +if [ "$MACOS_VERSION_MAJOR" -ge 11 ]; then + echo "-- Newer MacOS detected (>=11.0), using more recent base target." + echo "-- Using minimum target ${MACOS_VERSION_MAJOR}.0" + MINIMUM_TARGET="${MACOS_VERSION_MAJOR}.0" +else + # keep as is + echo "-- Defaulting build to use as minimum target ${MINIMUM_TARGET}" +fi -echo "Executing buildwheel script located in $CWD" pushd $CWD > /dev/null cd .. -# protobuf 3.20-3.21.2 is broken for MacOS, so use -# 3.19.4 -# brew tap-new $USER/local-podman -# brew extract --version=3.19.4 protobuf $USER/local-podman -# brew install $USER/local-podman/protobuf@3.19.4 -# i.e., prepend to statemtnt the following: brew tap-new $USER/local; brew extract --force --version=3.19.4 protobuf $USER/local && brew install $USER/local/protobuf@3.19.4 && -export CIBW_BEFORE_BUILD_MACOS="brew install protobuf coreutils zstd zlib libmagic llvm@9 aws-sdk-cpp pcre2 antlr4-cpp-runtime googletest gflags yaml-cpp celero wget boost" -export CIBW_ENVIRONMENT_MACOS="MACOSX_DEPLOYMENT_TARGET=10.13 CMAKE_ARGS='-DBUILD_WITH_AWS=ON -DBUILD_WITH_ORC=ON' " +# Note: protobuf 3.20 - 3.21.2 is broken for MacOS, do not use those versions +export CIBW_BEFORE_BUILD_MACOS="brew install protobuf coreutils zstd zlib libmagic llvm@16 aws-sdk-cpp pcre2 antlr4-cpp-runtime googletest gflags yaml-cpp celero wget boost ninja snappy" +export CIBW_ENVIRONMENT_MACOS="MACOSX_DEPLOYMENT_TARGET=${MINIMUM_TARGET} CMAKE_ARGS='-DBUILD_WITH_AWS=ON -DBUILD_WITH_ORC=ON' " -export CIBW_BUILD="cp3{7,8,9}-*" -export CIBW_SKIP="cp3{5,6}-macosx* pp* *-musllinux_*" +export CIBW_BUILD="${CIBW_BUILD}" +export CIBW_PROJECT_REQUIRES_PYTHON=">=3.8" -export CIBW_PROJECT_REQUIRES_PYTHON=">=3.7" +# uncomment to increase verbosity of cibuildwheel +# export CIBW_BUILD_VERBOSITY=3 cibuildwheel --platform macos diff --git a/setup.py b/setup.py index 91285f654..f619ccd81 100644 --- a/setup.py +++ b/setup.py @@ -328,12 +328,13 @@ def build_extension(self, ext): if platform.system().lower() == 'darwin': # mac os, use brewed versions! out_py = subprocess.check_output(['brew', 'info', 'python3']).decode() - print(out_py) def find_pkg_path(lines): - return list(filter(lambda x: 'usr/local' in x, lines.split('\n')))[0] + ans = list(filter(lambda x: 'usr/local' in x, lines.split('\n'))) + return None if 0 == len(ans) else ans[0] out_py = find_pkg_path(out_py) - print('Found python3 @ {}'.format(out_py)) + if out_py: + logging.info('Found python3 @ {}'.format(out_py)) # setups find everything automatically... llvm_root = None