Skip to content

Commit 6a38371

Browse files
authored
[chore](cloud) add build fdb script (apache#60877)
1 parent d4cc96a commit 6a38371

File tree

1 file changed

+384
-0
lines changed

1 file changed

+384
-0
lines changed

cloud/script/build_fdb.sh

Lines changed: 384 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,384 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#!/bin/bash
18+
19+
set -e
20+
21+
# Default values
22+
VERSION="7.1.55"
23+
BUILD_DIR="./build_output"
24+
DOCKER_IMAGE="foundationdb/build:centos7-latest"
25+
REPO_URL="https://github.com/apple/foundationdb.git"
26+
SRC_DIR="./foundationdb"
27+
UPDATE_REPO=true
28+
29+
# Feature flags (default: all enabled except AWS and Azure backup)
30+
BUILD_AWS_BACKUP=false
31+
BUILD_AZURE_BACKUP=false
32+
USE_JEMALLOC=true
33+
USE_LTO=true
34+
BUILD_DOCUMENTATION=true
35+
WITH_ROCKSDB=true
36+
WITH_GRPC=true
37+
FULL_DEBUG_SYMBOLS=true
38+
39+
# Binding flags (default: only C and Python enabled)
40+
BUILD_C_BINDING=true
41+
BUILD_PYTHON_BINDING=true
42+
BUILD_JAVA_BINDING=false
43+
BUILD_GO_BINDING=false
44+
BUILD_SWIFT_BINDING=false
45+
BUILD_RUBY_BINDING=false
46+
47+
# Colors for output
48+
RED='\033[0;31m'
49+
GREEN='\033[0;32m'
50+
YELLOW='\033[1;33m'
51+
BLUE='\033[0;34m'
52+
NC='\033[0m' # No Color
53+
54+
# Print help message
55+
show_help() {
56+
cat << EOF
57+
Usage: $0 [OPTIONS]
58+
59+
Build FoundationDB using Docker.
60+
61+
Options:
62+
-v VERSION FoundationDB version/tag to build (default: 7.1.55)
63+
-o BUILD_DIR Output directory for build artifacts (default: ./build_output)
64+
-i DOCKER_IMAGE Docker image to use (default: foundationdb/build:centos7-latest)
65+
-s SRC_DIR Source directory (default: ./foundationdb)
66+
-u Skip updating repository
67+
68+
Backup Options:
69+
--aws Enable AWS backup support
70+
--azure Enable Azure backup support
71+
72+
Build Options:
73+
--no-jemalloc Disable jemalloc (default: enabled)
74+
--no-lto Disable Link Time Optimization (default: enabled)
75+
--no-debug-syms Disable full debug symbols (default: enabled)
76+
--no-docs Disable documentation (default: enabled)
77+
--no-rocksdb Disable RocksDB support (default: enabled)
78+
--no-grpc Disable gRPC support (default: enabled)
79+
80+
Binding Options (default: C and Python enabled, others disabled):
81+
--java Enable Java binding
82+
--go Enable Go binding
83+
--swift Enable Swift binding
84+
--ruby Enable Ruby binding
85+
--all-bindings Enable all bindings
86+
--minimal-bindings Enable only C binding
87+
88+
Environment Variables:
89+
FDB_ENABLE_JAVA Enable Java binding (true/false)
90+
FDB_ENABLE_GO Enable Go binding (true/false)
91+
FDB_ENABLE_SWIFT Enable Swift binding (true/false)
92+
FDB_ENABLE_RUBY Enable Ruby binding (true/false)
93+
94+
General:
95+
-h Show this help message
96+
97+
Examples:
98+
$0 # Build with all features (C + Python bindings)
99+
$0 -v 7.3.0 # Build specific version
100+
$0 -v 7.3.0 --aws --azure # Enable AWS + Azure backup
101+
$0 --java --go --swift # Enable additional bindings
102+
$0 --all-bindings # Enable all bindings
103+
$0 --no-grpc --no-rocksdb # Disable specific features
104+
$0 --minimal-bindings # Only C binding
105+
FDB_ENABLE_JAVA=true $0 # Enable Java via env var
106+
107+
EOF
108+
}
109+
110+
# Parse command line arguments
111+
while [[ $# -gt 0 ]]; do
112+
case $1 in
113+
-v)
114+
VERSION="$2"
115+
shift 2
116+
;;
117+
-o)
118+
BUILD_DIR="$2"
119+
shift 2
120+
;;
121+
-i)
122+
DOCKER_IMAGE="$2"
123+
shift 2
124+
;;
125+
-s)
126+
SRC_DIR="$2"
127+
shift 2
128+
;;
129+
-u)
130+
UPDATE_REPO=false
131+
shift
132+
;;
133+
--aws)
134+
BUILD_AWS_BACKUP=true
135+
shift
136+
;;
137+
--azure)
138+
BUILD_AZURE_BACKUP=true
139+
shift
140+
;;
141+
--no-jemalloc)
142+
USE_JEMALLOC=false
143+
shift
144+
;;
145+
--no-lto)
146+
USE_LTO=false
147+
shift
148+
;;
149+
--no-debug-syms)
150+
FULL_DEBUG_SYMBOLS=false
151+
shift
152+
;;
153+
--no-docs)
154+
BUILD_DOCUMENTATION=false
155+
shift
156+
;;
157+
--no-rocksdb)
158+
WITH_ROCKSDB=false
159+
shift
160+
;;
161+
--no-grpc)
162+
WITH_GRPC=false
163+
shift
164+
;;
165+
--debug-syms)
166+
FULL_DEBUG_SYMBOLS=true
167+
shift
168+
;;
169+
--docs)
170+
BUILD_DOCUMENTATION=true
171+
shift
172+
;;
173+
--rocksdb)
174+
WITH_ROCKSDB=true
175+
shift
176+
;;
177+
--grpc)
178+
WITH_GRPC=true
179+
shift
180+
;;
181+
--java)
182+
BUILD_JAVA_BINDING=true
183+
shift
184+
;;
185+
--go)
186+
BUILD_GO_BINDING=true
187+
shift
188+
;;
189+
--swift)
190+
BUILD_SWIFT_BINDING=true
191+
shift
192+
;;
193+
--ruby)
194+
BUILD_RUBY_BINDING=true
195+
shift
196+
;;
197+
--all-bindings)
198+
BUILD_JAVA_BINDING=true
199+
BUILD_GO_BINDING=true
200+
BUILD_SWIFT_BINDING=true
201+
BUILD_RUBY_BINDING=true
202+
shift
203+
;;
204+
--minimal-bindings)
205+
BUILD_PYTHON_BINDING=false
206+
shift
207+
;;
208+
-h)
209+
show_help
210+
exit 0
211+
;;
212+
*)
213+
echo -e "${RED}Unknown option: $1${NC}" >&2
214+
show_help
215+
exit 1
216+
;;
217+
esac
218+
done
219+
220+
# Override bindings from environment variables
221+
if [ "$FDB_ENABLE_JAVA" = "true" ]; then
222+
BUILD_JAVA_BINDING=true
223+
fi
224+
if [ "$FDB_ENABLE_GO" = "true" ]; then
225+
BUILD_GO_BINDING=true
226+
fi
227+
if [ "$FDB_ENABLE_SWIFT" = "true" ]; then
228+
BUILD_SWIFT_BINDING=true
229+
fi
230+
if [ "$FDB_ENABLE_RUBY" = "true" ]; then
231+
BUILD_RUBY_BINDING=true
232+
fi
233+
234+
# Build CMAKE options string
235+
CMAKE_OPTIONS=""
236+
237+
# Base options
238+
CMAKE_OPTIONS+=" -DCMAKE_BUILD_TYPE=Release"
239+
CMAKE_OPTIONS+=" -DFDB_RELEASE=ON"
240+
# CMAKE_OPTIONS+=" -DFORCE_ALL_COMPONENTS=ON"
241+
242+
# Optional features
243+
if [ "$USE_JEMALLOC" = true ]; then
244+
CMAKE_OPTIONS+=" -DUSE_JEMALLOC=ON"
245+
else
246+
CMAKE_OPTIONS+=" -DUSE_JEMALLOC=OFF"
247+
fi
248+
249+
if [ "$USE_LTO" = true ]; then
250+
CMAKE_OPTIONS+=" -DUSE_LTO=ON"
251+
else
252+
CMAKE_OPTIONS+=" -DUSE_LTO=OFF"
253+
fi
254+
255+
if [ "$FULL_DEBUG_SYMBOLS" = true ]; then
256+
CMAKE_OPTIONS+=" -DFULL_DEBUG_SYMBOLS=ON"
257+
fi
258+
259+
if [ "$BUILD_DOCUMENTATION" = true ]; then
260+
CMAKE_OPTIONS+=" -DBUILD_DOCUMENTATION=ON"
261+
fi
262+
263+
if [ "$WITH_ROCKSDB" = true ]; then
264+
CMAKE_OPTIONS+=" -DWITH_ROCKSDB=ON"
265+
fi
266+
267+
if [ "$WITH_GRPC" = true ]; then
268+
CMAKE_OPTIONS+=" -DWITH_GRPC=ON"
269+
fi
270+
271+
# Backup options
272+
if [ "$BUILD_AWS_BACKUP" = true ]; then
273+
CMAKE_OPTIONS+=" -DBUILD_AWS_BACKUP=ON"
274+
fi
275+
276+
if [ "$BUILD_AZURE_BACKUP" = true ]; then
277+
CMAKE_OPTIONS+=" -DBUILD_AZURE_BACKUP=ON"
278+
fi
279+
280+
# Binding options
281+
if [ "$BUILD_C_BINDING" = true ]; then
282+
CMAKE_OPTIONS+=" -DBUILD_C_BINDING=ON"
283+
fi
284+
285+
if [ "$BUILD_PYTHON_BINDING" = true ]; then
286+
CMAKE_OPTIONS+=" -DBUILD_PYTHON_BINDING=ON"
287+
fi
288+
289+
if [ "$BUILD_JAVA_BINDING" = true ]; then
290+
CMAKE_OPTIONS+=" -DBUILD_JAVA_BINDING=ON"
291+
fi
292+
293+
if [ "$BUILD_GO_BINDING" = true ]; then
294+
CMAKE_OPTIONS+=" -DBUILD_GO_BINDING=ON"
295+
fi
296+
297+
if [ "$BUILD_SWIFT_BINDING" = true ]; then
298+
CMAKE_OPTIONS+=" -DBUILD_SWIFT_BINDING=ON"
299+
fi
300+
301+
if [ "$BUILD_RUBY_BINDING" = true ]; then
302+
CMAKE_OPTIONS+=" -DBUILD_RUBY_BINDING=ON"
303+
fi
304+
305+
# Print configuration
306+
echo -e "${GREEN}=== FoundationDB Build Configuration ===${NC}"
307+
echo -e "${BLUE}Basic Settings:${NC}"
308+
echo " Version: $VERSION"
309+
echo " Build Dir: $BUILD_DIR"
310+
echo " Source Dir: $SRC_DIR"
311+
echo " Docker Image: $DOCKER_IMAGE"
312+
echo " Update Repo: $UPDATE_REPO"
313+
echo ""
314+
315+
echo -e "${BLUE}Enabled Features:${NC}"
316+
echo " JEMALLOC: $USE_JEMALLOC"
317+
echo " LTO: $USE_LTO"
318+
echo " Debug Symbols: $FULL_DEBUG_SYMBOLS"
319+
echo " Documentation: $BUILD_DOCUMENTATION"
320+
echo " RocksDB: $WITH_ROCKSDB"
321+
echo " gRPC: $WITH_GRPC"
322+
echo " AWS Backup: $BUILD_AWS_BACKUP"
323+
echo " Azure Backup: $BUILD_AZURE_BACKUP"
324+
echo ""
325+
326+
echo -e "${BLUE}Enabled Bindings:${NC}"
327+
echo " C: $BUILD_C_BINDING"
328+
echo " Python: $BUILD_PYTHON_BINDING"
329+
echo " Java: $BUILD_JAVA_BINDING"
330+
echo " Go: $BUILD_GO_BINDING"
331+
echo " Swift: $BUILD_SWIFT_BINDING"
332+
echo " Ruby: $BUILD_RUBY_BINDING"
333+
echo ""
334+
335+
echo -e "${BLUE}CMake Options:${NC}"
336+
echo "$CMAKE_OPTIONS" | tr ' ' '\n' | grep -v '^$' | sed 's/^/ /'
337+
echo ""
338+
339+
# Pull Docker image
340+
echo -e "${YELLOW}Pulling Docker image...${NC}"
341+
docker pull "$DOCKER_IMAGE"
342+
343+
# Clone or update repository
344+
if [ -d "$SRC_DIR" ]; then
345+
echo -e "${YELLOW}Repository exists...${NC}"
346+
if [ "$UPDATE_REPO" = true ]; then
347+
echo "Updating repository..."
348+
cd "$SRC_DIR"
349+
git fetch origin
350+
git reset --hard origin/main
351+
cd ..
352+
else
353+
echo "Skipping repository update (-u flag set)"
354+
fi
355+
else
356+
echo -e "${YELLOW}Cloning repository...${NC}"
357+
git clone "$REPO_URL" "$SRC_DIR"
358+
fi
359+
360+
# Checkout specific version/tag
361+
echo -e "${YELLOW}Checking out version: $VERSION${NC}"
362+
cd "$SRC_DIR"
363+
git checkout "$VERSION"
364+
cd ..
365+
366+
# Create build output directory
367+
mkdir -p "$BUILD_DIR"
368+
369+
# Run build in container
370+
echo -e "${YELLOW}Starting build...${NC}"
371+
docker run --rm \
372+
-v "$(pwd)/$SRC_DIR:/foundationdb/src:ro" \
373+
-v "$(pwd)/$BUILD_DIR:/foundationdb/build" \
374+
"$DOCKER_IMAGE" \
375+
bash -c "
376+
mkdir -p /foundationdb/build && \
377+
cd /foundationdb/build && \
378+
CC=clang CXX=clang++ LD=lld cmake -B build -D USE_LD=LLD -D USE_LIBCXX=1 -G Ninja $CMAKE_OPTIONS /foundationdb/src && \
379+
ninja -C build
380+
"
381+
382+
echo ""
383+
echo -e "${GREEN}=== Build Complete! ===${NC}"
384+
echo "Artifacts location: $(pwd)/$BUILD_DIR"

0 commit comments

Comments
 (0)