-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·167 lines (143 loc) · 5 KB
/
build.sh
File metadata and controls
executable file
·167 lines (143 loc) · 5 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
#!/bin/bash
set -e
# Check for Clang 16+ (required for full C++20 support)
check_clang_version() {
if ! command -v clang++ &> /dev/null; then
echo "Error: clang++ not found. Please install Clang 16 or later."
echo " Ubuntu/Debian: sudo apt install clang-16"
echo " macOS: brew install llvm"
exit 1
fi
CLANG_VERSION=$(clang++ --version | head -1 | grep -oE '[0-9]+\.[0-9]+' | head -1 | cut -d. -f1)
if [ -z "$CLANG_VERSION" ]; then
echo "Warning: Could not detect Clang version"
elif [ "$CLANG_VERSION" -lt 16 ]; then
echo "Error: Clang $CLANG_VERSION detected. WebCC requires Clang 16+ for full C++20 support."
echo " Ubuntu/Debian: sudo apt install clang-16"
echo " macOS: brew install llvm"
exit 1
fi
}
check_clang_version
# Set linker flags for Homebrew LLVM on macOS (if not already set by parent build)
if [ -z "$LDFLAGS_LIBCXX" ] && [[ "$OSTYPE" == "darwin"* ]]; then
LLVM_PREFIX=$(brew --prefix llvm 2>/dev/null || echo "")
if [ -n "$LLVM_PREFIX" ] && [ -d "$LLVM_PREFIX/lib/c++" ]; then
export LDFLAGS_LIBCXX="-L$LLVM_PREFIX/lib/c++ -Wl,-rpath,$LLVM_PREFIX/lib/c++"
else
echo "Error: Homebrew LLVM not found or incomplete installation."
echo "On macOS, this project requires Homebrew LLVM for proper linking."
echo ""
echo "To fix this:"
echo " brew install llvm"
echo ""
echo "Then add Homebrew LLVM to your PATH by adding this to ~/.zshrc:"
echo " export PATH=\"\$(brew --prefix llvm)/bin:\$PATH\""
echo ""
echo "Or run this command to add it automatically:"
echo " echo 'export PATH=\"\$(brew --prefix llvm)/bin:\$PATH\"' >> ~/.zshrc"
exit 1
fi
fi
FORCE_REBUILD=false
for arg in "$@"; do
case $arg in
--force|-f)
FORCE_REBUILD=true
;;
esac
done
# Force clean if requested
if [ "$FORCE_REBUILD" = true ]; then
rm -rf build webcc schema.wcc.bin
fi
# Create build directories
mkdir -p build/obj
# Run ninja (handles C++ compilation)
NINJA_STATUS=$(ninja -n 2>&1)
if echo "$NINJA_STATUS" | grep -q "no work to do"; then
NEEDS_COMPILE=false
else
NEEDS_COMPILE=true
echo "[WebCC] Building..."
ninja
fi
# Generate schema cache if it doesn't exist or schema.def changed
if [ ! -f "schema.wcc.bin" ] || [ "schema.def" -nt "schema.wcc.bin" ]; then
echo "[WebCC] Generating schema cache..."
./webcc --headers
NEEDS_COMPILE=true # Mark as rebuilt since headers changed
fi
if [ "$NEEDS_COMPILE" = false ]; then
echo "[WebCC] Up to date"
exit 0 # 0 = no rebuild needed
fi
echo "[WebCC] Done."
resolve_install_dir() {
local candidates=()
if [[ "$OSTYPE" == "darwin"* ]]; then
candidates=("/opt/homebrew/bin" "/usr/local/bin")
else
candidates=("/usr/local/bin")
fi
# Prefer a directory that exists and is already in PATH
for dir in "${candidates[@]}"; do
if [ -d "$dir" ] && [[ ":$PATH:" == *":$dir:"* ]]; then
echo "$dir"
return
fi
done
# Fallback to first existing candidate
for dir in "${candidates[@]}"; do
if [ -d "$dir" ]; then
echo "$dir"
return
fi
done
# Last resort for user-local installs
echo "$HOME/.local/bin"
}
# In CI, just exit successfully
if [ -n "$CI" ]; then
exit 0
fi
# Exit code 2 = rebuilt successfully (signals to parent builds that schema changed)
# Check if webcc is already linked correctly
if command -v webcc >/dev/null 2>&1 && [ "$(command -v webcc)" -ef "$PWD/webcc" ]; then
echo "webcc is already configured in PATH."
exit 2 # 2 = rebuilt
fi
# Only offer install in interactive terminals outside CI
if [ -t 0 ] && [ -z "$CI" ]; then
INSTALL_DIR=$(resolve_install_dir)
if [ "$INSTALL_DIR" = "$HOME/.local/bin" ] && [ ! -d "$INSTALL_DIR" ]; then
mkdir -p "$INSTALL_DIR"
fi
echo ""
echo "To use 'webcc' from anywhere, it needs to be in your PATH."
read -p "Would you like to create a symlink in $INSTALL_DIR? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
TARGET="$INSTALL_DIR/webcc"
if [ -w "$INSTALL_DIR" ]; then
ln -sf "$PWD/webcc" "$TARGET"
else
echo "Need sudo access to write to $INSTALL_DIR"
sudo ln -sf "$PWD/webcc" "$TARGET"
fi
echo "Symlink created: $TARGET -> $PWD/webcc"
echo "You can now use 'webcc' command from any directory."
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
echo ""
echo "Note: $INSTALL_DIR is not currently in your PATH."
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Add this to ~/.zshrc:"
echo " export PATH=\"$INSTALL_DIR:\$PATH\""
else
echo "Add this to your shell config (e.g. ~/.bashrc):"
echo " export PATH=\"$INSTALL_DIR:\$PATH\""
fi
fi
fi
fi
exit 2 # 2 = rebuilt (only reached when not in CI)