Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·2037 lines (1711 loc) · 59.3 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·2037 lines (1711 loc) · 59.3 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -e
#-----------------------------------------------------------------------------
# FalkorDB Build Script
#
# This script handles building the FalkorDB module and running tests.
# It supports various build configurations and test types.
#-----------------------------------------------------------------------------
# Get the absolute path to script directory
ROOT="$(cd "$(dirname "$0")" && pwd)"
BINROOT="$ROOT/bin"
#-----------------------------------------------------------------------------
# Default configuration values
#-----------------------------------------------------------------------------
DEBUG=0 # Debug build flag
COV=0 # Coverage mode
PROFILE=0 # Profile build flag
FORCE=0 # Force clean build flag
VERBOSE=0 # Verbose output flag
SLOW=0 # Disable parallel build
STATIC_OMP=0 # Link OpenMP statically
VG=0 # Valgrind mode
SAN="" # Sanitizer type (address/memory/leak/thread)
VARIANT="" # Custom variant name
GCC=0 # Force GCC toolchain
CLANG=0 # Force Clang toolchain
JIT=1 # GraphBLAS JIT support (default on)
# Test configuration (0=disabled, 1=enabled)
BUILD_TESTS=0 # Build test binaries
RUN_TESTS=0 # Run all tests
RUN_UNIT_TESTS=0 # Run unit tests
RUN_FLOW_TESTS=0 # Run flow tests
RUN_TCK_TESTS=0 # Run TCK tests
# Other options
LIST_TESTS=0 # List tests only
TEST_FILTER="" # Specific test to run
TESTFILE="" # File with list of tests
FAILFILE="" # File to write failed tests
PARALLEL="" # Test parallelism
GDB=0 # Run with GDB
# Build flags
MEMCHECK=0 # Memory checking mode
DEPS_DEBUG=0 # Build deps in debug mode
# Clean options
CLEAN=0 # Run clean operation
CLEAN_ALL=0 # Remove entire bin directory
CLEAN_DEPS=0 # Also clean dependencies
CLEAN_AUTOGEN=0 # Remove autogen files
# Package options
PACK=0 # Build RAMP packages
# Fuzz test options
RUN_FUZZ_TESTS=0 # Run fuzz tests
FUZZ_TIMEOUT=30 # Fuzz test timeout in seconds
# Benchmark options
BENCHMARK=0 # Run benchmarks
BENCHMARK_GROUP="" # Benchmark group to run (group_a, group_b, or empty for all)
# Run options
RUN=0 # Run redis-server with the module
#-----------------------------------------------------------------------------
# Color definitions for output
#-----------------------------------------------------------------------------
if [[ -t 1 ]]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
else
RED=''
GREEN=''
YELLOW=''
BLUE=''
CYAN=''
NC=''
fi
#-----------------------------------------------------------------------------
# Helper functions
#-----------------------------------------------------------------------------
log_info() {
echo -e "${CYAN}[INFO]${NC} $*"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $*"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $*" >&2
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $*"
}
start_group() {
if [[ -n $GITHUB_ACTIONS ]]; then
echo "::group::$1"
else
log_info "==== $1 ===="
fi
}
end_group() {
if [[ -n $GITHUB_ACTIONS ]]; then
echo "::endgroup::"
fi
}
#-----------------------------------------------------------------------------
# Function: show_help
# Display help information
#-----------------------------------------------------------------------------
show_help() {
cat <<-'EOF'
FalkorDB Build Script
USAGE:
./build.sh [OPTIONS]
BUILD OPTIONS:
DEBUG=1 Build for debugging
PROFILE=1 Build with profiling enabled
COV=1 Build for coverage analysis (implies DEBUG=1)
VG=1|docker Build for Valgrind
SAN=type Build with LLVM sanitizer (type=address|memory|leak|thread)
FORCE=1 Force clean build
SLOW=1 Disable parallel build
STATIC_OMP=1 Link OpenMP statically
VARIANT=name Add 'name' to build products directory
GCC=1 Build with GCC toolchain (default for Linux)
CLANG=1 Build with Clang toolchain (default for macOS)
JIT=0 Disable GraphBLAS JIT support
TEST OPTIONS:
TESTS=1 Build test binaries
RUN_TESTS=1 Run all tests
RUN_UNIT_TESTS=1 Run unit tests only
RUN_FLOW_TESTS=1 Run flow tests only
RUN_TCK_TESTS=1 Run TCK tests only
LIST=1 List all tests, do not execute
TEST=name Run specific test
TESTFILE=file Run tests listed in file
FAILFILE=file Write failed tests to file
PARALLEL=n Set testing parallelism
GDB=1 Run with GDB debugger
RUN_FUZZ_TESTS=1 Run fuzz tests
TIMEOUT=secs Fuzz test timeout in seconds (default: 30)
BENCHMARK OPTIONS:
BENCHMARK=1 Run benchmarks
BENCHMARK_GROUP=x Run specific benchmark group (group_a, group_b)
RUN OPTIONS:
RUN=1 Run redis-server with the FalkorDB module loaded
GDB=1 Run with GDB debugger (use with RUN=1)
CLEAN OPTIONS:
CLEAN=1 Clean build products
ALL=1 Remove entire bin directory (with CLEAN=1)
DEPS=1 Also clean dependencies (with CLEAN=1)
AUTOGEN=1 Remove autogen files (with CLEAN=1)
PACKAGE OPTIONS:
PACK=1 Build RAMP packages
OTHER OPTIONS:
VERBOSE=1 Show verbose output
HELP=1 Show this help message
EXAMPLES:
# Build in debug mode
./build.sh DEBUG=1
# Build and run all tests
./build.sh RUN_TESTS=1
# Build with address sanitizer and run flow tests
./build.sh SAN=address RUN_FLOW_TESTS=1
# Build for coverage and run tests
./build.sh COV=1 RUN_TESTS=1
# Clean build products
./build.sh CLEAN=1
# Full clean (remove entire bin directory)
./build.sh CLEAN=1 ALL=1
# Build RAMP packages
./build.sh PACK=1
# Run fuzz tests with 60 second timeout
./build.sh RUN_FUZZ_TESTS=1 TIMEOUT=60
EOF
}
#-----------------------------------------------------------------------------
# Function: parse_arguments
# Parse command-line arguments and set configuration variables
#-----------------------------------------------------------------------------
parse_arguments() {
for arg in "$@"; do
# Convert to uppercase for case-insensitive matching
upper_arg=$(echo "$arg" | tr '[:lower:]' '[:upper:]')
case $upper_arg in
HELP=1|--HELP|HELP)
show_help
exit 0
;;
DEBUG=1)
DEBUG=1
;;
PROFILE=1)
PROFILE=1
;;
COV=1)
COV=1
DEBUG=1 # Coverage implies debug
;;
VG=1)
VG=1
MEMCHECK=1
;;
SAN=*)
SAN="${arg#*=}"
MEMCHECK=1
;;
FORCE=1)
FORCE=1
;;
VERBOSE=1)
VERBOSE=1
;;
SLOW=1)
SLOW=1
;;
STATIC_OMP=1)
STATIC_OMP=1
;;
VARIANT=*)
VARIANT="${arg#*=}"
;;
GCC=1)
GCC=1
;;
CLANG=1)
CLANG=1
;;
JIT=*)
JIT="${arg#*=}"
;;
TESTS=1|UNIT_TESTS=1)
BUILD_TESTS=1
;;
RUN_TESTS=1)
RUN_TESTS=1
BUILD_TESTS=1
;;
RUN_UNIT_TESTS=1)
RUN_UNIT_TESTS=1
BUILD_TESTS=1
;;
RUN_FLOW_TESTS=1|FLOW=1)
RUN_FLOW_TESTS=1
;;
RUN_TCK_TESTS=1|TCK=1)
RUN_TCK_TESTS=1
;;
LIST=1)
LIST_TESTS=1
;;
TEST=*)
TEST_FILTER="${arg#*=}"
;;
TESTFILE=*)
TESTFILE="${arg#*=}"
;;
FAILFILE=*)
FAILFILE="${arg#*=}"
;;
PARALLEL=*)
PARALLEL="${arg#*=}"
;;
GDB=1)
GDB=1
;;
# Clean options
CLEAN=1)
CLEAN=1
;;
ALL=1)
CLEAN_ALL=1
;;
DEPS=1)
CLEAN_DEPS=1
;;
AUTOGEN=1)
CLEAN_AUTOGEN=1
;;
# Package options
PACK=1|PACKAGE=1)
PACK=1
;;
# Fuzz test options
RUN_FUZZ_TESTS=1|FUZZ=1)
RUN_FUZZ_TESTS=1
;;
TIMEOUT=*)
FUZZ_TIMEOUT="${arg#*=}"
;;
# Benchmark options
BENCHMARK=1)
BENCHMARK=1
;;
BENCHMARK_GROUP=*)
BENCHMARK_GROUP="${arg#*=}"
;;
# Run options
RUN=1)
RUN=1
;;
*)
log_warn "Unknown argument: $arg"
;;
esac
done
}
#-----------------------------------------------------------------------------
# Function: detect_platform
# Detect operating system and architecture
#-----------------------------------------------------------------------------
detect_platform() {
# Detect OS
OS_NAME=$(uname -s)
case "$OS_NAME" in
Linux*)
OS="linux"
;;
Darwin*)
OS="macos"
;;
*)
log_error "Unsupported OS: $OS_NAME"
exit 1
;;
esac
# Detect architecture
ARCH=$(uname -m)
case "$ARCH" in
x86_64)
ARCH="x64"
;;
aarch64|arm64)
ARCH="arm64v8"
;;
*)
log_error "Unsupported architecture: $ARCH"
exit 1
;;
esac
# Detect OS nickname (simplified version)
if [[ "$OS" == "linux" ]]; then
if [[ -f /etc/os-release ]]; then
. /etc/os-release
OSNICK=$(echo "$ID" | tr '[:upper:]' '[:lower:]')
if [[ -n "$VERSION_ID" ]]; then
OSNICK="${OSNICK}${VERSION_ID}"
fi
else
OSNICK="linux"
fi
elif [[ "$OS" == "macos" ]]; then
OSNICK="macos"
fi
# Detect musl libc (for Alpine and similar)
USING_MUSL=0
if command -v ldd &>/dev/null; then
if ldd 2>&1 | head -1 | grep -qi musl; then
USING_MUSL=1
fi
fi
if [[ "$OSNICK" =~ alpine ]]; then
USING_MUSL=1
fi
if [[ "$VERBOSE" == "1" ]]; then
log_info "Platform: OS=$OS, OSNICK=$OSNICK, ARCH=$ARCH"
log_info "Using musl: $USING_MUSL"
fi
}
#-----------------------------------------------------------------------------
# Function: setup_build_environment
# Configure the build environment variables
#-----------------------------------------------------------------------------
setup_build_environment() {
# Determine build flavor
if [[ "$SAN" == "address" ]]; then
FLAVOR="debug-asan"
elif [[ -n "$SAN" ]]; then
FLAVOR="debug-${SAN}"
elif [[ "$DEBUG" == "1" ]]; then
FLAVOR="debug"
elif [[ "$COV" == "1" ]]; then
FLAVOR="debug-cov"
elif [[ "$PROFILE" == "1" ]]; then
FLAVOR="release-profile"
else
FLAVOR="release"
fi
# Add custom variant if specified
if [[ -n "$VARIANT" ]]; then
FLAVOR="${FLAVOR}.${VARIANT}"
fi
# Create full variant string
FULL_VARIANT="${OS}-${ARCH}-${FLAVOR}"
# For dependencies, use release unless MEMCHECK is set
if [[ "$MEMCHECK" == "1" ]]; then
DEPS_FULL_VARIANT="$FULL_VARIANT"
DEPS_DEBUG=1
else
DEPS_FULL_VARIANT="${OS}-${ARCH}-release"
DEPS_DEBUG=0
fi
# Set build directories
BINROOT="${ROOT}/bin/${FULL_VARIANT}"
DEPS_BINDIR="${ROOT}/bin/${DEPS_FULL_VARIANT}"
TARGET="${BINROOT}/falkordb.so"
# Set up dependency directories
export RAX_BINDIR="${DEPS_BINDIR}/rax"
export LIBXXHASH_BINDIR="${DEPS_BINDIR}/xxHash"
export LIBCURL_BINDIR="${DEPS_BINDIR}/libcurl"
export LIBCSV_BINDIR="${DEPS_BINDIR}/libcsv"
export LIBCYPHER_PARSER_BINDIR="${DEPS_BINDIR}/libcypher-parser"
export GRAPHBLAS_BINDIR="${DEPS_BINDIR}/GraphBLAS"
export LAGRAPH_BINDIR="${DEPS_BINDIR}/LAGraph"
export QUICKJS_BINDIR="${DEPS_BINDIR}/quickjs"
export UTF8PROC_BINDIR="${DEPS_BINDIR}/utf8proc"
export ONIGURUMA_BINDIR="${DEPS_BINDIR}/oniguruma"
export FalkorDBRS_BINDIR="${BINROOT}/FalkorDB-core-rs"
# Export environment variables for dependencies
export RAX="${RAX_BINDIR}/librax.a"
export LIBXXHASH="${LIBXXHASH_BINDIR}/libxxhash.a"
export LIBCURL="${LIBCURL_BINDIR}/lib/.libs/libcurl.a"
export LIBCSV="${LIBCSV_BINDIR}/.libs/libcsv.a"
export LIBCYPHER_PARSER="${LIBCYPHER_PARSER_BINDIR}/lib/src/.libs/libcypher-parser.a"
export GRAPHBLAS="${GRAPHBLAS_BINDIR}/libgraphblas.a"
export LAGRAPH="${LAGRAPH_BINDIR}/src/liblagraph.a"
export LAGRAPHX="${LAGRAPH_BINDIR}/experimental/liblagraphx.a"
export QUICKJS="${QUICKJS_BINDIR}/libquickjs.a"
export UTF8PROC="${UTF8PROC_BINDIR}/libutf8proc.a"
export ONIGURUMA="${ONIGURUMA_BINDIR}/libonig.a"
# FalkorDB Rust
# Note: When using sanitizer with nightly Rust, cargo builds with --target <triple>
# which changes the output path structure to include the target triple
if [[ -n "$SAN" ]] && rustup run nightly rustc --version &>/dev/null 2>&1; then
# Sanitizer build with nightly uses explicit target - determine the correct triple
local rust_target
if [[ "$OS" == "macos" ]]; then
if [[ "$ARCH" == "arm64v8" ]]; then
rust_target="aarch64-apple-darwin"
else
rust_target="x86_64-apple-darwin"
fi
else
if [[ "$ARCH" == "arm64v8" ]]; then
rust_target="aarch64-unknown-linux-gnu"
else
rust_target="x86_64-unknown-linux-gnu"
fi
fi
export FalkorDBRS="${FalkorDBRS_BINDIR}/${rust_target}/debug/libFalkorDB_rs.a"
elif [[ "$DEBUG" == "1" || -n "$SAN" || "$COV" == "1" ]]; then
# Debug, coverage, or sanitizer fallback (without nightly)
export FalkorDBRS="${FalkorDBRS_BINDIR}/debug/libFalkorDB_rs.a"
else
export FalkorDBRS="${FalkorDBRS_BINDIR}/release/libFalkorDB_rs.a"
fi
# Setup compiler flags
if [[ "$OS" == "macos" ]]; then
export CC="${CC:-clang}"
export CXX="${CXX:-clang++}"
# Set macOS deployment target if not already set
if [[ -z "$CMAKE_OSX_DEPLOYMENT_TARGET" ]]; then
# Use reasonable minimum deployment target
# arm64 (Apple Silicon) requires macOS 12.0+
# x64 (Intel) can use macOS 10.15+
if [[ "$ARCH" == "arm64v8" ]]; then
export CMAKE_OSX_DEPLOYMENT_TARGET="12.0"
else
export CMAKE_OSX_DEPLOYMENT_TARGET="10.15"
fi
fi
# Also set MACOSX_DEPLOYMENT_TARGET for compatibility
export MACOSX_DEPLOYMENT_TARGET="${CMAKE_OSX_DEPLOYMENT_TARGET}"
elif [[ "$GCC" == "1" ]]; then
export CC="${CC:-gcc}"
export CXX="${CXX:-g++}"
elif [[ "$CLANG" == "1" ]]; then
export CC="${CC:-clang}"
export CXX="${CXX:-clang++}"
fi
# Export CMake flags for RediSearch compatibility
# RediSearch's readies expects these environment variables
# Set to space to avoid string REPLACE errors when empty
export CMAKE_CC_FLAGS="${CMAKE_CC_FLAGS:- }"
# Disable VLA warnings and GNU extensions completely for RediSearch macro compatibility
export CMAKE_CC_C_FLAGS="${CMAKE_CC_C_FLAGS:- -Wno-gnu-zero-variadic-macro-arguments}"
# Note: -Wno-vla-extension is Clang-specific, GCC doesn't recognize it
# Using -Wno-vla-extension instead of -Wno-vla-cxx-extension for compatibility with Clang < 18
if [[ "$CLANG" == "1" ]] || [[ "${CC:-}" == *"clang"* ]]; then
export CMAKE_CC_CXX_FLAGS="${CMAKE_CC_CXX_FLAGS:- -Wno-vla-extension -Wno-gnu-zero-variadic-macro-arguments}"
else
export CMAKE_CC_CXX_FLAGS="${CMAKE_CC_CXX_FLAGS:- -Wno-gnu-zero-variadic-macro-arguments}"
fi
export CMAKE_LD_FLAGS="${CMAKE_LD_FLAGS:- }"
export CMAKE_SO_LD_FLAGS="${CMAKE_SO_LD_FLAGS:- }"
export CMAKE_EXE_LD_FLAGS="${CMAKE_EXE_LD_FLAGS:- }"
export CMAKE_LD_FLAGS_LIST="${CMAKE_LD_FLAGS_LIST:- }"
export CMAKE_SO_LD_FLAGS_LIST="${CMAKE_SO_LD_FLAGS_LIST:- }"
export CMAKE_EXE_LD_FLAGS_LIST="${CMAKE_EXE_LD_FLAGS_LIST:- }"
export CMAKE_LD_LIBS="${CMAKE_LD_LIBS:- }"
# Determine number of parallel jobs (needed for dependency builds)
if [[ "$SLOW" == "1" ]]; then
NPROC=1
elif command -v nproc &> /dev/null; then
NPROC=$(nproc)
elif command -v sysctl &> /dev/null && [[ "$OS" == "macos" ]]; then
NPROC=$(sysctl -n hw.physicalcpu)
else
NPROC=4
fi
export NPROC
# Print build configuration
echo ""
log_info "Build Configuration:"
log_info " OS: $OS # Operating system (linux/macos)"
log_info " ARCH: $ARCH # CPU architecture (x64/arm64v8)"
log_info " FLAVOR: $FLAVOR # Build type (release/debug/debug-asan/etc)"
log_info " VARIANT: $FULL_VARIANT # Full build variant identifier"
log_info " BINROOT: $BINROOT # Build output directory"
log_info " TARGET: $TARGET # Output module path"
log_info " CC: ${CC:-cc} # C compiler"
log_info " CXX: ${CXX:-c++} # C++ compiler"
log_info " NPROC: $NPROC # Parallel build jobs"
if [[ "$OS" == "macos" ]]; then
log_info " MACOSX_TARGET: $MACOSX_DEPLOYMENT_TARGET # macOS deployment target"
fi
if [[ -n "$SAN" ]]; then
log_info " SANITIZER: $SAN # LLVM sanitizer enabled"
fi
if [[ "$DEBUG" == "1" ]]; then
log_info " DEBUG: enabled # Debug build"
fi
if [[ "$COV" == "1" ]]; then
log_info " COVERAGE: enabled # Code coverage instrumentation"
fi
if [[ "$VG" == "1" ]]; then
log_info " VALGRIND: enabled # Valgrind-compatible build"
fi
echo ""
}
#-----------------------------------------------------------------------------
# Function: check_dependencies
# Check if dependencies need to be built
#-----------------------------------------------------------------------------
check_dependencies() {
MISSING_DEPS=()
[[ ! -f "$RAX" ]] && MISSING_DEPS+=("rax")
[[ ! -f "$LIBXXHASH" ]] && MISSING_DEPS+=("xxhash")
[[ ! -f "$LIBCURL" ]] && MISSING_DEPS+=("libcurl")
[[ ! -f "$LIBCSV" ]] && MISSING_DEPS+=("libcsv")
[[ ! -f "$LIBCYPHER_PARSER" ]] && MISSING_DEPS+=("libcypher-parser")
[[ ! -f "$GRAPHBLAS" ]] && MISSING_DEPS+=("graphblas")
[[ ! -f "$LAGRAPH" ]] && MISSING_DEPS+=("lagraph")
[[ ! -f "$QUICKJS" ]] && MISSING_DEPS+=("quickjs")
[[ ! -f "$UTF8PROC" ]] && MISSING_DEPS+=("utf8proc")
[[ ! -f "$ONIGURUMA" ]] && MISSING_DEPS+=("oniguruma")
# RediSearch is now built by CMake as a subdirectory
[[ ! -f "$FalkorDBRS" ]] && MISSING_DEPS+=("falkordbrs")
if [[ ${#MISSING_DEPS[@]} -gt 0 ]]; then
log_info "Missing dependencies: ${MISSING_DEPS[*]}"
return 1
fi
return 0
}
#-----------------------------------------------------------------------------
# Function: build_rax
# Build rax library natively (without readies wrapper)
#-----------------------------------------------------------------------------
build_rax() {
if [[ -f "$RAX" ]] && [[ "$FORCE" != "1" ]]; then
return 0
fi
start_group "Building rax"
log_info "Building rax..."
local src_dir="${ROOT}/deps/rax"
local bin_dir="$RAX_BINDIR"
mkdir -p "$bin_dir"
local cc_flags="-fPIC -std=gnu99 -fvisibility=hidden -I${src_dir}"
if [[ "$DEPS_DEBUG" == "1" ]]; then
cc_flags+=" -g -O0"
else
cc_flags+=" -O3 -g" # -O3 for optimization, -g for debug symbols
fi
# Compile rax.c
${CC:-cc} $cc_flags -c "$src_dir/rax.c" -o "$bin_dir/rax.o"
# Create static library
ar rcs "$bin_dir/librax.a" "$bin_dir/rax.o"
log_success "rax built successfully"
end_group
}
#-----------------------------------------------------------------------------
# Function: build_xxhash
# Build xxHash library natively (without readies wrapper)
#-----------------------------------------------------------------------------
build_xxhash() {
if [[ -f "$LIBXXHASH" ]] && [[ "$FORCE" != "1" ]]; then
return 0
fi
start_group "Building xxHash"
log_info "Building xxHash..."
local src_dir="${ROOT}/deps/xxHash"
local bin_dir="$LIBXXHASH_BINDIR"
mkdir -p "$bin_dir"
local cc_flags="-O3 -g -fPIC" # -O3 for optimization, -g for debug symbols
# Compile xxhash.c
${CC:-cc} $cc_flags -c "$src_dir/xxhash.c" -o "$bin_dir/xxhash.o"
# Create static library
ar rcs "$bin_dir/libxxhash.a" "$bin_dir/xxhash.o"
log_success "xxHash built successfully"
end_group
}
#-----------------------------------------------------------------------------
# Function: build_libcypher_parser
# Build libcypher-parser using autotools (configure/make) out-of-source
#-----------------------------------------------------------------------------
build_libcypher_parser() {
if [[ -f "$LIBCYPHER_PARSER" ]] && [[ "$FORCE" != "1" ]]; then
return 0
fi
start_group "Building libcypher-parser"
local src_dir="${ROOT}/deps/libcypher-parser"
local build_dir="$LIBCYPHER_PARSER_BINDIR"
mkdir -p "$build_dir"
# Run autoreconf if configure doesn't exist (it's gitignored and must be generated)
if [[ ! -f "$src_dir/configure" ]]; then
log_info "Running autoreconf for libcypher-parser..."
cd "$src_dir"
autoreconf -fi
cd "$build_dir"
else
cd "$build_dir"
fi
# Run configure if Makefile doesn't exist
if [[ ! -f "$build_dir/Makefile" ]]; then
log_info "Configuring libcypher-parser..."
# --disable-tools: don't build cypher-lint (we only need the library)
# Use -fPIC for position-independent code (required for linking into shared library)
# Use -O3 for optimization, -g for debug symbols, -DYY_BUFFER_SIZE for larger parser buffer
if ! CFLAGS="-fPIC -O3 -g -DYY_BUFFER_SIZE=1048576" "$src_dir/configure" --disable-dependency-tracking --disable-tools; then
log_error "Failed to configure libcypher-parser"
cd "$ROOT"
end_group
exit 1
fi
fi
log_info "Building libcypher-parser..."
if ! make -j "$NPROC"; then
log_error "Failed to build libcypher-parser"
cd "$ROOT"
end_group
exit 1
fi
cd "$ROOT"
log_success "libcypher-parser built successfully"
end_group
}
#-----------------------------------------------------------------------------
# Function: build_libcurl
# Build libcurl using autotools
#-----------------------------------------------------------------------------
build_libcurl() {
if [[ -f "$LIBCURL" ]] && [[ "$FORCE" != "1" ]]; then
return 0
fi
start_group "Building libcurl"
local src_dir="${ROOT}/deps/libcurl"
local build_dir="$LIBCURL_BINDIR"
mkdir -p "$build_dir"
cd "$build_dir"
# Run autoreconf if configure doesn't exist
if [[ ! -f "$src_dir/configure" ]]; then
log_info "Running autoreconf for libcurl..."
cd "$src_dir"
autoreconf -fi
cd "$build_dir"
fi
# Run configure if Makefile doesn't exist
if [[ ! -f "$build_dir/Makefile" ]]; then
log_info "Configuring libcurl..."
# Disable all optional dependencies to build a minimal static library
# Use -fPIC for position-independent code (required for linking into shared library)
# Use -O3 for optimization, -g for debug symbols
if ! CFLAGS="-fPIC -O3 -g" "$src_dir/configure" --disable-dependency-tracking --disable-shared --enable-static \
--without-ssl --without-libssh2 --without-librtmp --without-libidn2 \
--without-nghttp2 --without-brotli --without-zstd --without-libpsl \
--without-zlib --disable-ldap; then
log_error "Failed to configure libcurl"
cd "$ROOT"
end_group
exit 1
fi
fi
log_info "Building libcurl..."
if ! make -j "$NPROC"; then
log_error "Failed to build libcurl"
cd "$ROOT"
end_group
exit 1
fi
cd "$ROOT"
log_success "libcurl built successfully"
end_group
}
#-----------------------------------------------------------------------------
# Function: build_libcsv
# Build libcsv using autotools
#-----------------------------------------------------------------------------
build_libcsv() {
if [[ -f "$LIBCSV" ]] && [[ "$FORCE" != "1" ]]; then
return 0
fi
start_group "Building libcsv"
local src_dir="${ROOT}/deps/libcsv"
local build_dir="$LIBCSV_BINDIR"
mkdir -p "$build_dir"
# Always run autoreconf to ensure build files are consistent with local automake version
# This avoids "automake-X.XX not found" errors when the repo's generated files
# were created with a different automake version
log_info "Running autoreconf for libcsv..."
cd "$src_dir"
autoreconf -fi
cd "$build_dir"
# Run configure if Makefile doesn't exist
if [[ ! -f "$build_dir/Makefile" ]]; then
log_info "Configuring libcsv..."
# Use -fPIC for position-independent code (required for linking into shared library)
# Use -O3 for optimization, -g for debug symbols
if ! CFLAGS="-fPIC -O3 -g" "$src_dir/configure" --disable-dependency-tracking; then
log_error "Failed to configure libcsv"
cd "$ROOT"
end_group
exit 1
fi
fi
log_info "Building libcsv..."
if ! make -j "$NPROC"; then
log_error "Failed to build libcsv"
cd "$ROOT"
end_group
exit 1
fi
cd "$ROOT"
log_success "libcsv built successfully"
end_group
}
#-----------------------------------------------------------------------------
# Function: build_graphblas
# Build GraphBLAS using cmake
#-----------------------------------------------------------------------------
build_graphblas() {
if [[ -f "$GRAPHBLAS" ]] && [[ "$FORCE" != "1" ]]; then
return 0
fi
start_group "Building GraphBLAS"
log_info "Building GraphBLAS..."
local src_dir="${ROOT}/deps/GraphBLAS"
local build_dir="$GRAPHBLAS_BINDIR"
mkdir -p "$build_dir"
cd "$build_dir"
local cmake_args=(
-DSUITESPARSE_USE_FORTRAN=OFF
-DBUILD_STATIC_LIBS=ON
-DBUILD_SHARED_LIBS=OFF
-DGRAPHBLAS_COMPACT=OFF
-DGRAPHBLAS_BUILD_STATIC_LIBS=ON
-DBUILD_TESTING=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_C_FLAGS="-fPIC -fno-stack-protector"
-DCMAKE_CXX_FLAGS="-fPIC -fno-stack-protector"
)
if [[ "$DEPS_DEBUG" == "1" ]]; then
cmake_args+=(-DCMAKE_BUILD_TYPE=Debug)
else
# Use RelWithDebInfo for debug symbols, but override to -O3 for max optimization
cmake_args+=(
-DCMAKE_BUILD_TYPE=RelWithDebInfo
"-DCMAKE_C_FLAGS_RELWITHDEBINFO=-O3 -g -DNDEBUG -fPIC -fno-stack-protector"
"-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-O3 -g -DNDEBUG -fPIC -fno-stack-protector"
)
fi
if [[ "$JIT" != "" ]]; then
cmake_args+=(-DGRAPHBLAS_USE_JIT="$JIT")
fi
log_info "Configuring GraphBLAS..."
if ! cmake "$src_dir" "${cmake_args[@]}"; then
log_error "Failed to configure GraphBLAS"
cd "$ROOT"
end_group
exit 1
fi
log_info "Building GraphBLAS..."
if ! cmake --build . --config RelWithDebInfo -j "$NPROC"; then
log_error "Failed to build GraphBLAS"
cd "$ROOT"
end_group
exit 1
fi
cd "$ROOT"
log_success "GraphBLAS built successfully"
end_group
}
#-----------------------------------------------------------------------------
# Function: build_lagraph
# Build LAGraph using cmake
#-----------------------------------------------------------------------------
build_lagraph() {
if [[ -f "$LAGRAPH" ]] && [[ "$FORCE" != "1" ]]; then
return 0
fi
start_group "Building LAGraph"
log_info "Building LAGraph..."
local src_dir="${ROOT}/deps/LAGraph"
local build_dir="$LAGRAPH_BINDIR"
mkdir -p "$build_dir"
cd "$build_dir"
local cmake_args=(
-DBUILD_STATIC_LIBS=ON
-DBUILD_SHARED_LIBS=OFF
-DLIBRARY_ONLY=ON
-DBUILD_TESTING=OFF
-DGRAPHBLAS_ROOT="$GRAPHBLAS_BINDIR"
-DGRAPHBLAS_INCLUDE_DIR="${ROOT}/deps/GraphBLAS/Include"
-DGRAPHBLAS_LIBRARY="$GRAPHBLAS"
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_C_FLAGS="-fPIC"
-DCMAKE_CXX_FLAGS="-fPIC"
)
if [[ "$DEPS_DEBUG" == "1" ]]; then
cmake_args+=(-DCMAKE_BUILD_TYPE=Debug)
else
# Use RelWithDebInfo for debug symbols, but override to -O3 for max optimization
cmake_args+=(
-DCMAKE_BUILD_TYPE=RelWithDebInfo
"-DCMAKE_C_FLAGS_RELWITHDEBINFO=-O3 -g -DNDEBUG -fPIC"
"-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-O3 -g -DNDEBUG -fPIC"
)
fi
log_info "Configuring LAGraph..."
if ! cmake "$src_dir" "${cmake_args[@]}"; then
log_error "Failed to configure LAGraph"
cd "$ROOT"
end_group
exit 1
fi
log_info "Building LAGraph..."
if ! cmake --build . --config RelWithDebInfo -j "$NPROC"; then
log_error "Failed to build LAGraph"
cd "$ROOT"
end_group
exit 1
fi
cd "$ROOT"
log_success "LAGraph built successfully"
end_group
}
#-----------------------------------------------------------------------------
# Function: build_quickjs
# Build quickjs natively
#
# Symbol Conflict Resolution:
# Both quickjs and Friso (a Chinese text segmentation library used by RediSearch)
# define a function called `unicode_to_utf8`. This causes a duplicate symbol error
# at link time when building falkordb.so.
#
# Solution: Before building quickjs, we rename all occurrences of `unicode_to_utf8`
# to `quickjs_unicode_to_utf8` in the quickjs source files. This includes:
# - The function definition in cutils.c
# - The function declaration in cutils.h
# - All internal calls in quickjs.c, libregexp.c, quickjs-libc.c, etc.
#
# This is safe because `unicode_to_utf8` is an internal quickjs utility function,
# not part of the public quickjs API (quickjs.h). FalkorDB only uses the public API,
# so this rename is transparent to our code. After building, we restore the original
# source files to keep the deps/quickjs directory clean.
#-----------------------------------------------------------------------------
build_quickjs() {
if [[ -f "$QUICKJS" ]] && [[ "$FORCE" != "1" ]]; then