Skip to content

Commit d302f15

Browse files
committed
Build shared OpenSSL
OpenSSL & curl libraries are isolated from the system one & won't conflict with system tools.
1 parent 58a7576 commit d302f15

File tree

2 files changed

+60
-21
lines changed

2 files changed

+60
-21
lines changed

docker/build_scripts/build.sh

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ hash -r
8686
curl --version
8787
curl-config --features
8888

89-
# Install a git we link against OpenSSL so that we can use TLS 1.2
90-
build_git $GIT_ROOT $GIT_HASH
91-
git version
92-
9389
# Install newest autoconf
9490
build_autoconf $AUTOCONF_ROOT $AUTOCONF_HASH
9591
autoconf --version
@@ -102,6 +98,45 @@ automake --version
10298
build_libtool $LIBTOOL_ROOT $LIBTOOL_HASH
10399
libtool --version
104100

101+
# Install patchelf (latest with unreleased bug fixes)
102+
curl -fsSL -o patchelf.tar.gz https://github.com/NixOS/patchelf/archive/$PATCHELF_VERSION.tar.gz
103+
check_sha256sum patchelf.tar.gz $PATCHELF_HASH
104+
tar -xzf patchelf.tar.gz
105+
(cd patchelf-$PATCHELF_VERSION && ./bootstrap.sh && do_standard_install)
106+
rm -rf patchelf.tar.gz patchelf-$PATCHELF_VERSION
107+
108+
# We strip curl now because stripping after patchelf breaks it
109+
strip --strip-unneeded /opt/_internal/_vendor/lib/libcurl.so.4
110+
strip --strip-unneeded /usr/local/bin/curl
111+
112+
# Let's patch curl & openssl:
113+
CHECKSUM=$(sha256sum /opt/_internal/_vendor/lib/libcrypto.so.1.0.0)
114+
CHECKSUM=${CHECKSUM:0:8}
115+
patchelf --set-soname /opt/_internal/_vendor/lib/libcrypto.so.1.0.0-${CHECKSUM} /opt/_internal/_vendor/lib/libcrypto.so.1.0.0
116+
mv /opt/_internal/_vendor/lib/libcrypto.so.1.0.0 /opt/_internal/_vendor/lib/libcrypto.so.1.0.0-${CHECKSUM}
117+
ln -sf libcrypto.so.1.0.0-${CHECKSUM} /opt/_internal/_vendor/lib/libcrypto.so
118+
patchelf --replace-needed libcrypto.so.1.0.0 /opt/_internal/_vendor/lib/libcrypto.so.1.0.0-${CHECKSUM} /opt/_internal/_vendor/lib/libssl.so.1.0.0
119+
patchelf --replace-needed libcrypto.so.1.0.0 /opt/_internal/_vendor/lib/libcrypto.so.1.0.0-${CHECKSUM} /opt/_internal/_vendor/lib/libcurl.so.4
120+
patchelf --replace-needed libcrypto.so.1.0.0 /opt/_internal/_vendor/lib/libcrypto.so.1.0.0-${CHECKSUM} /usr/local/bin/curl
121+
122+
CHECKSUM=$(sha256sum /opt/_internal/_vendor/lib/libssl.so.1.0.0)
123+
CHECKSUM=${CHECKSUM:0:8}
124+
patchelf --set-soname /opt/_internal/_vendor/lib/libssl.so.1.0.0-${CHECKSUM} /opt/_internal/_vendor/lib/libssl.so.1.0.0
125+
mv /opt/_internal/_vendor/lib/libssl.so.1.0.0 /opt/_internal/_vendor/lib/libssl.so.1.0.0-${CHECKSUM}
126+
ln -sf libssl.so.1.0.0-${CHECKSUM} /opt/_internal/_vendor/lib/libssl.so
127+
patchelf --replace-needed libssl.so.1.0.0 /opt/_internal/_vendor/lib/libssl.so.1.0.0-${CHECKSUM} /opt/_internal/_vendor/lib/libcurl.so.4
128+
patchelf --replace-needed libssl.so.1.0.0 /opt/_internal/_vendor/lib/libssl.so.1.0.0-${CHECKSUM} /usr/local/bin/curl
129+
130+
CHECKSUM=$(sha256sum /opt/_internal/_vendor/lib/libcurl.so.4)
131+
CHECKSUM=${CHECKSUM:0:8}
132+
patchelf --set-soname /opt/_internal/_vendor/lib/libcurl.so.4-${CHECKSUM} /opt/_internal/_vendor/lib/libcurl.so.4
133+
mv /opt/_internal/_vendor/lib/libcurl.so.4 /opt/_internal/_vendor/lib/libcurl.so.4-${CHECKSUM}
134+
patchelf --replace-needed libcurl.so.4 /opt/_internal/_vendor/lib/libcurl.so.4-${CHECKSUM} /usr/local/bin/curl
135+
136+
# Install a git we link against OpenSSL so that we can use TLS 1.2
137+
build_git $GIT_ROOT $GIT_HASH
138+
git version
139+
105140
# Install a more recent SQLite3
106141
curl -fsSLO $SQLITE_AUTOCONF_DOWNLOAD_URL/$SQLITE_AUTOCONF_VERSION.tar.gz
107142
check_sha256sum $SQLITE_AUTOCONF_VERSION.tar.gz $SQLITE_AUTOCONF_HASH
@@ -110,11 +145,14 @@ cd $SQLITE_AUTOCONF_VERSION
110145
do_standard_install
111146
cd ..
112147
rm -rf $SQLITE_AUTOCONF_VERSION*
148+
rm -f /usr/local/lib/libsqlite3.a
149+
150+
# Create a symbolic link for python to find openssl
151+
ln -s /opt/_internal/_vendor /usr/local/ssl
113152

