-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathamqp
executable file
·232 lines (180 loc) · 5.76 KB
/
amqp
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
#!/usr/bin/env bash
set -e
if [ -n "$BUILDPACK_DEBUG" ]; then
set -x
fi
#
# This script is called by the `build_ext` function
# which is defined in `php-buildpack/support/lib/php_ext`.
#
# The `build_ext` function is itself called by the `package_{internal_}ext` function,
# which is defined in `php-buildpack/support/package_{internal_}ext`.
#
# The following parameters are passed when the script is called (yet, unused):
# - $1: PHP version
# - $2: Zend API version
# - $3: Path to a temporary directory where PHP source code resides
# (only for internal extension)
#
# amqp requires librabbitmq to work.
# Since our package deploys the PHP extension `amqp.so` in /app/vendor/php/...
# librabbitmq must be deployed somewhere in there too.
#
# To do this, we use the CMAKE_INSTALL_PREFIX when compiling librabbitmq and
# set it to /app/vendor/php/lib/rabbitmq.
# This means `amqp.so` will look for the `librabbitmq.so` file in
# /app/vendor/php/lib/rabbitmq/lib/
#
# We specify the same path when compiling amqp (`--with-librabbitmq-dir`).
#
# Since librabbitmq must be deployed along with the amqp extension, it must be
# added to the future package. That's why we are moving the librabbitmq files
# to $PREFIX once they are ready.
#
download_archive() {
local archive_url
archive_url="${1}"
curl --location "${archive_url}"
}
build_librabbitmq() {
local pkgname
local pkgver
local url
local librabbitmq_dir
pkgname="${1}"
pkgver="${2}"
url="${3}"
librabbitmq_dir="${4}"
printf -v archive_url "${url}" "${pkgver}"
mkdir -p "${pkgname}-${pkgver}"
pushd "${pkgname}-${pkgver}"
download_archive "${archive_url}" \
| tar xvz --strip-components=1
if [ "${STACK}" = "scalingo-18" ]; then
cmake \
-DCMAKE_INSTALL_PREFIX="${librabbitmq_dir}" \
-DBUILD_TESTS=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_TOOLS=OFF \
-DBUILD_TOOLS_DOCS=OFF \
-DBUILD_API_DOCS=OFF \
-DRUN_SYSTEM_TESTS=OFF \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_STATIC_LIBS=OFF \
-Wno-dev \
|| ( echo "Failed to build librabbitmq." \
&& exit 1 )
else
cmake \
-DCMAKE_INSTALL_PREFIX="${librabbitmq_dir}" \
-DBUILD_TESTING=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_TOOLS=OFF \
-DBUILD_TOOLS_DOCS=OFF \
-DBUILD_API_DOCS=OFF \
-DRUN_SYSTEM_TESTS=OFF \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_STATIC_LIBS=OFF \
-Wno-dev \
|| ( echo "Failed to build librabbitmq." \
&& exit 1 )
fi
cmake \
--build . \
--config Release \
--target install \
|| ( echo "Failed to build librabbitmq." \
&& exit 1 )
popd
mkdir -p "${PREFIX}/lib"
if [ "${STACK}" = "scalingo-18" ]; then
# Move things that have been stored in `${prefix}/lib/x86_64-linux-gnu`
# to `${prefix}/lib` so that AMQP's `configure` finds them.
find "${librabbitmq_dir}/lib/x86_64-linux-gnu" \
-mindepth 1 \
-maxdepth 1 \
-exec mv --target-directory "${librabbitmq_dir}/lib/" -- {} \+
rmdir "${librabbitmq_dir}/lib/x86_64-linux-gnu"
fi
# Copy library to `$PREFIX/lib` so it's included in the future package
cp -ar "${librabbitmq_dir}" "${PREFIX}/lib/"
}
build_amqp() {
local pkgname
local pkgver
local url
local librabbitmq_dir
pkgname="${1}"
pkgver="${2}"
url="${3}"
librabbitmq_dir="${4}"
printf -v archive_url "${url}" "${pkgver}"
mkdir -p "${pkgname}-${pkgver}"
pushd "${pkgname}-${pkgver}"
download_archive "${archive_url}" \
| tar xvz --strip-components=1
/app/vendor/php/bin/phpize \
|| ( echo "Failed to PHPize AMQP extension." \
&& exit 1 )
./configure \
--with-php-config="/app/vendor/php/bin/php-config" \
--with-librabbitmq-dir="${librabbitmq_dir}" \
|| ( echo "Failed to configure AMQP extension." \
&& exit 1 )
make \
|| ( echo "Failed to build AMQP extension." \
&& exit 1 )
popd
}
# Remove everything in /app to avoid conflicts while building other versions
# of the extension.
cleanup_amqp() {
rm -Rf "/app/vendor"
}
# Make sure `cmake` is available
which cmake 2>/dev/null || (apt update && apt install -y cmake)
source "/buildpack/conf/buildpack.conf"
librabbitmq_prefix="/app/vendor/php/lib/rabbitmq"
# librabbitmq
# https://github.com/alanxz/rabbitmq-c/releases
# Default `$version` is loaded from the buildpack.conf file.
pkgname="librabbitmq-c"
source_url="https://github.com/alanxz/rabbitmq-c/archive/refs/tags/v%s.tar.gz"
case "${STACK}" in
"scalingo-18")
version="0.11.0"
;;
"scalingo-20")
version="0.13.0"
;;
*)
version="${librabbitmq_version}"
;;
esac
build_librabbitmq "${pkgname}" "${version}" "${source_url}" "${librabbitmq_prefix}"
# amqp
# https://pecl.php.net/package/amqp
# Default `$version` is loaded from the buildpack.conf file.
pkgname="amqp"
source_url="https://pecl.php.net/get/amqp-%s.tgz"
case "${STACK}" in
"scalingo-18")
version="1.11.0"
;;
*)
version="${amqp_version}"
;;
esac
build_amqp "${pkgname}" "${version}" "${source_url}" "${librabbitmq_prefix}"
cp "${pkgname}-${version}/modules/amqp.so" "${EXT_DIR}/amqp.so"
echo "extension=amqp.so" > "${PREFIX}/etc/conf.d/amqp.ini"
# Versions breakdown:
#
# | Stack | amqp | librabbitmq |
# | ----------- | ------ | ----------- |
# | scalingo-22 | 2.1.2 | 0.14.0 |
# | scalingo-20 | 2.1.2 | 0.13.0 |
# | scalingo-18 | 1.11.0 | 0.11.0 |
#
# Cleanup
cleanup_amqp