Skip to content

Commit c45e50c

Browse files
committed
Make mac-arm64 for apple silicon(M1, M2)
1 parent 81dcf3d commit c45e50c

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# auto generated files
1111
*.logrt
1212

13+
/python_pkg/
1314
/chdb-0.*/
1415
*.strings
1516
/arrow1100

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all clean buildlib wheel pub
1+
.PHONY: all clean buildlib wheel pub mac-arm64
22

33
buildlib:
44
@echo "Building library..."
@@ -20,5 +20,9 @@ clean:
2020
tox -e clean
2121
@echo "Done."
2222

23+
mac-arm64:
24+
@echo "Make macOS arm64 whl"
25+
bash packages/build_mac_arm64.sh
26+
@echo "Done."
2327

2428
build: clean buildlib wheel

gen_manifest.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
#!/bin/bash
2+
3+
set -e
4+
5+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6+
7+
cd ${DIR}
8+
29
echo "include chdb/*.py" > MANIFEST.in
310
export SO_SUFFIX=$(python3 -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
411
echo "include chdb/_chdb${SO_SUFFIX}" >> MANIFEST.in

packages/build_mac_arm64.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/arch -arm64 /bin/bash
2+
3+
set -e
4+
5+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6+
PROJ_DIR=$(dirname ${DIR})
7+
8+
cd ${PROJ_DIR}
9+
10+
# Download py39 py310 py311 universal2 pkg from python.org
11+
if [ ! -d ${PROJ_DIR}/python_pkg ]; then
12+
mkdir ${PROJ_DIR}/python_pkg
13+
fi
14+
15+
# prefer /usr/local/opt/llvm@15/bin/clang++ then /usr/local/opt/llvm/bin/clang++
16+
if [ -f /usr/local/opt/llvm@15/bin/clang++ ]; then
17+
export CXX=/usr/local/opt/llvm@15/bin/clang++
18+
elif [ -f /usr/local/opt/llvm/bin/clang++ ]; then
19+
export CXX=/usr/local/opt/llvm/bin/clang++
20+
fi
21+
if [ -f /usr/local/opt/llvm@15/bin/clang ]; then
22+
export CC=/usr/local/opt/llvm@15/bin/clang
23+
elif [ -f /usr/local/opt/llvm/bin/clang ]; then
24+
export CC=/usr/local/opt/llvm/bin/clang
25+
fi
26+
27+
for PY_VER in 3.9.13 3.10.11 3.11.3; do
28+
if [ ! -f ${PROJ_DIR}/python_pkg/python-${PY_VER}-macos11.pkg ]; then
29+
wget https://www.python.org/ftp/python/${PY_VER}/python-${PY_VER}-macos11.pkg -O ${PROJ_DIR}/python_pkg/python-${PY_VER}-macos11.pkg
30+
fi
31+
32+
PY_SHORT_VER=$(echo ${PY_VER} | cut -d. -f1,2)
33+
# Install universal2 pkg
34+
sudo installer -pkg ${PROJ_DIR}/python_pkg/python-${PY_VER}-macos11.pkg -target /
35+
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
36+
python3 -VV
37+
python3-config --includes
38+
# if python3 -VV does not contain ${PY_VER}, then exit
39+
if ! python3 -VV 2>&1 | grep -q "${PY_VER}"; then
40+
echo "Error: Required version of Python (${PY_VER}) not found. Aborting."
41+
exit 1
42+
fi
43+
# if python3-config --includes does not contain ${PY_SHORT_VER}, then exit
44+
if ! python3-config --includes 2>&1 | grep -q "${PY_SHORT_VER}"; then
45+
echo "Error: Required version of Python (${PY_VER}) not found. Aborting."
46+
exit 1
47+
fi
48+
49+
python3 -m pip install -U pybind11 wheel build tox
50+
rm -rf ${PROJ_DIR}/buildlib
51+
52+
${PROJ_DIR}/chdb/build.sh
53+
cd ${PROJ_DIR}/chdb && python3 -c "import _chdb; res = _chdb.query('select 1112222222,555', 'JSON'); print(res.get_memview().tobytes())"
54+
55+
cd ${PROJ_DIR}
56+
${PROJ_DIR}/gen_manifest.sh
57+
cat ${PROJ_DIR}/MANIFEST.in
58+
59+
python3 -m build --wheel
60+
61+
python3 -m wheel tags --platform-tag=macosx_11_0_arm64 --remove dist/chdb-*-cp${PY_SHORT_VER//./}-cp${PY_SHORT_VER//./}-macosx_*_universal2.whl
62+
63+
python3 -m pip install --force-reinstall dist/chdb-*-cp${PY_SHORT_VER//./}-cp${PY_SHORT_VER//./}-macosx_11_0_arm64.whl
64+
65+
python3 -c "import chdb; res = chdb.query('select version()', 'CSV'); print(str(res.get_memview().tobytes()))"
66+
done
67+
68+
cd ${PROJ_DIR}
69+
make pub
70+

0 commit comments

Comments
 (0)