-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlocal-build.sh
More file actions
executable file
·188 lines (156 loc) · 4.43 KB
/
local-build.sh
File metadata and controls
executable file
·188 lines (156 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env bash
# local-build.sh -- Unified wheel build entrypoint.
#
# Usage:
# ./local-build.sh <llvm-ref> [platform]
#
# Platforms:
# local (default): host macOS target local build, host Linux target Docker manylinux
# x86-64-macos | arm-64-macos: local build
# x86-64-linux | x86-32-linux | arm-64-linux | arm-32-linux: Docker manylinux build
set -euo pipefail
usage() {
cat >&2 <<'USAGE'
Usage: ./local-build.sh <llvm-ref> [platform]
Platforms:
local (default) Host platform (macOS local, Linux via manylinux Docker)
x86-64-macos Local macOS x86-64 build
arm-64-macos Local macOS ARM64 build
x86-64-linux manylinux_2_28_x86_64 (Docker)
x86-32-linux manylinux_2_28_i686 (Docker)
arm-64-linux manylinux_2_28_aarch64 (Docker)
arm-32-linux manylinux_2_31_armv7l (Docker)
USAGE
}
resolve_platform() {
local requested="$1"
local host_os host_arch
if [[ "$requested" != "local" ]]; then
echo "$requested"
return
fi
host_os="$(uname -s)"
host_arch="$(uname -m)"
case "$host_os/$host_arch" in
Darwin/x86_64) echo "x86-64-macos" ;;
Darwin/arm64) echo "arm-64-macos" ;;
Linux/x86_64) echo "x86-64-linux" ;;
Linux/aarch64) echo "arm-64-linux" ;;
*)
echo "error: unsupported host for local platform: $host_os/$host_arch" >&2
exit 1
;;
esac
}
run_local_macos_build() {
local platform="$1"
local toolchain_path dist_dir host_os host_arch
case "$platform" in
x86-64-macos|arm-64-macos) ;;
*)
echo "error: unsupported local platform: $platform" >&2
exit 1
;;
esac
host_os="$(uname -s)"
host_arch="$(uname -m)"
if [[ "$host_os" != "Darwin" ]]; then
echo "error: local macOS build requested, but host is $host_os/$host_arch" >&2
exit 1
fi
toolchain_path="toolchains/$platform.cmake"
export MACOSX_DEPLOYMENT_TARGET=11
dist_dir="dist/$platform"
mkdir -p "$dist_dir"
if [[ ! -d .venv ]]; then
echo "Creating virtual environment..."
uv venv .venv
fi
echo "Installing build dependencies..."
uv pip install --quiet "scikit-build-core>=0.10"
local config_settings=(
"--config-settings=cmake.define.CMAKE_TOOLCHAIN_FILE=$toolchain_path"
)
if command -v ccache &>/dev/null; then
config_settings+=(
"--config-settings=cmake.define.CMAKE_C_COMPILER_LAUNCHER=ccache"
"--config-settings=cmake.define.CMAKE_CXX_COMPILER_LAUNCHER=ccache"
)
fi
echo "Building halide-llvm (local macOS)"
echo " HALIDE_LLVM_REF: $HALIDE_LLVM_REF"
echo " Platform: $platform"
echo " Toolchain: $toolchain_path"
echo " Output: $dist_dir/"
uv build --wheel -v --no-build-isolation --out-dir "$dist_dir" "${config_settings[@]}"
}
run_linux_docker_build() {
local platform="$1"
local image dist_dir
local toolchain="toolchains/$platform.cmake"
case "$platform" in
x86-64-linux)
image="quay.io/pypa/manylinux_2_28_x86_64"
;;
x86-32-linux)
image="quay.io/pypa/manylinux_2_28_i686"
;;
arm-64-linux)
image="quay.io/pypa/manylinux_2_28_aarch64"
;;
arm-32-linux)
image="quay.io/pypa/manylinux_2_31_armv7l"
;;
*)
echo "error: unsupported Linux Docker platform: $platform" >&2
exit 1
;;
esac
dist_dir="dist/$platform"
mkdir -p "$dist_dir"
echo "Building halide-llvm (manylinux Docker)"
echo " HALIDE_LLVM_REF: $HALIDE_LLVM_REF"
echo " Platform: $platform"
echo " Image: $image"
echo " Output: $dist_dir/"
docker run --rm \
-v "$(pwd):/project" \
-w /project \
-e "HALIDE_LLVM_REF=$HALIDE_LLVM_REF" \
"$image" \
bash -c "
set -euo pipefail
export PATH=/opt/python/cp312-cp312/bin:\$PATH
pip wheel . -w $dist_dir/ -v \
--config-settings=cmake.define.CMAKE_TOOLCHAIN_FILE=$toolchain
pip install auditwheel
auditwheel repair -w $dist_dir/ $dist_dir/*.whl
rm -f $dist_dir/*-linux_*.whl
echo
echo 'Built wheels:'
ls -lh $dist_dir/*.whl
"
}
REF="${1:-}"
REQUESTED_PLATFORM="${2:-local}"
if [[ -z "$REF" || "$#" -gt 2 ]]; then
usage
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
export HALIDE_LLVM_REF="$REF"
PLATFORM="$(resolve_platform "$REQUESTED_PLATFORM")"
case "$PLATFORM" in
x86-64-macos|arm-64-macos)
run_local_macos_build "$PLATFORM"
;;
x86-64-linux|x86-32-linux|arm-64-linux|arm-32-linux)
run_linux_docker_build "$PLATFORM"
;;
*)
echo "error: unknown platform: $PLATFORM" >&2
usage
exit 1
;;
esac