2023-01-25 17:35:53 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-08-26 18:22:41 +01:00
|
|
|
#
|
|
|
|
# This script is run inside a docker container as part of our
|
2021-10-25 17:58:42 +01:00
|
|
|
# reproducible build process.
|
2021-08-26 18:22:41 +01:00
|
|
|
#
|
2022-05-25 12:10:55 +01:00
|
|
|
set -xeuo pipefail
|
2021-08-25 16:16:49 +01:00
|
|
|
if [ ! -f /.dockerenv ]; then
|
|
|
|
echo Not running inside Docker, build will probably not be reproducible
|
2022-02-17 17:56:33 +00:00
|
|
|
echo Use docker_reproducible_build instead to get the right environment
|
2021-08-25 16:16:49 +01:00
|
|
|
fi
|
2021-09-19 20:38:07 +01:00
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
echo usage : "$0" '<linux|windows|macos...>'
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-09-01 18:09:16 +01:00
|
|
|
|
|
|
|
: "${CARGO:=cargo}" # quotes are just to placate shellcheck
|
|
|
|
|
2021-09-20 10:08:01 +01:00
|
|
|
linux=""
|
|
|
|
windows=""
|
|
|
|
macos=""
|
|
|
|
while [ "$#" -ne 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
linux) linux=1;;
|
|
|
|
windows) windows=1;;
|
|
|
|
macos) macos=1;;
|
|
|
|
*)
|
|
|
|
echo "unknown target : $1" >&2
|
|
|
|
exit 1;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2021-08-26 07:30:05 +01:00
|
|
|
here=$(pwd)
|
2021-08-25 16:16:49 +01:00
|
|
|
|
2021-08-26 07:30:05 +01:00
|
|
|
## fix the target architecture to get reproducible builds
|
2021-09-09 18:06:05 +01:00
|
|
|
## the architecture was chosen as old enough that it should cover most usage
|
2021-10-25 17:58:42 +01:00
|
|
|
## while still supporting useful features like AES-NI. Older architectures
|
2021-08-26 07:30:05 +01:00
|
|
|
## won't be able to execute the resulting binary.
|
2021-08-25 16:16:49 +01:00
|
|
|
export CFLAGS="-march=westmere"
|
|
|
|
export RUSTFLAGS="-C target-cpu=westmere"
|
|
|
|
|
2021-10-25 17:58:42 +01:00
|
|
|
## force build to run in a fixed location. Necessary because the build path
|
2021-08-26 07:30:05 +01:00
|
|
|
## is somehow captured when compiling.
|
|
|
|
cp -a "$here" /arti
|
2021-08-25 16:16:49 +01:00
|
|
|
cd /arti
|
|
|
|
|
2022-09-01 18:05:53 +01:00
|
|
|
cargo_build () {
|
2022-09-01 18:10:24 +01:00
|
|
|
$CARGO build --locked "$@"
|
2022-09-01 18:05:53 +01:00
|
|
|
}
|
2022-09-01 18:08:00 +01:00
|
|
|
cargo_build_arti () {
|
|
|
|
cargo_build -p arti --release --features static "$@"
|
|
|
|
}
|
2022-09-01 18:05:53 +01:00
|
|
|
|
2021-09-09 18:06:05 +01:00
|
|
|
## add missing dependencies
|
2021-09-20 10:08:01 +01:00
|
|
|
apk add perl make git musl-dev
|
|
|
|
if [ -n "$linux" ]; then
|
2021-10-25 17:58:42 +01:00
|
|
|
## no additional dependencies specifically for Linux
|
2021-09-19 20:38:07 +01:00
|
|
|
|
2021-09-20 10:08:01 +01:00
|
|
|
## Build targeting x86_64-unknown-linux-musl to get a static binary
|
|
|
|
## feature "static" enable compiling some C dependencies instead of linking
|
|
|
|
## to system libraries. It is required to get a well behaving result.
|
2022-09-01 18:08:00 +01:00
|
|
|
cargo_build_arti --target x86_64-unknown-linux-musl
|
2021-09-20 10:08:01 +01:00
|
|
|
mv /arti/target/x86_64-unknown-linux-musl/release/arti "$here"/arti-linux
|
|
|
|
fi
|
|
|
|
if [ -n "$windows" ]; then
|
|
|
|
apk add mingw-w64-gcc
|
|
|
|
rustup target add x86_64-pc-windows-gnu
|
2021-09-19 20:38:07 +01:00
|
|
|
|
2021-09-20 10:08:01 +01:00
|
|
|
## Same tweaks as for Linux, plus don't insert compilation timestamp into PE headers
|
|
|
|
RUSTFLAGS="$RUSTFLAGS -C link-arg=-Wl,--no-insert-timestamp" \
|
2022-09-01 18:08:00 +01:00
|
|
|
cargo_build_arti --target x86_64-pc-windows-gnu
|
2021-09-20 10:08:01 +01:00
|
|
|
mv /arti/target/x86_64-pc-windows-gnu/release/arti.exe "$here"/arti-windows.exe
|
|
|
|
fi
|
|
|
|
if [ -n "$macos" ]; then
|
2023-04-16 12:22:18 +01:00
|
|
|
apk add bash cmake patch clang libc-dev libxml2-dev openssl-dev musl-fts-dev build-base python3 bsd-compat-headers xz
|
2021-09-20 10:08:01 +01:00
|
|
|
rustup target add x86_64-apple-darwin
|
2021-08-26 07:30:05 +01:00
|
|
|
|
2021-09-20 10:08:01 +01:00
|
|
|
mkdir -p .cargo
|
2021-11-03 19:52:22 +00:00
|
|
|
# (note: "ar" seems to be unused here. We could probably remove it?)
|
2021-09-20 10:08:01 +01:00
|
|
|
cat > .cargo/config << EOF
|
2021-09-19 20:38:07 +01:00
|
|
|
[target.x86_64-apple-darwin]
|
2021-11-03 19:52:22 +00:00
|
|
|
linker = "x86_64-apple-darwin16-clang"
|
|
|
|
ar = "x86_64-apple-darwin16-ar"
|
2021-09-19 20:38:07 +01:00
|
|
|
EOF
|
2021-11-03 19:52:22 +00:00
|
|
|
OSX_SDK_URL=https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX10.12.sdk.tar.xz
|
|
|
|
OSX_SDK_VERSION=10.12
|
|
|
|
OSX_SDK_SHA256=b314704d85934481c9927a0450db1768baf9af9efe649562fcb1a503bb44512f
|
|
|
|
OSX_SDK="MacOSX${OSX_SDK_VERSION}.sdk.tar.xz"
|
2021-08-26 07:30:05 +01:00
|
|
|
|
2021-09-20 10:08:01 +01:00
|
|
|
## don't compile clang if it's already here (CI cache?)
|
|
|
|
if [ ! -x "/arti/osxcross/target/bin/o64-clang" ]; then
|
|
|
|
git clone https://github.com/tpoechtrager/osxcross
|
|
|
|
cd osxcross
|
2021-11-03 19:52:22 +00:00
|
|
|
wget -nc "${OSX_SDK_URL}" -O tarballs/${OSX_SDK}
|
|
|
|
echo "${OSX_SDK_SHA256} tarballs/${OSX_SDK}" > ./sdk-checksum
|
|
|
|
sha256sum -c ./sdk-checksum
|
2021-09-20 10:08:01 +01:00
|
|
|
UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh
|
|
|
|
# copy it to gitlab build-dir so it may get cached
|
|
|
|
cp -r /arti/osxcross "$here"
|
2022-03-04 17:08:43 +00:00
|
|
|
cd ..
|
2021-09-20 10:08:01 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
PATH="/arti/osxcross/target/bin:$PATH" \
|
|
|
|
CC=o64-clang \
|
|
|
|
CXX=o64-clang++ \
|
2022-09-01 18:08:00 +01:00
|
|
|
cargo_build_arti --target x86_64-apple-darwin
|
2021-09-20 10:08:01 +01:00
|
|
|
mv /arti/target/x86_64-apple-darwin/release/arti "$here"/arti-macos
|
|
|
|
fi
|
2021-08-25 19:37:58 +01:00
|
|
|
|
2022-05-25 12:10:55 +01:00
|
|
|
git config --global --add safe.directory /arti
|
|
|
|
|
2021-08-29 12:48:33 +01:00
|
|
|
set +x
|
|
|
|
echo "branch :" "$(git rev-parse --abbrev-ref HEAD)"
|
|
|
|
echo "commit :" "$(git rev-parse HEAD)"
|
2021-09-20 10:08:01 +01:00
|
|
|
[ -z "$linux" ] || echo "Linux hash :" "$(sha256sum "$here"/arti-linux | cut -d " " -f 1)"
|
|
|
|
[ -z "$windows" ] || echo "Windows hash :" "$(sha256sum "$here"/arti-windows.exe | cut -d " " -f 1)"
|
|
|
|
[ -z "$macos" ] || echo "MacOS hash :" "$(sha256sum "$here"/arti-macos | cut -d " " -f 1)"
|