-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathpreinstall.sh
More file actions
executable file
·158 lines (143 loc) · 4.37 KB
/
preinstall.sh
File metadata and controls
executable file
·158 lines (143 loc) · 4.37 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
#!/bin/sh
set -e
# Preinstall script for aws-lambda-ric
# Builds curl and aws-lambda-cpp from source archives during npm install
SCRIPT_DIR=$(dirname "$0")
PACKAGE_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
DEPS_DIR="$PACKAGE_DIR/deps"
ARTIFACTS_DIR="$DEPS_DIR/artifacts"
# OS detection - skip on macOS
if [ "$(uname)" = "Darwin" ]; then
echo "aws-lambda-cpp does not build on OS X. Skipping the preinstall step."
exit 0
fi
# Check for cmake (cmake3 or cmake)
if command -v cmake3 >/dev/null 2>&1; then
CMAKE=cmake3
elif command -v cmake >/dev/null 2>&1; then
CMAKE=cmake
else
echo 'Error: cmake is not installed.' >&2
exit 1
fi
echo "Using cmake: $CMAKE"
# Create artifacts directory
mkdir -p "$ARTIFACTS_DIR"
cd "$DEPS_DIR"
# Build curl
echo "Extracting curl..."
CURL_DIR="$DEPS_DIR/curl-src"
mkdir -p "$CURL_DIR"
# Use -o for busybox tar (Alpine), --no-same-owner for GNU tar
if tar --version 2>/dev/null | grep -q GNU; then
tar xJf ./curl.tar.xz --no-same-owner -C "$CURL_DIR"
else
tar xJf ./curl.tar.xz -o -C "$CURL_DIR"
fi
if [ ! -f "$CURL_DIR/configure" ]; then
echo "Error: Failed to extract curl archive" >&2
exit 1
fi
echo "Building curl..."
(
cd "$CURL_DIR"
# The curl tarball includes a pre-generated configure script.
# We skip autoreconf as it hangs on ARM platforms due to a known
# bash/libtool/autoconf interaction issue.
if [ ! -f configure ]; then
echo "Error: configure script not found in curl archive" >&2
exit 1
fi
./configure \
--prefix "$ARTIFACTS_DIR" \
--disable-alt-svc \
--disable-ares \
--disable-cookies \
--disable-crypto-auth \
--disable-dateparse \
--disable-dict \
--disable-dnsshuffle \
--disable-doh \
--disable-file \
--disable-ftp \
--disable-get-easy-options \
--disable-gopher \
--disable-hsts \
--disable-http-auth \
--disable-imap \
--disable-ipv6 \
--disable-ldap \
--disable-ldaps \
--disable-libcurl-option \
--disable-manual \
--disable-mime \
--disable-mqtt \
--disable-netrc \
--disable-ntlm-wb \
--disable-pop3 \
--disable-progress-meter \
--disable-proxy \
--disable-pthreads \
--disable-rtsp \
--disable-shared \
--disable-smtp \
--disable-socketpair \
--disable-sspi \
--disable-telnet \
--disable-tftp \
--disable-threaded-resolver \
--disable-unix-sockets \
--disable-verbose \
--disable-versioned-symbols \
--with-pic \
--without-brotli \
--without-ca-bundle \
--without-gssapi \
--without-libidn2 \
--without-libpsl \
--without-librtmp \
--without-libssh2 \
--without-nghttp2 \
--without-nghttp3 \
--without-ngtcp2 \
--without-ssl \
--without-zlib \
--without-zstd
make -j "$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)"
make install
)
echo "curl build complete."
# Build aws-lambda-cpp
echo "Extracting aws-lambda-cpp..."
AWS_LAMBDA_CPP_DIR="$DEPS_DIR/aws-lambda-cpp-src"
mkdir -p "$AWS_LAMBDA_CPP_DIR"
# Use -o for busybox tar (Alpine), --no-same-owner for GNU tar
if tar --version 2>/dev/null | grep -q GNU; then
tar xJf ./aws-lambda-cpp.tar.xz --no-same-owner -C "$AWS_LAMBDA_CPP_DIR"
else
tar xJf ./aws-lambda-cpp.tar.xz -o -C "$AWS_LAMBDA_CPP_DIR"
fi
if [ ! -f "$AWS_LAMBDA_CPP_DIR/CMakeLists.txt" ]; then
echo "Error: Failed to extract aws-lambda-cpp archive" >&2
exit 1
fi
echo "Building aws-lambda-cpp..."
(
cd "$AWS_LAMBDA_CPP_DIR"
mkdir -p build
cd build
# Detect musl libc (Alpine) and disable backtrace support
CMAKE_CXX_FLAGS="-fPIC"
if ldd --version 2>&1 | grep -q musl; then
echo "Detected musl libc (Alpine), disabling backtrace support..."
CMAKE_CXX_FLAGS="-fPIC -DBACKWARD_HAS_BACKTRACE=0 -DBACKWARD_HAS_BACKTRACE_SYMBOL=0"
fi
$CMAKE .. \
-DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS" \
-DCMAKE_INSTALL_PREFIX="$ARTIFACTS_DIR" \
-DCMAKE_MODULE_PATH="$ARTIFACTS_DIR/lib/pkgconfig"
make -j "$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)"
make install
)
echo "aws-lambda-cpp build complete."
echo "Artifacts installed to: $ARTIFACTS_DIR"