rust-musl-builder/test-image
Eric Kidd 727d912b3b Add support for static linking of sqlx
`sqlx` requires linking against OpenSSL twice:

- `sqlx-macros` needs to link against OpenSSL as a shared libary for use
  at compile time.
- `sqlx` needs to link against OpenSSL a static library for use at
  runtime.

You can find the details here:

https://github.com/launchbadge/sqlx/issues/670
https://github.com/sfackler/rust-openssl/issues/1337

We go with the fix proposed by @sfackler, and add a test program that we
can use to verify everything works correctly.

We remove a few `OPENSSL`-related variables that were added 4 years ago,
and that no longer appear to be needed.
2020-09-03 16:24:49 -04:00

75 lines
2.1 KiB
Bash
Executable file

#!/bin/bash
# Make bash fail much more aggressively on errors.
set -euo pipefail
# Make sure we can build our main container.
docker build -t ekidd/rust-musl-builder .
# Make sure we can build our example derived container.
docker build -t rust-musl-zlib examples/adding-a-library
# Make sure we can build a multi-stage container.
docker build -t rust-musl-builder-using-diesel examples/using-diesel
docker run --rm rust-musl-builder-using-diesel
echo "==== Verifying static linking"
# Make sure we can build a static executable.
docker run --rm ekidd/rust-musl-builder bash -c "
set -euo pipefail
export USER=rust
cargo new --vcs none --bin testme
cd testme
echo -e '--- Test case for x86_64:'
cargo build
echo 'ldd says:'
if ldd target/x86_64-unknown-linux-musl/debug/testme; then
echo '[FAIL] Executable is not static!' 1>&2
exit 1
fi
echo -e '[PASS] x86_64 binary is statically linked.\n'
echo -e '--- Test case for ARMhf:'
cargo build --target=armv7-unknown-linux-musleabihf
echo 'ldd says:'
if ldd target/armv7-unknown-linux-musleabihf/debug/testme; then
echo '[FAIL] Executable is not static!' 1>&2
exit 1
fi
echo -e '[PASS] ARMhf binary is statically linked.\n'
"
# Make sure we can build a static executable using `sqlx`.
docker build -t rust-musl-builder-using-sqlx examples/using-sqlx
docker run --rm rust-musl-builder-using-sqlx sh -c "
set -euo pipefail
echo -e '--- Test case for sqlx:'
echo 'ldd says:'
if ldd /usr/local/bin/using-sqlx; then
echo '[FAIL] Executable is not static!' 1>&2
exit 1
fi
echo -e '[PASS] using-sqlx binary is statically linked.\n'
"
# Make sure we can build a static executable using `git2`.
docker build -t rust-musl-builder-linking-with-git2 examples/linking-with-git2
docker run --rm rust-musl-builder-linking-with-git2 bash -c "
set -euo pipefail
cd /home/rust/src
echo -e '--- Test case for libgit2:'
echo 'ldd says:'
if ldd target/x86_64-unknown-linux-musl/debug/linking-with-git2; then
echo '[FAIL] Executable is not static!' 1>&2
exit 1
fi
echo -e '[PASS] libgit2 binary is statically linked.\n'
"
# We're good.
echo 'OK. ALL TESTS PASSED.' 1>&2