Skip to content

Commit c9adb35

Browse files
authored
Merge pull request #428 from wudidapaopao/cross_compile
Support cross-compilation for macOS
2 parents b6a0af3 + 501c642 commit c9adb35

27 files changed

+1506
-470
lines changed

.github/workflows/build_linux_arm64_wheels-gh.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ on:
2323

2424
jobs:
2525
build_universal_wheel:
26-
name: Build Universal Wheel (Linux ARM64)
26+
name: Build Universal Wheel (Linux arm64)
2727
runs-on: GH-Linux-ARM64
2828
if: ${{ !github.event.pull_request.draft }}
2929
steps:

.github/workflows/build_linux_x86_wheels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build Linux X86
1+
name: Build Linux x86_64
22

33
on:
44
workflow_dispatch:

.github/workflows/build_macos_arm64_wheels.yml

Lines changed: 132 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,119 @@ on:
2121
- '**/*.md'
2222

2323
jobs:
24-
build_universal_wheel:
25-
name: Build Universal Wheel (macOS ARM64)
24+
build_universal_wheel_on_linux:
25+
name: Build on Linux (cross-compile for macOS arm64)
26+
runs-on: GH-Linux-ARM64
27+
if: ${{ !github.event.pull_request.draft }}
28+
timeout-minutes: 600
29+
steps:
30+
- name: Install Python build dependencies
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
34+
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
35+
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev \
36+
libffi-dev liblzma-dev p7zip-full
37+
- name: Upgrade Rust toolchain
38+
run: |
39+
rustup toolchain install nightly-2025-07-07
40+
rustup default nightly-2025-07-07
41+
rustup component add rust-src
42+
rustc --version
43+
cargo --version
44+
- name: Install clang++ for Ubuntu
45+
run: |
46+
pwd
47+
uname -a
48+
wget https://apt.llvm.org/llvm.sh
49+
chmod +x llvm.sh
50+
sudo ./llvm.sh 19
51+
which clang++-19
52+
clang++-19 --version
53+
sudo apt-get install -y make cmake ccache ninja-build yasm gawk wget
54+
# Install WebAssembly linker (wasm-ld)
55+
sudo apt-get install -y lld-19
56+
# Create symlink for wasm-ld
57+
if ! command -v wasm-ld &> /dev/null; then
58+
sudo ln -sf /usr/bin/wasm-ld-19 /usr/bin/wasm-ld || true
59+
fi
60+
which wasm-ld || echo "wasm-ld not found in PATH"
61+
ccache -s
62+
- name: Update git
63+
run: |
64+
sudo add-apt-repository ppa:git-core/ppa -y
65+
sudo apt-get update
66+
sudo apt-get install -y git
67+
git --version
68+
- uses: actions/checkout@v3
69+
with:
70+
fetch-depth: 0
71+
- name: Update submodules
72+
run: |
73+
git submodule update --init --recursive --jobs 4
74+
- name: ccache
75+
uses: hendrikmuhs/[email protected]
76+
with:
77+
key: ubuntu-24.04-aarch64-cross-compile
78+
max-size: 5G
79+
append-timestamp: true
80+
- name: remove old clang and link clang-19 to clang
81+
run: |
82+
sudo rm -f /usr/bin/clang || true
83+
sudo ln -s /usr/bin/clang-19 /usr/bin/clang
84+
sudo rm -f /usr/bin/clang++ || true
85+
sudo ln -s /usr/bin/clang++-19 /usr/bin/clang++
86+
which clang++
87+
clang++ --version
88+
- name: Run chdb/build_mac_on_linux.sh
89+
timeout-minutes: 600
90+
run: |
91+
source ~/.cargo/env
92+
bash ./chdb/build_mac_on_linux.sh arm64
93+
continue-on-error: false
94+
- name: Run chdb/build/build_static_lib_mac_on_linux.sh
95+
timeout-minutes: 600
96+
run: |
97+
source ~/.cargo/env
98+
bash ./chdb/build/build_static_lib_mac_on_linux.sh arm64
99+
continue-on-error: false
100+
- name: Check ccache statistics
101+
run: |
102+
ccache -s
103+
ls -lh chdb
104+
df -h
105+
- name: Keep killall ccache and wait for ccache to finish
106+
if: always()
107+
run: |
108+
sleep 60
109+
while ps -ef | grep ccache | grep -v grep; do \
110+
killall ccache; \
111+
sleep 10; \
112+
done
113+
- name: Upload build artifacts
114+
uses: actions/upload-artifact@v4
115+
with:
116+
name: macos-arm64-build-artifacts
117+
path: |
118+
./libchdb.so
119+
./libchdb.a
120+
./chdb/_chdb.abi3.so
121+
./chdb/libpybind11nonlimitedapi_stubs.dylib
122+
./chdb/libpybind11nonlimitedapi_chdb_3.8.dylib
123+
./chdb/libpybind11nonlimitedapi_chdb_3.9.dylib
124+
./chdb/libpybind11nonlimitedapi_chdb_3.10.dylib
125+
./chdb/libpybind11nonlimitedapi_chdb_3.11.dylib
126+
./chdb/libpybind11nonlimitedapi_chdb_3.12.dylib
127+
./chdb/libpybind11nonlimitedapi_chdb_3.13.dylib
128+
./chdb/libpybind11nonlimitedapi_chdb_3.14.dylib
129+
retention-days: 1
130+
131+
test_on_macos:
132+
name: Test on macOS arm64
26133
runs-on: macos-14-xlarge
134+
needs: build_universal_wheel_on_linux
27135
if: ${{ !github.event.pull_request.draft }}
136+
timeout-minutes: 600
28137
steps:
29138
- name: Check machine architecture
30139
run: |
@@ -39,17 +148,6 @@ jobs:
39148
else
40149
echo "This is an x86_64 (Intel) machine"
41150
fi
42-
- name: Free up disk space (Initial)
43-
run: |
44-
# Clean Homebrew cache
45-
brew cleanup -s 2>/dev/null || true
46-
rm -rf "$(brew --cache)" 2>/dev/null || true
47-
sudo rm -rf ~/Library/Developer/Xcode/DerivedData 2>/dev/null || true
48-
sudo rm -rf ~/Library/Caches/com.apple.dt.Xcode 2>/dev/null || true
49-
sudo rm -rf /Users/runner/Library/Android 2>/dev/null || true
50-
sudo rm -rf /tmp/* 2>/dev/null || true
51-
echo "=== Disk usage after cleanup ==="
52-
df -h
53151
- name: Setup pyenv
54152
run: |
55153
curl https://pyenv.run | bash
@@ -97,39 +195,14 @@ jobs:
97195
- name: Remove /usr/local/bin/python3
98196
run: |
99197
sudo rm -f /usr/local/bin/python3
100-
- name: Install clang++ for macOS
198+
- name: Install go for macOS
101199
run: |
102-
pwd
103-
uname -a
104-
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
105200
brew update
106-
brew install ca-certificates lz4 mpdecimal readline sqlite xz z3 zstd
107-
brew install openssl@3 || echo "OpenSSL install failed, continuing..."
108-
brew install --ignore-dependencies llvm@19
109-
brew install git ninja libtool gettext binutils grep findutils nasm lld@19 libiconv
110-
brew install ccache || echo "ccache installation failed, continuing without it"
111201
brew install go
112-
cd /usr/local/opt/ && sudo rm -f llvm && sudo ln -sf llvm@19 llvm
113-
export PATH=$(brew --prefix llvm@19)/bin:$(brew --prefix lld@19)/bin:$PATH
114-
which clang++
115-
clang++ --version
116-
which wasm-ld || echo "wasm-ld not found in PATH"
117-
which go
118202
go version
119-
ccache -s | echo "ccache not available yet"
120-
- name: Upgrade Rust toolchain
121-
run: |
122-
rustup toolchain install nightly-2025-07-07
123-
rustup default nightly-2025-07-07
124-
rustup component add rust-src
125-
rustc --version
126-
cargo --version
127203
- uses: actions/checkout@v3
128204
with:
129205
fetch-depth: 0
130-
- name: Update submodules
131-
run: |
132-
git submodule update --init --recursive --jobs 4
133206
- name: Update version for release
134207
if: startsWith(github.ref, 'refs/tags/v')
135208
run: |
@@ -143,89 +216,34 @@ jobs:
143216
bump-my-version replace --new-version $TAG_NAME
144217
echo "Version files updated to $TAG_NAME"
145218
pyenv shell --unset
146-
- name: Free up disk space (Before compilation)
147-
run: |
148-
echo "=== Disk usage before compilation cleanup ==="
149-
df -h
150-
brew cleanup -s 2>/dev/null || true
151-
rm -rf "$(brew --cache)" 2>/dev/null || true
152-
rm -rf ~/.cache/pip 2>/dev/null || true
153-
rm -rf ~/.pyenv/.cache 2>/dev/null || true
154-
rm -rf ~/.cargo/registry/cache 2>/dev/null || true
155-
echo "=== Disk usage after cleanup ==="
156-
df -h
157-
- name: ccache
158-
uses: hendrikmuhs/[email protected]
219+
- name: Download build artifacts
220+
uses: actions/download-artifact@v4
159221
with:
160-
key: ${{ runner.os }}-arm64-ccache
161-
max-size: 5G
162-
append-timestamp: true
163-
- name: Run chdb/build.sh
222+
name: macos-arm64-build-artifacts
223+
path: ./artifacts
224+
- name: Restore artifacts to original paths
225+
run: |
226+
mv ./artifacts/libchdb.so ./
227+
mv ./artifacts/libchdb.a ./
228+
mv ./artifacts/chdb/_chdb.abi3.so ./chdb/
229+
mv ./artifacts/chdb/libpybind11nonlimitedapi_stubs.dylib ./chdb/
230+
for v in 8 9 10 11 12 13 14; do
231+
mv ./artifacts/chdb/libpybind11nonlimitedapi_chdb_3.${v}.dylib ./chdb/
232+
done
233+
ls -lh ./libchdb.so ./libchdb.a
234+
ls -lh ./chdb/*.so ./chdb/*.dylib
235+
- name: Run chdb/test_smoke.sh
164236
timeout-minutes: 600
165237
run: |
166238
export PATH="$HOME/.pyenv/bin:$PATH"
167239
eval "$(pyenv init -)"
168-
source ~/.cargo/env
169240
pyenv shell 3.8
170-
export PATH=$(brew --prefix llvm@19)/bin:$(brew --prefix lld@19)/bin:/usr/local/opt/grep/libexec/gnubin:/usr/local/opt/binutils/bin:$PATH:/usr/local/opt/findutils/libexec/gnubin
171-
export CC=$(brew --prefix llvm@19)/bin/clang
172-
export CXX=$(brew --prefix llvm@19)/bin/clang++
173241
bash gen_manifest.sh
174-
bash ./chdb/build.sh
175-
pyenv shell 3.8
176-
bash -x ./chdb/test_smoke.sh
177-
- name: Run chdb/build/build_static_lib.sh
242+
bash -x ./chdb/test_smoke.sh cross-compile
243+
- name: Run chdb/build/test_go_example.sh
178244
timeout-minutes: 600
179245
run: |
180-
export PATH=$HOME/.pyenv/bin:$(brew --prefix llvm@19)/bin:$(brew --prefix lld@19)/bin:/usr/local/opt/grep/libexec/gnubin:/usr/local/opt/binutils/bin:$PATH:/usr/local/opt/findutils/libexec/gnubin
181-
export CC=$(brew --prefix llvm@19)/bin/clang
182-
export CXX=$(brew --prefix llvm@19)/bin/clang++
183-
source ~/.cargo/env
184-
eval "$(pyenv init -)"
185-
pyenv shell 3.8
186-
bash ./chdb/build/build_static_lib.sh
187-
pyenv shell --unset
188-
continue-on-error: false
189-
- name: Debug libchdb
190-
run: |
191-
ls -lh
192-
llvm-nm libchdb.so | grep query_stable || true
193-
echo "Global Symbol in libchdb.so:"
194-
llvm-nm -g libchdb.so || true
195-
echo "Global Symbol in libclickhouse-local-chdb.a:"
196-
llvm-nm -g buildlib/programs/local/libclickhouse-local-chdb.a || true
197-
echo "Global Symbol in libclickhouse-local-lib.a:"
198-
llvm-nm -g buildlib/programs/local/libclickhouse-local-lib.a || true
199-
echo "pychdb_cmd.sh:"
200-
cat buildlib/pychdb_cmd.sh
201-
echo "libchdb_cmd.sh:"
202-
cat buildlib/libchdb_cmd.sh
203-
- name: Scan chdb libraries with grype
204-
run: |
205-
echo "Scanning chdb libraries for vulnerabilities..."
206-
# Files to scan
207-
FILES_TO_SCAN=""
208-
[ -f libchdb.so ] && FILES_TO_SCAN="$FILES_TO_SCAN libchdb.so"
209-
[ -f libchdb.a ] && FILES_TO_SCAN="$FILES_TO_SCAN libchdb.a"
210-
FILES_TO_SCAN="$FILES_TO_SCAN $(find chdb/ \( -name "*.dylib" -o -name "*.so" \) 2>/dev/null || true)"
211-
SQLITE_VULNERABILITIES_FOUND=false
212-
for file in $FILES_TO_SCAN; do
213-
if [ -f "$file" ]; then
214-
echo "=== Scanning $file ==="
215-
SCAN_OUTPUT=$(grype "$file" 2>/dev/null || true)
216-
echo "$SCAN_OUTPUT"
217-
if echo "$SCAN_OUTPUT" | grep -qi sqlite; then
218-
echo "❌ SQLite vulnerability found in $file"
219-
SQLITE_VULNERABILITIES_FOUND=true
220-
fi
221-
fi
222-
done
223-
if [ "$SQLITE_VULNERABILITIES_FOUND" = true ]; then
224-
echo "❌ SQLite vulnerabilities detected in chdb libraries!"
225-
exit 1
226-
else
227-
echo "✅ No SQLite vulnerabilities found in chdb libraries"
228-
fi
246+
bash ./chdb/build/test_go_example.sh ${{ github.workspace }}/libchdb.a
229247
continue-on-error: false
230248
- name: Run libchdb stub in examples dir
231249
run: |
@@ -236,9 +254,6 @@ jobs:
236254
rm -rf chdb/build/
237255
export PATH="$HOME/.pyenv/bin:$PATH"
238256
eval "$(pyenv init -)"
239-
export PATH=$(brew --prefix llvm@19)/bin:$(brew --prefix lld@19)/bin:/usr/local/opt/grep/libexec/gnubin:/usr/local/opt/binutils/bin:$PATH:/usr/local/opt/findutils/libexec/gnubin
240-
export CC=$(brew --prefix llvm@19)/bin/clang
241-
export CXX=$(brew --prefix llvm@19)/bin/clang++
242257
pyenv shell 3.8
243258
make wheel
244259
- name: Fix wheel platform tag
@@ -257,12 +272,6 @@ jobs:
257272
sudo sysctl kern.corefile=$PWD/tmp/core/core.%P
258273
sudo sysctl kern.coredump=1
259274
ulimit -c unlimited
260-
- name: Free up disk space
261-
run: |
262-
# Clean more build artifacts
263-
rm -rf buildlib/contrib 2>/dev/null || true
264-
rm -rf buildlib/base 2>/dev/null || true
265-
rm -rf buildlib/src 2>/dev/null || true
266275
- name: Test wheel on all Python versions
267276
run: |
268277
ulimit -c unlimited
@@ -282,7 +291,7 @@ jobs:
282291
run: |
283292
export PATH="$HOME/.pyenv/bin:$PATH"
284293
eval "$(pyenv init -)"
285-
pyenv shell 3.8
294+
pyenv shell 3.9
286295
python -m pip install dist/*.whl --force-reinstall
287296
jupyter nbconvert --to notebook --execute tests/test_data_insertion.ipynb --output test_data_insertion_output.ipynb
288297
pyenv shell --unset
@@ -300,14 +309,6 @@ jobs:
300309
echo "No core files found in tmp/core"
301310
fi
302311
continue-on-error: true
303-
- name: Keep killall ccache and wait for ccache to finish
304-
if: always()
305-
run: |
306-
sleep 60
307-
while ps -ef | grep ccache | grep -v grep; do \
308-
killall ccache; \
309-
sleep 10; \
310-
done
311312
- name: Upload core files artifact
312313
if: always() && env.CORE_FILES_FOUND == 'true'
313314
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)