-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-vendor.sh
More file actions
executable file
·261 lines (239 loc) · 8.97 KB
/
build-vendor.sh
File metadata and controls
executable file
·261 lines (239 loc) · 8.97 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
VENDOR_DIR="$PROJECT_ROOT/vendor"
C_BRIDGES_DIR="$PROJECT_ROOT/c_bridges"
NPROC=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
# Load pinned versions
source "$SCRIPT_DIR/vendor-pins.sh"
mkdir -p "$VENDOR_DIR"
# --- bdwgc (Boehm GC) ---
if [ ! -f "$VENDOR_DIR/bdwgc/libgc.a" ]; then
echo "==> Building bdwgc..."
cd "$VENDOR_DIR"
if [ ! -d bdwgc ]; then
git clone --depth 1 --branch "$BDWGC_TAG" https://github.com/ivmai/bdwgc.git
fi
cd bdwgc
# Ensure compiler atomics are used (avoids libatomic_ops dependency)
if ! grep -q 'CHADSCRIPT_PATCHED' include/private/gcconfig.h; then
{ printf '/* CHADSCRIPT_PATCHED */\n#ifndef GC_BUILTIN_ATOMIC\n#define GC_BUILTIN_ATOMIC 1\n#endif\n'; cat include/private/gcconfig.h; } > /tmp/gcconfig_patched.h
mv /tmp/gcconfig_patched.h include/private/gcconfig.h
fi
mkdir -p build && cd build
cmake .. \
-DCMAKE_C_FLAGS="-fPIC" \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_TESTING=OFF \
-Denable_cplusplus=OFF -Denable_docs=OFF -Dwithout_libatomic_ops=ON
make -j"$NPROC"
mkdir -p "$VENDOR_DIR/bdwgc"
if [ -f libgc.a ]; then
cp libgc.a "$VENDOR_DIR/bdwgc/"
else
find CMakeFiles/gc.dir -name "*.o" -exec ar rcs "$VENDOR_DIR/bdwgc/libgc.a" {} +
fi
echo " -> $VENDOR_DIR/bdwgc/libgc.a"
else
echo "==> bdwgc already built, skipping"
fi
# --- picohttpparser ---
if [ ! -f "$VENDOR_DIR/picohttpparser/picohttpparser.o" ]; then
echo "==> Building picohttpparser..."
cd "$VENDOR_DIR"
if [ ! -f picohttpparser/picohttpparser.c ]; then
git clone --depth 1 https://github.com/h2o/picohttpparser.git picohttpparser-src
if [ -n "$PICOHTTPPARSER_COMMIT" ]; then
git -C picohttpparser-src fetch --depth 1 origin "$PICOHTTPPARSER_COMMIT"
git -C picohttpparser-src checkout "$PICOHTTPPARSER_COMMIT"
fi
mkdir -p picohttpparser
cp picohttpparser-src/picohttpparser.h picohttpparser-src/picohttpparser.c picohttpparser/
rm -rf picohttpparser-src
fi
cd picohttpparser
SSE_FLAGS=""
if [ "$(uname -m)" = "x86_64" ]; then
SSE_FLAGS="-msse4.2"
fi
cc -c -O2 -fPIC $SSE_FLAGS picohttpparser.c -o picohttpparser.o
echo " -> $VENDOR_DIR/picohttpparser/picohttpparser.o"
else
echo "==> picohttpparser already built, skipping"
fi
# --- yyjson ---
if [ ! -f "$VENDOR_DIR/yyjson/libyyjson.a" ] || [ "$C_BRIDGES_DIR/yyjson-bridge.c" -nt "$VENDOR_DIR/yyjson/libyyjson.a" ]; then
echo "==> Building yyjson..."
cd "$VENDOR_DIR"
if [ ! -d yyjson ]; then
mkdir -p yyjson
fi
if [ ! -f yyjson/yyjson.c ]; then
git clone --depth 1 --branch "$YYJSON_TAG" https://github.com/ibireme/yyjson.git yyjson-src
cp yyjson-src/src/yyjson.h yyjson-src/src/yyjson.c yyjson/
rm -rf yyjson-src
fi
cd yyjson
cc -c -O2 -fPIC yyjson.c -o yyjson.o
cc -c -O2 -fPIC -I"$VENDOR_DIR/yyjson" "$C_BRIDGES_DIR/yyjson-bridge.c" -o yyjson-bridge.o
ar rcs libyyjson.a yyjson.o yyjson-bridge.o
echo " -> $VENDOR_DIR/yyjson/libyyjson.a"
else
echo "==> yyjson already built, skipping"
fi
# --- libuv ---
if [ ! -f "$VENDOR_DIR/libuv/build/libuv.a" ]; then
echo "==> Building libuv..."
cd "$VENDOR_DIR"
if [ ! -d libuv ]; then
git clone --depth 1 --branch "$LIBUV_TAG" https://github.com/libuv/libuv.git
fi
mkdir -p libuv/build
cd libuv/build
cmake .. \
-DCMAKE_C_FLAGS="-fPIC" \
-DBUILD_TESTING=OFF \
-DLIBUV_BUILD_SHARED=OFF
make -j"$NPROC"
echo " -> $VENDOR_DIR/libuv/build/libuv.a"
else
echo "==> libuv already built, skipping"
fi
# --- lws-bridge (must come after libuv and picohttpparser) ---
LWS_BRIDGE_SRC="$C_BRIDGES_DIR/lws-bridge.c"
LWS_BRIDGE_OBJ="$C_BRIDGES_DIR/lws-bridge.o"
if [ ! -f "$LWS_BRIDGE_OBJ" ] || [ "$LWS_BRIDGE_SRC" -nt "$LWS_BRIDGE_OBJ" ]; then
echo "==> Building lws-bridge..."
EXTRA_CFLAGS=""
if [ "$(uname)" = "Darwin" ]; then
BREW_PREFIX=$(brew --prefix 2>/dev/null || echo "/opt/homebrew")
ZSTD_PREFIX=$(brew --prefix zstd 2>/dev/null || echo "$BREW_PREFIX")
if [ -f "$ZSTD_PREFIX/include/zstd.h" ]; then
EXTRA_CFLAGS="-I$ZSTD_PREFIX/include"
fi
fi
cc -c -O2 -fPIC \
-I"$VENDOR_DIR/libuv/include" \
-I"$VENDOR_DIR/picohttpparser" \
$EXTRA_CFLAGS \
"$LWS_BRIDGE_SRC" -o "$LWS_BRIDGE_OBJ"
echo " -> $LWS_BRIDGE_OBJ"
else
echo "==> lws-bridge already built, skipping"
fi
# --- multipart-bridge (multipart/form-data parser) ---
MP_BRIDGE_SRC="$C_BRIDGES_DIR/multipart-bridge.c"
MP_BRIDGE_OBJ="$C_BRIDGES_DIR/multipart-bridge.o"
if [ ! -f "$MP_BRIDGE_OBJ" ] || [ "$MP_BRIDGE_SRC" -nt "$MP_BRIDGE_OBJ" ]; then
echo "==> Building multipart-bridge..."
cc -c -O2 -fPIC "$MP_BRIDGE_SRC" -o "$MP_BRIDGE_OBJ"
echo " -> $MP_BRIDGE_OBJ"
else
echo "==> multipart-bridge already built, skipping"
fi
# --- regex-bridge ---
REGEX_BRIDGE_SRC="$C_BRIDGES_DIR/regex-bridge.c"
REGEX_BRIDGE_OBJ="$C_BRIDGES_DIR/regex-bridge.o"
if [ ! -f "$REGEX_BRIDGE_OBJ" ] || [ "$REGEX_BRIDGE_SRC" -nt "$REGEX_BRIDGE_OBJ" ]; then
echo "==> Building regex-bridge..."
cc -c -O2 -fPIC "$REGEX_BRIDGE_SRC" -o "$REGEX_BRIDGE_OBJ"
echo " -> $REGEX_BRIDGE_OBJ"
else
echo "==> regex-bridge already built, skipping"
fi
# --- dotenv-bridge (auto-loads .env at startup) ---
DOTENV_BRIDGE_SRC="$C_BRIDGES_DIR/dotenv-bridge.c"
DOTENV_BRIDGE_OBJ="$C_BRIDGES_DIR/dotenv-bridge.o"
if [ ! -f "$DOTENV_BRIDGE_OBJ" ] || [ "$DOTENV_BRIDGE_SRC" -nt "$DOTENV_BRIDGE_OBJ" ]; then
echo "==> Building dotenv-bridge..."
cc -c -O2 -fPIC "$DOTENV_BRIDGE_SRC" -o "$DOTENV_BRIDGE_OBJ"
echo " -> $DOTENV_BRIDGE_OBJ"
else
echo "==> dotenv-bridge already built, skipping"
fi
# --- watch-bridge (file watcher for `chad watch`) ---
WATCH_BRIDGE_SRC="$C_BRIDGES_DIR/watch-bridge.c"
WATCH_BRIDGE_OBJ="$C_BRIDGES_DIR/watch-bridge.o"
if [ ! -f "$WATCH_BRIDGE_OBJ" ] || [ "$WATCH_BRIDGE_SRC" -nt "$WATCH_BRIDGE_OBJ" ]; then
echo "==> Building watch-bridge..."
cc -c -O2 -fPIC "$WATCH_BRIDGE_SRC" -o "$WATCH_BRIDGE_OBJ"
echo " -> $WATCH_BRIDGE_OBJ"
else
echo "==> watch-bridge already built, skipping"
fi
# --- child-process-bridge (sync only, no libuv dependency) ---
CP_BRIDGE_SRC="$C_BRIDGES_DIR/child-process-bridge.c"
CP_BRIDGE_OBJ="$C_BRIDGES_DIR/child-process-bridge.o"
if [ ! -f "$CP_BRIDGE_OBJ" ] || [ "$CP_BRIDGE_SRC" -nt "$CP_BRIDGE_OBJ" ]; then
echo "==> Building child-process-bridge..."
cc -c -O2 -fPIC "$CP_BRIDGE_SRC" -o "$CP_BRIDGE_OBJ"
echo " -> $CP_BRIDGE_OBJ"
else
echo "==> child-process-bridge already built, skipping"
fi
# --- time-bridge (platform-abstracted high-resolution time) ---
TIME_BRIDGE_SRC="$C_BRIDGES_DIR/time-bridge.c"
TIME_BRIDGE_OBJ="$C_BRIDGES_DIR/time-bridge.o"
if [ ! -f "$TIME_BRIDGE_OBJ" ] || [ "$TIME_BRIDGE_SRC" -nt "$TIME_BRIDGE_OBJ" ]; then
echo "==> Building time-bridge..."
cc -c -O2 -fPIC "$TIME_BRIDGE_SRC" -o "$TIME_BRIDGE_OBJ"
echo " -> $TIME_BRIDGE_OBJ"
else
echo "==> time-bridge already built, skipping"
fi
# --- os-bridge (platform-abstracted os.freemem/os.uptime) ---
OS_BRIDGE_SRC="$C_BRIDGES_DIR/os-bridge.c"
OS_BRIDGE_OBJ="$C_BRIDGES_DIR/os-bridge.o"
if [ ! -f "$OS_BRIDGE_OBJ" ] || [ "$OS_BRIDGE_SRC" -nt "$OS_BRIDGE_OBJ" ]; then
echo "==> Building os-bridge..."
cc -c -O2 -fPIC "$OS_BRIDGE_SRC" -o "$OS_BRIDGE_OBJ"
echo " -> $OS_BRIDGE_OBJ"
else
echo "==> os-bridge already built, skipping"
fi
# --- base64-bridge ---
BASE64_BRIDGE_SRC="$C_BRIDGES_DIR/base64-bridge.c"
BASE64_BRIDGE_OBJ="$C_BRIDGES_DIR/base64-bridge.o"
if [ ! -f "$BASE64_BRIDGE_OBJ" ] || [ "$BASE64_BRIDGE_SRC" -nt "$BASE64_BRIDGE_OBJ" ]; then
echo "==> Building base64-bridge..."
cc -c -O2 -fPIC "$BASE64_BRIDGE_SRC" -o "$BASE64_BRIDGE_OBJ"
echo " -> $BASE64_BRIDGE_OBJ"
else
echo "==> base64-bridge already built, skipping"
fi
# --- url-bridge ---
URL_BRIDGE_SRC="$C_BRIDGES_DIR/url-bridge.c"
URL_BRIDGE_OBJ="$C_BRIDGES_DIR/url-bridge.o"
if [ ! -f "$URL_BRIDGE_OBJ" ] || [ "$URL_BRIDGE_SRC" -nt "$URL_BRIDGE_OBJ" ]; then
echo "==> Building url-bridge..."
cc -c -O2 -fPIC "$URL_BRIDGE_SRC" -o "$URL_BRIDGE_OBJ"
echo " -> $URL_BRIDGE_OBJ"
else
echo "==> url-bridge already built, skipping"
fi
# --- child-process-spawn (async, requires libuv) ---
CP_SPAWN_SRC="$C_BRIDGES_DIR/child-process-spawn.c"
CP_SPAWN_OBJ="$C_BRIDGES_DIR/child-process-spawn.o"
if [ ! -f "$CP_SPAWN_OBJ" ] || [ "$CP_SPAWN_SRC" -nt "$CP_SPAWN_OBJ" ]; then
echo "==> Building child-process-spawn..."
cc -c -O2 -fPIC -I"$VENDOR_DIR/libuv/include" "$CP_SPAWN_SRC" -o "$CP_SPAWN_OBJ"
echo " -> $CP_SPAWN_OBJ"
else
echo "==> child-process-spawn already built, skipping"
fi
# --- tree-sitter ---
if [ ! -f "$VENDOR_DIR/tree-sitter/libtree-sitter.a" ]; then
echo "==> Building tree-sitter..."
cd "$VENDOR_DIR"
if [ ! -d tree-sitter ]; then
git clone --depth 1 --branch "$TREE_SITTER_TAG" https://github.com/tree-sitter/tree-sitter.git
fi
cd tree-sitter
make -j"$NPROC"
echo " -> $VENDOR_DIR/tree-sitter/libtree-sitter.a"
else
echo "==> tree-sitter already built, skipping"
fi
echo ""
echo "All vendor libraries built successfully in $VENDOR_DIR"