114153
# Compile the latest Python releases.
115154
# (In order to have a proper SSL module, Python is compiled
116-
# against a recent openssl [see env vars above], which is linked
117-
# statically.
155+
# against a recent openssl [see env vars above])
118156
mkdir -p /opt/python
119157
build_cpythons $CPYTHON_VERSIONS
120158

@@ -134,14 +172,8 @@ ln -s $($PY36_BIN/python -c 'import certifi; print(certifi.where())') \
134172
export SSL_CERT_FILE=/opt/_internal/certs.pem
135173

136174
# Now we can delete our built OpenSSL headers/static libs since we've linked everything we need
137-
rm -rf /usr/local/ssl
138-
139-
# Install patchelf (latest with unreleased bug fixes)
140-
curl -fsSL -o patchelf.tar.gz https://github.com/NixOS/patchelf/archive/$PATCHELF_VERSION.tar.gz
141-
check_sha256sum patchelf.tar.gz $PATCHELF_HASH
142-
tar -xzf patchelf.tar.gz
143-
(cd patchelf-$PATCHELF_VERSION && ./bootstrap.sh && do_standard_install)
144-
rm -rf patchelf.tar.gz patchelf-$PATCHELF_VERSION
175+
unlink /usr/local/ssl
176+
find /opt/_internal/_vendor -mindepth 1 -maxdepth 1 -not -path '/opt/_internal/_vendor/lib*' | xargs rm -rf
145177

146178
ln -s $PY36_BIN/auditwheel /usr/local/bin/auditwheel
147179

@@ -164,10 +196,18 @@ yum list installed
164196
find /opt/_internal -name '*.a' -print0 | xargs -0 rm -f
165197

166198
# Strip what we can -- and ignore errors, because this just attempts to strip
167-
# *everything*, including non-ELF files:
168-
find /opt/_internal -type f -print0 \
199+
# *everything*, including non-ELF files.
200+
# We ignore curl which was stripped before patching it with patchelf
201+
find /opt/_internal -type f -not -name 'libcurl.so*' -print0 \
202+
| xargs -0 -n1 strip --strip-unneeded 2>/dev/null || true
203+
find /usr/local -type f -not -name 'curl' -print0 \
169204
| xargs -0 -n1 strip --strip-unneeded 2>/dev/null || true
170205

206+
# Make sure curl is still working after stripping, patchelf can break things
207+
# libcurl is in exceptions for stripping and this will help catch errors if openssl gets broken after an update
208+
curl -fsSLO $GET_PIP_URL
209+
rm -f get-pip.py
210+
171211
for PYTHON in /opt/python/*/bin/python; do
172212
# Smoke test to make sure that our Pythons work, and do indeed detect as
173213
# being manylinux compatible:

docker/build_scripts/build_utils.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ function build_cpythons {
104104

105105

106106
function do_openssl_build {
107-
./config no-ssl2 no-shared -fPIC --prefix=/usr/local/ssl > /dev/null
107+
./config no-ssl2 shared --prefix=/opt/_internal/_vendor --openssldir=/opt/_internal/_vendor > /dev/null
108108
make > /dev/null
109109
make install_sw > /dev/null
110+
rm -rf /opt/_internal/_vendor/bin /opt/_internal/_vendor/lib/*.a
110111
}
111112

112113

@@ -170,15 +171,13 @@ function build_git {
170171
fetch_source v${git_fname}.tar.gz ${GIT_DOWNLOAD_URL}
171172
check_sha256sum v${git_fname}.tar.gz ${git_sha256}
172173
tar -xzf v${git_fname}.tar.gz
173-
(cd git-${git_fname} && make install prefix=/usr/local LDFLAGS="-L/usr/local/ssl/lib -ldl" CFLAGS="-I/usr/local/ssl/include" > /dev/null)
174+
(cd git-${git_fname} && make install prefix=/usr/local NO_GETTEXT=1 LDFLAGS="-L/opt/_internal/_vendor/lib -ldl" CFLAGS="-I/opt/_internal/_vendor/include" > /dev/null)
174175
rm -rf git-${git_fname} v${git_fname}.tar.gz
175176
}
176177

177178

178179
function do_curl_build {
179-
# We do this shared to avoid obnoxious linker issues where git couldn't
180-
# link properly. If anyone wants to make this build statically go for it.
181-
LIBS=-ldl CFLAGS=-Wl,--exclude-libs,ALL ./configure --with-ssl --disable-static > /dev/null
180+
LD_LIBRARY_PATH=/opt/_internal/_vendor/lib:$LD_LIBRARY_PATH LIBS=-ldl CFLAGS=-Wl,--exclude-libs,ALL ./configure --with-ssl=/opt/_internal/_vendor --disable-static --prefix=/opt/_internal/_vendor --bindir=/usr/local/bin > /dev/null
182181
make > /dev/null
183182
make install > /dev/null
184183
}

0 commit comments

Comments
 (0)