2020-03-07 19:44:22 +01:00
|
|
|
#!/bin/bash
|
2019-07-21 07:30:19 +02:00
|
|
|
printf "\n\n--------------------------------------- BUILD -----------------------------------------------\n";
|
2019-07-17 20:50:38 +02:00
|
|
|
|
2019-07-21 07:30:19 +02:00
|
|
|
# Setup Script Variables
|
2020-03-28 23:18:19 +01:00
|
|
|
srcdir=$1;
|
2019-07-17 20:50:38 +02:00
|
|
|
OUTPUT_TARBALL=$2;
|
2020-03-28 23:15:41 +01:00
|
|
|
CI_PROJECT_DIR=${CI_PROJECT_DIR:-$(realpath $(dirname $0)/../../)}
|
2019-07-21 07:30:19 +02:00
|
|
|
_SOURCE_CODE_BINARY_TARBALL_LOCATION="./obj*/dist/librewolf*.tar.bz2";
|
2020-03-29 01:27:47 +01:00
|
|
|
_MOZBUILD=$srcdir/../mozbuild
|
|
|
|
|
2020-03-29 11:23:57 +02:00
|
|
|
# we do change / unset some of them later, but setting them as set by Arch
|
|
|
|
# might make it easier to maintain changes in build scripts on both sides
|
|
|
|
|
|
|
|
if [[ $CARCH == 'aarch64' ]]; then
|
|
|
|
export CPPFLAGS="-D_FORTIFY_SOURCE=2"
|
|
|
|
export CFLAGS="-march=armv8-a -O2 -pipe -fstack-protector-strong -fno-plt"
|
|
|
|
export CXXFLAGS="-march=armv8-a -O2 -pipe -fstack-protector-strong -fno-plt"
|
|
|
|
export LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"
|
|
|
|
else
|
|
|
|
export CPPFLAGS="-D_FORTIFY_SOURCE=2"
|
|
|
|
export CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fno-plt"
|
|
|
|
export CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fno-plt"
|
|
|
|
export LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"
|
|
|
|
fi
|
2019-07-17 20:50:38 +02:00
|
|
|
|
2020-03-28 23:15:41 +01:00
|
|
|
export MOZ_NOSPAM=1
|
2020-03-29 11:23:57 +02:00
|
|
|
export MOZBUILD_STATE_PATH="${_MOZBUILD}"
|
2020-03-28 23:15:41 +01:00
|
|
|
|
2020-03-29 01:27:47 +01:00
|
|
|
if [[ $CARCH == 'aarch64' ]]; then
|
|
|
|
LDFLAGS+=" -Wl,--no-keep-memory -Wl,--reduce-memory-overheads"
|
|
|
|
fi
|
|
|
|
|
2020-03-28 23:15:41 +01:00
|
|
|
# LTO needs more open files
|
|
|
|
ulimit -n 4096
|
|
|
|
|
|
|
|
# -fno-plt with cross-LTO causes obscure LLVM errors
|
|
|
|
# LLVM ERROR: Function Import: link error
|
|
|
|
CFLAGS="${CFLAGS/-fno-plt/}"
|
|
|
|
CXXFLAGS="${CXXFLAGS/-fno-plt/}"
|
|
|
|
|
2019-07-17 22:22:03 +02:00
|
|
|
# Prevents build from breaking in CI/CD environments
|
|
|
|
export SHELL=/bin/bash;
|
|
|
|
|
2019-07-21 07:30:19 +02:00
|
|
|
# Changes current folder to the source code folder
|
2020-03-28 23:18:19 +01:00
|
|
|
cd $srcdir;
|
2019-07-17 20:50:38 +02:00
|
|
|
|
2020-03-29 00:29:09 +01:00
|
|
|
# Runs bootstrapper to install dependencies
|
|
|
|
printf "\nRunning bootstrapper to install build dependencies (using ./mach script within source code)\n";
|
2020-03-29 11:36:10 +02:00
|
|
|
./mach bootstrap --application-choice=browser --no-interactive
|
2020-03-29 00:29:09 +01:00
|
|
|
|
2020-03-29 11:23:57 +02:00
|
|
|
# add cargo binary to path
|
|
|
|
source /root/.cargo/env
|
|
|
|
|
2020-03-29 12:20:30 +02:00
|
|
|
# Runs bootstrapper agin to install dependencies (like cbindgen)
|
|
|
|
printf "\nRunning bootstrapper to install remaining build dependencies (using ./mach script within source code)\n";
|
|
|
|
./mach bootstrap --application-choice=browser --no-interactive
|
|
|
|
|
2020-03-29 00:38:17 +01:00
|
|
|
rm -f mozconfig
|
2020-03-29 00:29:09 +01:00
|
|
|
|
2020-03-28 23:15:41 +01:00
|
|
|
# Do 3-tier PGO
|
|
|
|
echo "Building instrumented browser..."
|
|
|
|
|
|
|
|
if [[ $CARCH == 'aarch64' ]]; then
|
|
|
|
|
2020-03-29 01:27:47 +01:00
|
|
|
cat >.mozconfig ${CI_PROJECT_DIR}/mozconfig - <<END
|
2020-03-28 23:15:41 +01:00
|
|
|
ac_add_options --enable-profile-generate
|
|
|
|
END
|
|
|
|
|
|
|
|
else
|
|
|
|
|
2020-03-29 01:27:47 +01:00
|
|
|
cat >.mozconfig ${CI_PROJECT_DIR}/mozconfig - <<END
|
2020-03-28 23:15:41 +01:00
|
|
|
ac_add_options --enable-profile-generate=cross
|
|
|
|
END
|
|
|
|
|
|
|
|
fi
|
2019-07-17 20:50:38 +02:00
|
|
|
|
2019-07-21 07:30:19 +02:00
|
|
|
# Executes the actual build
|
2019-07-17 20:50:38 +02:00
|
|
|
printf "\nBuilding LibreWolf\n";
|
|
|
|
./mach build;
|
|
|
|
|
2020-03-28 23:15:41 +01:00
|
|
|
echo "Profiling instrumented browser..."
|
|
|
|
./mach package
|
|
|
|
LLVM_PROFDATA=llvm-profdata \
|
|
|
|
JARLOG_FILE="$PWD/jarlog" \
|
|
|
|
xvfb-run -s "-screen 0 1920x1080x24 -nolisten local" \
|
|
|
|
./mach python build/pgo/profileserver.py
|
|
|
|
|
|
|
|
if [[ ! -s merged.profdata ]]; then
|
|
|
|
echo "No profile data produced."
|
2020-03-29 00:18:58 +01:00
|
|
|
exit 1
|
2020-03-28 23:15:41 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -s jarlog ]]; then
|
|
|
|
echo "No jar log produced."
|
2020-03-29 00:18:58 +01:00
|
|
|
exit 1
|
2020-03-28 23:15:41 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Removing instrumented browser..."
|
|
|
|
./mach clobber
|
|
|
|
|
|
|
|
echo "Building optimized browser..."
|
|
|
|
|
|
|
|
if [[ $CARCH == 'aarch64' ]]; then
|
|
|
|
|
2020-03-29 01:27:47 +01:00
|
|
|
cat >.mozconfig ${CI_PROJECT_DIR}/mozconfig - <<END
|
2020-03-28 23:15:41 +01:00
|
|
|
ac_add_options --enable-lto
|
|
|
|
ac_add_options --enable-profile-use
|
|
|
|
ac_add_options --with-pgo-profile-path=${PWD@Q}/merged.profdata
|
|
|
|
ac_add_options --with-pgo-jarlog=${PWD@Q}/jarlog
|
|
|
|
# seems to break on arm
|
|
|
|
# ac_add_options --enable-linker=gold
|
|
|
|
END
|
|
|
|
|
|
|
|
else
|
|
|
|
|
2020-03-29 01:27:47 +01:00
|
|
|
cat >.mozconfig ${CI_PROJECT_DIR}/mozconfig - <<END
|
2020-03-28 23:15:41 +01:00
|
|
|
ac_add_options --enable-lto=cross
|
|
|
|
ac_add_options --enable-profile-use=cross
|
|
|
|
ac_add_options --with-pgo-profile-path=${PWD@Q}/merged.profdata
|
|
|
|
ac_add_options --with-pgo-jarlog=${PWD@Q}/jarlog
|
|
|
|
ac_add_options --enable-linker=gold
|
|
|
|
END
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
./mach build
|
|
|
|
|
|
|
|
echo "Building symbol archive..."
|
|
|
|
./mach buildsymbols
|
|
|
|
|
|
|
|
# End "build()" equivalent.
|
|
|
|
|
2019-07-21 07:30:19 +02:00
|
|
|
# Packages the build into a binary tarball
|
2019-07-17 20:50:38 +02:00
|
|
|
printf "\nPackaging LibreWolf\n";
|
|
|
|
./mach package;
|
|
|
|
|
2019-07-21 07:30:19 +02:00
|
|
|
# Moves the packaged tarball to the specified location
|
2019-07-17 20:50:38 +02:00
|
|
|
printf "\nMoving Binary Tarball to output location\n";
|
2019-07-21 07:30:19 +02:00
|
|
|
mv $_SOURCE_CODE_BINARY_TARBALL_LOCATION $OUTPUT_TARBALL;
|
2019-07-17 20:50:38 +02:00
|
|
|
|
2019-07-21 07:30:19 +02:00
|
|
|
# Deletes the source code
|
|
|
|
printf "\nDeleting source code\n";
|
2020-03-28 23:18:19 +01:00
|
|
|
rm -rf $srcdir;
|
2019-07-17 20:50:38 +02:00
|
|
|
|