Skip to content

Commit

Permalink
Make mac-arm64 for apple silicon(M1, M2)
Browse files Browse the repository at this point in the history
  • Loading branch information
auxten committed Apr 9, 2023
1 parent e37ace5 commit ab2afa8
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# auto generated files
*.logrt

/python_pkg/
/chdb-0.*/
*.strings
/arrow1100
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all clean buildlib wheel pub
.PHONY: all clean buildlib wheel pub mac-arm64

buildlib:
@echo "Building library..."
Expand All @@ -20,5 +20,9 @@ clean:
tox -e clean
@echo "Done."

mac-arm64:
@echo "Make macOS arm64 whl"
bash packages/build_mac_arm64.sh
@echo "Done."

build: clean buildlib wheel
7 changes: 7 additions & 0 deletions gen_manifest.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/bin/bash

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

cd ${DIR}

echo "include chdb/*.py" > MANIFEST.in
export SO_SUFFIX=$(python3 -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
echo "include chdb/_chdb${SO_SUFFIX}" >> MANIFEST.in
70 changes: 70 additions & 0 deletions packages/build_mac_arm64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/arch -arm64 /bin/bash

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PROJ_DIR=$(dirname ${DIR})

cd ${PROJ_DIR}

# Download py39 py310 py311 universal2 pkg from python.org
if [ ! -d ${PROJ_DIR}/python_pkg ]; then
mkdir ${PROJ_DIR}/python_pkg
fi

# prefer /usr/local/opt/llvm@15/bin/clang++ then /usr/local/opt/llvm/bin/clang++
if [ -f /usr/local/opt/llvm@15/bin/clang++ ]; then
export CXX=/usr/local/opt/llvm@15/bin/clang++
elif [ -f /usr/local/opt/llvm/bin/clang++ ]; then
export CXX=/usr/local/opt/llvm/bin/clang++
fi
if [ -f /usr/local/opt/llvm@15/bin/clang ]; then
export CC=/usr/local/opt/llvm@15/bin/clang
elif [ -f /usr/local/opt/llvm/bin/clang ]; then
export CC=/usr/local/opt/llvm/bin/clang
fi

for PY_VER in 3.9.13 3.10.11 3.11.3; do
if [ ! -f ${PROJ_DIR}/python_pkg/python-${PY_VER}-macos11.pkg ]; then
wget https://www.python.org/ftp/python/${PY_VER}/python-${PY_VER}-macos11.pkg -O ${PROJ_DIR}/python_pkg/python-${PY_VER}-macos11.pkg
fi

PY_SHORT_VER=$(echo ${PY_VER} | cut -d. -f1,2)
# Install universal2 pkg
sudo installer -pkg ${PROJ_DIR}/python_pkg/python-${PY_VER}-macos11.pkg -target /
export PATH=/Library/Frameworks/Python.framework/Versions/${PY_SHORT_VER}/bin:/Library/Frameworks/Python.framework/Versions/${PY_SHORT_VER}/Resources/Python.app/Contents/MacOS/:$PATH
python3 -VV
python3-config --includes
# if python3 -VV does not contain ${PY_VER}, then exit
if ! python3 -VV 2>&1 | grep -q "${PY_VER}"; then
echo "Error: Required version of Python (${PY_VER}) not found. Aborting."
exit 1
fi
# if python3-config --includes does not contain ${PY_SHORT_VER}, then exit
if ! python3-config --includes 2>&1 | grep -q "${PY_SHORT_VER}"; then
echo "Error: Required version of Python (${PY_VER}) not found. Aborting."
exit 1
fi

python3 -m pip install -U pybind11 wheel build tox
rm -rf ${PROJ_DIR}/buildlib

${PROJ_DIR}/chdb/build.sh
cd ${PROJ_DIR}/chdb && python3 -c "import _chdb; res = _chdb.query('select 1112222222,555', 'JSON'); print(res.get_memview().tobytes())"

cd ${PROJ_DIR}
${PROJ_DIR}/gen_manifest.sh
cat ${PROJ_DIR}/MANIFEST.in

python3 -m build --wheel

python3 -m wheel tags --platform-tag=macosx_11_0_arm64 --remove dist/chdb-*-cp${PY_SHORT_VER//./}-cp${PY_SHORT_VER//./}-macosx_*_universal2.whl

python3 -m pip install --force-reinstall dist/chdb-*-cp${PY_SHORT_VER//./}-cp${PY_SHORT_VER//./}-macosx_11_0_arm64.whl

python3 -c "import chdb; res = chdb.query('select version()', 'CSV'); print(str(res.get_memview().tobytes()))"
done

cd ${PROJ_DIR}
make pub

0 comments on commit ab2afa8

Please sign in to comment.