-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-linux-deps.sh
More file actions
executable file
·1546 lines (1351 loc) · 54 KB
/
setup-linux-deps.sh
File metadata and controls
executable file
·1546 lines (1351 loc) · 54 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
#!/bin/bash
# Linux (Ubuntu) native compilation dependency setup script
# Updated: Installs/builds all libraries and dev_libraries from build config
set -e
SCRIPT_DIR="$(pwd)"
# Install dependencies to system locations that build_lambda_config.json expects
SYSTEM_PREFIX="/usr/local"
# List of libraries and dev_libraries from build_lambda_config.json
ALL_LIBS=(
"libmpdec-dev" # mpdecimal
"libutf8proc-dev" # utf8proc
"libssl-dev" # ssl
"zlib1g-dev" # z
"libnghttp2-dev" # nghttp2
"libncurses5-dev" # ncurses
"build-essential" # includes pthread
"libevent-dev" # libevent (HTTP server)
"libbrotli-dev" # brotlidec + brotlicommon (WOFF2 dep)
)
# Radiant project dependencies - for HTML/CSS/SVG rendering engine
# Note: ThorVG is built from source (see build_thorvg_v1_0_pre34_for_linux function)
RADIANT_DEPS=(
"libglfw3-dev" # OpenGL window and context management
"libpng-dev" # PNG image format support
"libbz2-dev" # Alternative compression library
"zlib1g-dev" # Compression library (already included above)
"libturbojpeg0-dev" # TurboJPEG library with turbojpeg.h header
"libgif-dev" # GIF image format support
"gettext" # For libintl support
"libgl1-mesa-dev" # OpenGL development libraries
"libglu1-mesa-dev" # OpenGL utility libraries
"libegl1-mesa-dev" # EGL development libraries
)
# Check for cleanup option
if [ "$1" = "clean" ] || [ "$1" = "--clean" ]; then
echo "Cleaning up intermediate files..."
# Clean tree-sitter build files
rm -f lambda/tree-sitter/libtree-sitter.a lambda/tree-sitter/tree_sitter.o 2>/dev/null || true
rm -f lambda/tree-sitter-lambda/libtree-sitter-lambda.a lambda/tree-sitter-lambda/src/*.o 2>/dev/null || true
rm -f lambda/tree-sitter-javascript/libtree-sitter-javascript.a lambda/tree-sitter-javascript/src/*.o 2>/dev/null || true
rm -f lambda/tree-sitter-python/libtree-sitter-python.a lambda/tree-sitter-python/src/*.o 2>/dev/null || true
rm -f lambda/tree-sitter-latex/libtree-sitter-latex.a lambda/tree-sitter-latex/src/*.o 2>/dev/null || true
rm -f lambda/tree-sitter-latex-math/libtree-sitter-latex-math.a lambda/tree-sitter-latex-math/src/*.o 2>/dev/null || true
# Clean build directories
rm -rf build/ build_debug/ 2>/dev/null || true
# Clean object files
find . -name "*.o" -type f -delete 2>/dev/null || true
# Clean dependency build files but keep the built libraries
if [ -d "build_temp" ]; then
rm -rf build_temp/
fi
echo "Cleanup completed."
exit 0
fi
echo "Setting up Linux (Ubuntu) native compilation dependencies..."
# Verify installation function
verify_installation() {
local tool="$1"
local package="$2"
if command -v "$tool" >/dev/null 2>&1; then
echo "✅ $tool verified and working"
return 0
else
echo "❌ $tool not found after installing $package"
return 1
fi
}
# Function to check if a package is installed
is_package_installed() {
local package="$1"
dpkg -l | grep -q "^ii.*$package" 2>/dev/null
}
# Function to install package if not already installed
install_if_missing() {
local package="$1"
local description="${2:-$package}"
# For certain packages, check if the command is available first
case "$package" in
"cmake"|"git"|"curl"|"wget"|"python3"|"xxd"|"clang"|"nodejs"|"npm")
local command_name="$package"
if [ "$package" = "python3-pip" ]; then
command_name="pip3"
elif [ "$package" = "nodejs" ]; then
command_name="node"
fi
if command -v "$command_name" >/dev/null 2>&1; then
echo "✅ $description already available"
return 0
fi
;;
esac
# Check if package is installed via apt
if is_package_installed "$package"; then
echo "✅ $description already installed"
return 0
else
echo "Installing $description..."
if sudo apt install -y "$package"; then
echo "✅ $description installed successfully"
return 0
else
echo "❌ Failed to install $description"
return 1
fi
fi
}
# Check for required tools
check_and_install_tool() {
local tool="$1"
local package="$2"
if command -v "$tool" >/dev/null 2>&1; then
echo "✅ $tool already available"
return 0
else
echo "Installing $tool via $package..."
install_if_missing "$package" "$package"
if command -v "$tool" >/dev/null 2>&1; then
echo "✅ $tool installed successfully"
return 0
else
echo "❌ Failed to install $tool via $package"
return 1
fi
fi
}
# Check if running on Ubuntu/Debian
if ! command -v apt >/dev/null 2>&1; then
echo "Warning: This script is designed for Ubuntu/Debian systems with apt package manager."
echo "You may need to adapt the package installation commands for your distribution."
fi
# Check for essential build tools
echo "Setting up essential build tools..."
check_and_install_tool "make" "build-essential" || exit 1
check_and_install_tool "gcc" "build-essential" || exit 1
check_and_install_tool "g++" "build-essential" || exit 1
check_and_install_tool "git" "git" || exit 1
check_and_install_tool "curl" "curl" || exit 1
# xxd is now a separate package in Ubuntu 24.04+
if ! command -v xxd >/dev/null 2>&1; then
echo "Installing xxd..."
if sudo apt install -y xxd; then
echo "✅ xxd installed successfully"
else
echo "❌ Failed to install xxd"
exit 1
fi
else
echo "✅ xxd already available"
fi
# Check for Node.js and npm (needed for tree-sitter CLI via npx)
echo "Setting up Node.js and npm for tree-sitter CLI..."
# Node.js install: try apt, then fallback to NodeSource setup script if needed
echo "Checking for Node.js (node)..."
if command -v node >/dev/null 2>&1; then
echo "✅ node already available"
else
echo "Trying to install nodejs via apt..."
if sudo apt update && sudo apt install -y nodejs npm; then
if command -v node >/dev/null 2>&1; then
echo "✅ node installed via apt"
else
echo "❌ nodejs package installed but 'node' command not found. Trying NodeSource setup..."
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
fi
else
echo "❌ Failed to install nodejs via apt. Trying NodeSource setup..."
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
fi
if command -v node >/dev/null 2>&1; then
echo "✅ node available after NodeSource setup"
else
echo "❌ Node.js installation failed. Please install manually."
exit 1
fi
fi
echo "Checking for npm..."
if command -v npm >/dev/null 2>&1; then
echo "✅ npm already available"
else
echo "Trying to install npm via apt..."
if sudo apt install -y npm; then
echo "✅ npm installed via apt"
else
echo "❌ Failed to install npm via apt. Trying NodeSource setup..."
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y npm
fi
if command -v npm >/dev/null 2>&1; then
echo "✅ npm available after NodeSource setup"
else
echo "❌ npm installation failed. Please install manually."
exit 1
fi
fi
# Verify npx can access tree-sitter CLI
echo "Verifying tree-sitter CLI access via npx..."
if timeout 10 npx tree-sitter-cli@0.24.7 --version >/dev/null 2>&1; then
echo "✅ Tree-sitter CLI 0.24.7 accessible via npx"
else
echo "Warning: tree-sitter CLI may need to be downloaded on first use"
fi
# Install npm dependencies (jsdom for test comparators, puppeteer for browser tests)
# Use --ignore-scripts to avoid node-gyp trying to build tree-sitter-javascript
# native binding before parser.c is generated. The C static library is built
# separately by the tree-sitter build steps below.
echo "Installing npm dependencies..."
if [ -f "$SCRIPT_DIR/package.json" ]; then
npm install --ignore-scripts --prefix "$SCRIPT_DIR"
echo "npm dependencies installed"
else
echo "Warning: package.json not found, skipping npm install"
fi
# Check for cmake (needed for some dependencies)
if command -v cmake >/dev/null 2>&1; then
echo "✅ cmake already available"
else
echo "Installing cmake..."
sudo apt update
install_if_missing "cmake" "cmake"
fi
# Check for pkg-config (often needed for library detection)
if ! command -v pkg-config >/dev/null 2>&1; then
echo "Installing pkg-config..."
install_if_missing "pkg-config" "pkg-config"
else
echo "✅ pkg-config already available"
fi
# Check for meson (needed for building dependencies from source)
if ! command -v meson >/dev/null 2>&1; then
echo "Installing meson..."
install_if_missing "meson" "meson"
else
echo "✅ meson already available"
fi
# Install additional development tools if not present
echo "Installing additional development dependencies..."
sudo apt update
# Function to build Google Test for Linux
build_gtest_for_linux() {
echo "Building Google Test for Linux..."
# Check if already installed in system location
if [ -f "$SYSTEM_PREFIX/lib/libgtest.a" ] && [ -f "$SYSTEM_PREFIX/lib/libgtest_main.a" ]; then
echo "Google Test already installed in system location"
return 0
fi
# Create build_temp directory if it doesn't exist
mkdir -p "build_temp"
# Build from source
if [ ! -d "build_temp/googletest" ]; then
cd build_temp
echo "Cloning Google Test repository..."
git clone https://github.com/google/googletest.git || {
echo "Warning: Could not clone Google Test repository"
cd - > /dev/null
return 1
}
cd - > /dev/null
fi
cd "build_temp/googletest"
# Create build directory
mkdir -p build
cd build
echo "Configuring Google Test with CMake..."
if cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$SYSTEM_PREFIX" \
-DBUILD_GMOCK=ON \
-DBUILD_GTEST=ON \
-DGTEST_CREATE_SHARED_LIBRARY=OFF \
..; then
echo "Building Google Test..."
if make -j$(nproc); then
echo "Installing Google Test to system location (requires sudo)..."
sudo make install
# Update library cache
sudo ldconfig
# Verify the build
if [ -f "$SYSTEM_PREFIX/lib/libgtest.a" ] && [ -f "$SYSTEM_PREFIX/lib/libgtest_main.a" ]; then
echo "✅ Google Test built successfully"
cd - > /dev/null
cd - > /dev/null
return 0
fi
fi
fi
echo "❌ Google Test build failed"
cd - > /dev/null
cd - > /dev/null
return 1
}
# Function to build mpdecimal for Linux
build_mpdecimal_for_linux() {
echo "Building mpdecimal for Linux..."
# Check if already installed in system location
if [ -f "$SYSTEM_PREFIX/include/mpdecimal.h" ]; then
echo "mpdecimal already installed in system location"
return 0
fi
# Create build_temp directory if it doesn't exist
mkdir -p "build_temp"
# Build from source
if [ ! -d "build_temp/mpdecimal" ]; then
cd build_temp
echo "Downloading mpdecimal..."
curl -L "https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-2.5.1.tar.gz" -o "mpdecimal-2.5.1.tar.gz"
tar -xzf "mpdecimal-2.5.1.tar.gz"
mv "mpdecimal-2.5.1" "mpdecimal"
rm "mpdecimal-2.5.1.tar.gz"
cd - > /dev/null
fi
cd "build_temp/mpdecimal"
echo "Configuring mpdecimal..."
if ./configure --prefix="$SYSTEM_PREFIX"; then
echo "Building mpdecimal..."
if make -j$(nproc); then
echo "Installing mpdecimal to system location (requires sudo)..."
sudo make install
# Update library cache
sudo ldconfig
# Verify the build
if [ -f "$SYSTEM_PREFIX/include/mpdecimal.h" ]; then
echo "✅ mpdecimal built and installed successfully"
cd - > /dev/null
return 0
fi
fi
fi
echo "❌ mpdecimal build failed"
cd - > /dev/null
return 1
}
# Function to build libcurl for Linux without libpsl
build_curl_without_libpsl_for_linux() {
echo "Building libcurl for Linux without libpsl..."
if [ -f "$SYSTEM_PREFIX/include/curl/curl.h" ] && [ -f "$SYSTEM_PREFIX/lib/libcurl.so" ]; then
if "$SYSTEM_PREFIX/bin/curl-config" --features 2>/dev/null | grep -qw PSL; then
echo "Existing libcurl has PSL support; rebuilding without libpsl"
else
echo "libcurl without PSL already installed in system location"
return 0
fi
fi
mkdir -p "build_temp"
if [ ! -d "build_temp/curl-8.10.1" ]; then
cd build_temp
echo "Downloading curl 8.10.1..."
curl -L "https://curl.se/download/curl-8.10.1.tar.gz" -o "curl-8.10.1.tar.gz"
tar -xzf "curl-8.10.1.tar.gz"
rm "curl-8.10.1.tar.gz"
cd - > /dev/null
fi
cd "build_temp/curl-8.10.1"
export CPPFLAGS="-I$SYSTEM_PREFIX/include $CPPFLAGS"
export LDFLAGS="-L$SYSTEM_PREFIX/lib $LDFLAGS"
export PKG_CONFIG_PATH="$SYSTEM_PREFIX/lib/pkgconfig:/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
echo "Configuring libcurl without libpsl..."
if ./configure --prefix="$SYSTEM_PREFIX" \
--enable-shared --enable-static \
--with-openssl \
--with-nghttp2 \
--without-libpsl \
--without-libidn2 \
--without-libssh2 \
--without-brotli \
--without-zstd; then
echo "Building libcurl..."
if make -j$(nproc); then
echo "Installing libcurl to system location (requires sudo)..."
sudo make install
sudo ldconfig
if "$SYSTEM_PREFIX/bin/curl-config" --features 2>/dev/null | grep -qw PSL; then
echo "❌ libcurl still reports PSL support"
cd - > /dev/null
return 1
fi
echo "✅ libcurl built and installed without libpsl"
cd - > /dev/null
return 0
fi
fi
echo "❌ libcurl build failed"
cd - > /dev/null
return 1
}
# Install all libraries and dev_libraries from config
# Install all libraries and dev_libraries from config
for lib in "${ALL_LIBS[@]}"; do
if [ "$lib" = "libmpdec-dev" ]; then
if ! install_if_missing "$lib" "$lib"; then
echo "Falling back to building mpdecimal from source..."
build_mpdecimal_for_linux
fi
else
install_if_missing "$lib" "$lib"
fi
done
if ! build_curl_without_libpsl_for_linux; then
echo "Warning: libcurl without libpsl build failed"
fi
# Install Radiant project dependencies
echo "Installing Radiant project dependencies..."
for dep in "${RADIANT_DEPS[@]}"; do
# Skip zlib1g-dev as it's already installed above
if [ "$dep" = "zlib1g-dev" ]; then
echo "zlib1g-dev already handled in core dependencies"
continue
fi
install_if_missing "$dep" "$dep"
done
# Verify mpdecimal header installation
echo "Verifying mpdecimal header installation..."
if [ -f "/usr/include/mpdecimal.h" ]; then
echo "✅ mpdecimal.h found at /usr/include/mpdecimal.h"
elif [ -f "/usr/include/mpdec/mpdecimal.h" ]; then
echo "✅ mpdecimal.h found at /usr/include/mpdec/mpdecimal.h"
echo "Creating symlink for standard location..."
sudo ln -sf /usr/include/mpdec/mpdecimal.h /usr/include/mpdecimal.h
elif [ -f "/usr/local/include/mpdecimal.h" ]; then
echo "✅ mpdecimal.h found at /usr/local/include/mpdecimal.h"
else
echo "❌ mpdecimal.h not found after installation"
echo "Searching for mpdecimal headers..."
find /usr -name "*mpdec*" -type f 2>/dev/null || echo "No mpdecimal files found"
# Directly build from source if header is missing
echo "Building mpdecimal from source..."
build_mpdecimal_for_linux
fi
# Create temporary build directory
mkdir -p "build_temp"
# Function to download and extract if not exists
download_extract() {
local name="$1"
local url="$2"
local archive="$3"
if [ ! -d "build_temp/$name" ]; then
echo "Downloading $name..."
cd build_temp
curl -L "$url" -o "$archive"
case "$archive" in
*.tar.gz) tar -xzf "$archive" ;;
*.tar.bz2) tar -xjf "$archive" ;;
*.tar.xz) tar -xJf "$archive" ;;
*.zip) unzip "$archive" ;;
esac
rm "$archive"
cd - > /dev/null
else
echo "$name already exists, skipping download"
fi
}
# Function to build dependency
build_dependency() {
local name="$1"
local src_dir="$2"
local build_cmd="$3"
echo "Building $name for Linux..."
if [ ! -d "build_temp/$src_dir" ]; then
echo "Warning: Source directory build_temp/$src_dir not found"
return 1
fi
cd "build_temp/$src_dir"
# Set up environment for native Linux compilation
export CC="gcc"
export CXX="g++"
export AR="ar"
export STRIP="strip"
export RANLIB="ranlib"
export CFLAGS="-O2 -fPIC"
export CXXFLAGS="-O2 -fPIC"
export LDFLAGS=""
# Add standard library paths
export CPPFLAGS="-I/usr/include -I/usr/local/include $CPPFLAGS"
export LDFLAGS="-L/usr/lib -L/usr/local/lib $LDFLAGS"
export PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
# Run the build command in a subshell to prevent exit from affecting the main script
(eval "$build_cmd") || {
echo "Warning: $name build failed"
cd - > /dev/null
return 1
}
cd - > /dev/null
return 0
}
# Function to clean up intermediate files
cleanup_intermediate_files() {
echo "Cleaning up intermediate files..."
# Clean object files but keep static libraries
find . -name "*.o" -type f -delete 2>/dev/null || true
# Clean dependency build files but keep source and built libraries
# Note: build_temp/re2-noabsl is needed at build time (Makefile references it)
# Only clean cmake/meson build caches, not source trees
rm -rf build_temp/mbedtls-*/build 2>/dev/null || true
rm -f build_temp/mbedtls-*.tar.bz2 2>/dev/null || true
echo "Cleanup completed."
}
# Function to build ThorVG v1.0-pre34 for Linux
build_thorvg_v1_0_pre34_for_linux() {
echo "Building ThorVG v1.0-pre34 for Linux from mac-deps/thorvg..."
# Determine arch-specific install path (matches build config)
local ARCH=$(uname -m)
local LIB_DIR
if [ "$ARCH" = "aarch64" ]; then
LIB_DIR="$SYSTEM_PREFIX/lib/aarch64-linux-gnu"
else
LIB_DIR="$SYSTEM_PREFIX/lib/x86_64-linux-gnu"
fi
# Use mac-deps/thorvg source (already at v1.0-pre34, same as Mac)
local THORVG_SRC="$SCRIPT_DIR/mac-deps/thorvg"
if [ ! -d "$THORVG_SRC" ]; then
echo "mac-deps/thorvg source not found - cloning ThorVG v1.0-pre34..."
mkdir -p "$SCRIPT_DIR/mac-deps"
if ! git clone --depth 1 --branch v1.0-pre34 https://github.com/thorvg/thorvg.git "$THORVG_SRC"; then
echo "❌ Failed to clone ThorVG v1.0-pre34"
return 1
fi
echo "✅ ThorVG v1.0-pre34 cloned to mac-deps/thorvg"
fi
# Verify the source is at the right tag
cd "$THORVG_SRC"
local tag
tag=$(git describe --tags 2>/dev/null || echo "unknown")
if echo "$tag" | grep -qv "v1.0-pre34"; then
echo "⚠️ Warning: mac-deps/thorvg is at tag '$tag', expected v1.0-pre34"
fi
# Apply Lambda patches
PATCH_FILE="$SCRIPT_DIR/patches/thorvg-svg-font-inheritance.patch"
if [ -f "$PATCH_FILE" ]; then
echo "Applying ThorVG patches..."
git apply "$PATCH_FILE" 2>/dev/null || {
git apply --check "$PATCH_FILE" 2>/dev/null && true || {
echo " (patch already applied or skipped)"
}
}
fi
cd - > /dev/null
# Build in mac-deps/thorvg/build-linux (mirroring Mac's build-mac)
cd "$THORVG_SRC"
rm -rf build-linux
mkdir -p build-linux
echo "Configuring ThorVG with Meson..."
if ! meson setup build-linux \
--buildtype=plain \
--default-library=static \
-Dengines=sw \
-Dloaders=svg,ttf \
-Dsavers= \
-Dbindings=capi \
-Dtools= \
-Dtests=false \
-Dsimd=true \
-Dthreads=true; then
echo "❌ ThorVG meson setup failed"
cd - > /dev/null
return 1
fi
echo "Building ThorVG v1.0-pre34..."
if ! ninja -C build-linux; then
echo "❌ ThorVG ninja build failed"
cd - > /dev/null
return 1
fi
# Install library and headers
echo "Installing ThorVG to $LIB_DIR..."
sudo mkdir -p "$LIB_DIR"
sudo mkdir -p "$SYSTEM_PREFIX/include"
sudo cp "build-linux/src/libthorvg.a" "$LIB_DIR/libthorvg.a"
sudo cp "inc/thorvg.h" "$SYSTEM_PREFIX/include/thorvg.h"
sudo cp "src/bindings/capi/thorvg_capi.h" "$SYSTEM_PREFIX/include/thorvg_capi.h"
# Verify installation and API
if nm "$LIB_DIR/libthorvg.a" 2>/dev/null | grep -q "tvg_text_set_size"; then
if ! nm "$LIB_DIR/libthorvg.a" 2>/dev/null | grep -q "glClearColor"; then
echo "✅ ThorVG v1.0-pre34 installed to $LIB_DIR"
echo " - tvg_text_set_size: ✓ Available"
echo " - GL symbols: ✓ None"
cd - > /dev/null
return 0
else
echo "❌ ThorVG library has unexpected GL symbols"
fi
else
echo "❌ ThorVG text API missing from built library"
fi
return 1
}
# Function to build rpmalloc for Linux
build_rpmalloc_for_linux() {
echo "Building rpmalloc for Linux..."
# Determine architecture
ARCH=$(uname -m)
if [ "$ARCH" = "aarch64" ]; then
LIB_DIR="$SYSTEM_PREFIX/lib/aarch64-linux-gnu"
else
LIB_DIR="$SYSTEM_PREFIX/lib/x86_64-linux-gnu"
fi
# Check if already installed in system location
if [ -f "$LIB_DIR/librpmalloc.a" ] && [ -f "$SYSTEM_PREFIX/include/rpmalloc/rpmalloc.h" ]; then
# Verify the library has the expected symbols
if nm "$LIB_DIR/librpmalloc.a" 2>/dev/null | grep -q "rpmalloc_initialize"; then
echo "✅ rpmalloc already installed and verified"
return 0
else
echo "rpmalloc found but missing expected symbols, rebuilding..."
sudo rm -f "$LIB_DIR/librpmalloc.a" 2>/dev/null || true
fi
fi
# Create build_temp directory if it doesn't exist
mkdir -p build_temp
# Check if source exists, if not clone it
if [ ! -d "build_temp/rpmalloc-src" ]; then
echo "Cloning rpmalloc repository..."
cd build_temp
git clone https://github.com/mjansson/rpmalloc.git rpmalloc-src || {
echo "Warning: Could not clone rpmalloc repository"
cd - > /dev/null
return 1
}
cd - > /dev/null
else
echo "rpmalloc source already downloaded"
fi
cd build_temp/rpmalloc-src
# Clean any previous builds
rm -f *.o *.a 2>/dev/null || true
# Build rpmalloc with ENABLE_OVERRIDE=0 (no malloc override)
# This allows us to use rpmalloc only for explicit pool allocations
echo "Compiling rpmalloc with ENABLE_OVERRIDE=0..."
if gcc -c -O2 \
-DRPMALLOC_FIRST_CLASS_HEAPS=1 \
-DENABLE_OVERRIDE=0 \
-I. \
rpmalloc/rpmalloc.c \
-o rpmalloc.o; then
echo "Creating static library..."
if ar rcs librpmalloc.a rpmalloc.o; then
# Install the library and headers
echo "Installing rpmalloc to system location (requires sudo)..."
sudo mkdir -p "$LIB_DIR"
sudo mkdir -p "$SYSTEM_PREFIX/include/rpmalloc"
sudo cp librpmalloc.a "$LIB_DIR/"
sudo cp rpmalloc/rpmalloc.h "$SYSTEM_PREFIX/include/rpmalloc/"
# Verify the library has expected symbols
if nm "$LIB_DIR/librpmalloc.a" | grep -q "rpmalloc_initialize"; then
echo "✅ rpmalloc built successfully"
echo " - rpmalloc_initialize: ✓ Available"
echo " - rpmalloc_heap_acquire: ✓ Available"
echo " - rpmalloc_heap_alloc: ✓ Available"
echo " - ENABLE_OVERRIDE=0: ✓ No malloc override"
cd - > /dev/null
return 0
else
echo "❌ Required functions not found in built library"
cd - > /dev/null
return 1
fi
fi
fi
echo "❌ rpmalloc build failed"
cd - > /dev/null
return 1
}
# Function to build mpdecimal for Linux
build_mpdecimal_for_linux() {
echo "Building mpdecimal for Linux..."
# Check if already installed in system location
if [ -f "$SYSTEM_PREFIX/include/mpdecimal.h" ]; then
echo "mpdecimal already installed in system location"
return 0
fi
# Create build_temp directory if it doesn't exist
mkdir -p "build_temp"
# Build from source
if [ ! -d "build_temp/mpdecimal" ]; then
cd build_temp
echo "Downloading mpdecimal..."
curl -L "https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-2.5.1.tar.gz" -o "mpdecimal-2.5.1.tar.gz"
tar -xzf "mpdecimal-2.5.1.tar.gz"
mv "mpdecimal-2.5.1" "mpdecimal"
rm "mpdecimal-2.5.1.tar.gz"
cd - > /dev/null
fi
cd "build_temp/mpdecimal"
echo "Configuring mpdecimal..."
if ./configure --prefix="$SYSTEM_PREFIX"; then
echo "Building mpdecimal..."
if make -j$(nproc); then
echo "Installing mpdecimal to system location (requires sudo)..."
sudo make install
# Update library cache
sudo ldconfig
# Verify the build
if [ -f "$SYSTEM_PREFIX/include/mpdecimal.h" ]; then
echo "✅ mpdecimal built and installed successfully"
cd - > /dev/null
return 0
fi
fi
fi
echo "❌ mpdecimal build failed"
cd - > /dev/null
return 1
}
# Function to build utf8proc for Linux
build_utf8proc_for_linux() {
echo "Building utf8proc for Linux..."
# Check if already installed in system location
if [ -f "$SYSTEM_PREFIX/lib/libutf8proc.a" ] || [ -f "$SYSTEM_PREFIX/lib/libutf8proc.so" ]; then
echo "utf8proc already installed in system location"
return 0
fi
# Build from source
if [ ! -d "build_temp/utf8proc" ]; then
cd build_temp
echo "Cloning utf8proc repository..."
git clone https://github.com/JuliaStrings/utf8proc.git || {
echo "Warning: Could not clone utf8proc repository"
cd - > /dev/null
return 1
}
cd - > /dev/null
fi
cd "build_temp/utf8proc"
# Check if Makefile exists
if [ ! -f "Makefile" ]; then
echo "Warning: Makefile not found in utf8proc directory"
cd - > /dev/null
return 1
fi
echo "Building utf8proc..."
if make -j$(nproc); then
echo "Installing utf8proc to system location (requires sudo)..."
sudo make install
# Update library cache
sudo ldconfig
# Verify the build
if [ -f "$SYSTEM_PREFIX/lib/libutf8proc.a" ] || [ -f "$SYSTEM_PREFIX/lib/libutf8proc.so" ]; then
echo "✅ utf8proc built successfully"
cd - > /dev/null
return 0
fi
fi
echo "❌ utf8proc build failed"
cd - > /dev/null
return 1
}
# Function to build MIR for Linux
build_mir_for_linux() {
echo "Building MIR for Linux..."
# Check if already installed in system location
if [ -f "$SYSTEM_PREFIX/lib/libmir.a" ] || [ -f "$SYSTEM_PREFIX/lib/libmir.so" ]; then
echo "MIR already installed in system location"
return 0
fi
# Create build_temp directory if it doesn't exist
mkdir -p "build_temp"
# Build from source
if [ ! -d "build_temp/mir" ]; then
cd build_temp
echo "Cloning MIR repository..."
git clone https://github.com/vnmakarov/mir.git || {
echo "Warning: Could not clone MIR repository"
cd - > /dev/null
return 1
}
cd - > /dev/null
fi
cd "build_temp/mir"
# Apply MIR alloca-branch fix patch
PATCH_FILE="$SCRIPT_DIR/patches/mir-alloca-branch-fix.patch"
if [ -f "$PATCH_FILE" ]; then
echo "Applying MIR patches..."
git apply "$PATCH_FILE" 2>/dev/null || {
git apply --check "$PATCH_FILE" 2>/dev/null && true || {
echo " (patch already applied or skipped)"
}
}
fi
# Check if GNUmakefile exists (MIR uses GNUmakefile, not Makefile)
if [ ! -f "GNUmakefile" ]; then
echo "Warning: GNUmakefile not found in MIR directory"
cd - > /dev/null
return 1
fi
echo "Building MIR..."
if make -j$(nproc); then
echo "Installing MIR to system location (requires sudo)..."
# Create directories if they don't exist
sudo mkdir -p "$SYSTEM_PREFIX/lib"
sudo mkdir -p "$SYSTEM_PREFIX/include"
# Copy library (try different names)
if [ -f "libmir.a" ]; then
sudo cp libmir.a "$SYSTEM_PREFIX/lib/"
elif [ -f "mir.a" ]; then
sudo cp mir.a "$SYSTEM_PREFIX/lib/libmir.a"
else
echo "Warning: MIR library not found"
find . -name "*.a" -name "*mir*" | head -5
fi
# Copy headers (more comprehensive approach)
if [ -f "mir.h" ]; then
sudo cp mir.h "$SYSTEM_PREFIX/include/"
echo "✅ mir.h copied to $SYSTEM_PREFIX/include/"
else
echo "Warning: mir.h not found"
find . -name "mir.h" | head -5
fi
# Copy c2mir.h specifically (critical for compilation)
C2MIR_PATH=$(find . -name "c2mir.h" | head -1)
if [ -n "$C2MIR_PATH" ] && [ -f "$C2MIR_PATH" ]; then
sudo cp "$C2MIR_PATH" "$SYSTEM_PREFIX/include/"
echo "✅ c2mir.h copied from $C2MIR_PATH to $SYSTEM_PREFIX/include/"
else
echo "Warning: c2mir.h not found in MIR build directory"
# Fallback: check if c2mir.h exists in project include directory
if [ -f "$SCRIPT_DIR/include/c2mir.h" ]; then
sudo cp "$SCRIPT_DIR/include/c2mir.h" "$SYSTEM_PREFIX/include/"
echo "✅ c2mir.h copied from project include/ to $SYSTEM_PREFIX/include/"
else
echo "Warning: c2mir.h not found in project include/ either"
find . -name "c2mir.h" | head -5
fi
fi
# Copy all MIR-related headers
for header in mir-*.h; do
if [ -f "$header" ]; then
sudo cp "$header" "$SYSTEM_PREFIX/include/"
echo "✅ $header copied to $SYSTEM_PREFIX/include/"
fi
done
# Update library cache
sudo ldconfig
# Verify the build
if [ -f "$SYSTEM_PREFIX/lib/libmir.a" ] && [ -f "$SYSTEM_PREFIX/include/mir.h" ] && [ -f "$SYSTEM_PREFIX/include/c2mir.h" ]; then
echo "✅ MIR built successfully"
cd - > /dev/null
return 0
elif [ -f "$SYSTEM_PREFIX/lib/libmir.a" ] && [ -f "$SYSTEM_PREFIX/include/mir.h" ]; then
echo "⚠️ MIR library and mir.h built but c2mir.h header missing"
cd - > /dev/null
return 1
elif [ -f "$SYSTEM_PREFIX/lib/libmir.a" ]; then
echo "⚠️ MIR library built but header files missing"
cd - > /dev/null
return 1
else
echo "❌ MIR library not found after build"
cd - > /dev/null
return 1
fi
fi
echo "❌ MIR build failed"
cd - > /dev/null
return 1
}
# Helper: returns 0 if the archive contains ELF objects, 1 if not (e.g. Mach-O from macOS)
is_elf_archive() {
local lib="$1"
[ -f "$lib" ] || return 1
local first_obj
first_obj=$(ar t "$lib" 2>/dev/null | head -1)
[ -n "$first_obj" ] || return 1
# ELF magic bytes: 7f 45 4c 46
local magic
magic=$(ar p "$lib" "$first_obj" 2>/dev/null | od -A n -N 4 -t x1 | tr -d ' \n')
[ "$magic" = "7f454c46" ]
}