pegh/.ci/build.sh

56 lines
2.3 KiB
Bash
Raw Normal View History

2019-12-27 01:00:10 -05:00
#!/bin/sh
set -exu
# change to the directory this script is in
cd "$(dirname "$0")"
# dependencies to build+test pegh
2019-12-30 00:10:18 -05:00
apk add build-base clang bash libsodium-dev libsodium-static libressl-dev
# first build for libressl, which doesn't have "EVP_PBE_scrypt" so can only be compiled with libsodium
make clean all PEGH_LIBSODIUM=1 PEGH_OPENSSL=1 CC=clang LDFLAGS="-static -lcrypto" || clang pegh.c -DPEGH_LIBSODIUM -DPEGH_OPENSSL -static -lsodium -lcrypto -O3 -o pegh
mv pegh pegh.static.libsodium-libressl
# now remove libressl and install openssl
apk del libressl-dev
apk add openssl-dev openssl-libs-static
2019-12-27 01:00:10 -05:00
# gcc is apparantly incapable of building a static binary, even gcc -static helloworld.c ends up linked to libc, instead of solving, use clang
make clean all PEGH_LIBSODIUM=1 CC=clang LDFLAGS="-static -lsodium" || clang pegh.c -DPEGH_LIBSODIUM -static -lsodium -O3 -o pegh
mv pegh pegh.static.libsodium
make clean all PEGH_OPENSSL=1 CC=clang LDFLAGS="-static -lcrypto" || clang pegh.c -DPEGH_OPENSSL -static -lcrypto -O3 -o pegh
mv pegh pegh.static.openssl
make clean all PEGH_LIBSODIUM=1 PEGH_OPENSSL=1 CC=clang LDFLAGS="-static -lcrypto" || clang pegh.c -DPEGH_LIBSODIUM -DPEGH_OPENSSL -static -lsodium -lcrypto -O3 -o pegh
2019-12-30 00:10:18 -05:00
mv pegh pegh.static.libsodium-openssl
2019-12-27 01:00:10 -05:00
./pegh.static.libsodium-openssl -h
2019-12-27 01:00:10 -05:00
ls -lah pegh.static.*
strip pegh.static.*
# print out some info about this, size, and to ensure it's actually fully static
ls -lah pegh.static.*
file pegh.static.*
ldd pegh.static.* || true
# libsodium only supports AES-256-GCM on certain CPUs that have hardware instructions for it
# we can build them regardless, but we can't test them without that, pegh prints that right away
2019-12-30 00:10:18 -05:00
export TEST_BINS="./pegh.static.openssl ./pegh.openssl ./pegh.static.libsodium-openssl ./pegh.libsodium-openssl ./pegh.static.libsodium-libressl"
2019-12-27 01:00:10 -05:00
set +e
if ./pegh.static.libsodium -h 2>&1 >/dev/null | grep '^Error: libsodium'
then
echo "CPU does not have AES support so can't run libsodium version"
else
echo "CPU has AES support so can run libsodium version"
# we can test everything
2019-12-30 00:10:18 -05:00
export TEST_BINS="$TEST_BINS ./pegh.libsodium ./pegh.static.libsodium"
2019-12-27 01:00:10 -05:00
fi
set -e
# compile dynamically linked versions (with gcc) to openssl and libsodium, then test all 4 against each other
./test.sh
echo "successfully built and tested static pegh against libsodium and openssl!"