aboutsummaryrefslogtreecommitdiff
path: root/binary_tarball/scripts/4_Build_Binary_Tarball.sh
blob: 16f77b6757d85df8aa5a0f547a40344832c5cd71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
printf "\n\n--------------------------------------- BUILD -----------------------------------------------\n";

# Setup Script Variables
srcdir=$1;
OUTPUT_TARBALL=$2;
CI_PROJECT_DIR=${CI_PROJECT_DIR:-$(realpath $(dirname $0)/../../)}
_SOURCE_CODE_BINARY_TARBALL_LOCATION="./obj*/dist/librewolf*.tar.bz2";
_MOZBUILD=$srcdir/../mozbuild

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 MOZ_NOSPAM=1
export MOZBUILD_STATE_PATH="$srcdir/mozbuild"

if [[ $CARCH == 'aarch64' ]]; then
  LDFLAGS+=" -Wl,--no-keep-memory -Wl,--reduce-memory-overheads"
fi

# 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/}"

# Prevents build from breaking in CI/CD environments
export SHELL=/bin/bash;

# Changes current folder to the source code folder
cd $srcdir;

# Runs bootstrapper to install dependencies
printf "\nRunning bootstrapper to install build dependencies (using ./mach script within source code)\n";
./mach bootstrap --application-choice=browser --no-interactive;

rm -f mozconfig

# Do 3-tier PGO
echo "Building instrumented browser..."

if [[ $CARCH == 'aarch64' ]]; then

cat >.mozconfig ${CI_PROJECT_DIR}/mozconfig - <<END
ac_add_options --enable-profile-generate
END

else

cat >.mozconfig ${CI_PROJECT_DIR}/mozconfig - <<END
ac_add_options --enable-profile-generate=cross
END

fi

# Executes the actual build
printf "\nBuilding LibreWolf\n";
./mach build;

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."
  exit 1
fi

if [[ ! -s jarlog ]]; then
  echo "No jar log produced."
  exit 1
fi

echo "Removing instrumented browser..."
./mach clobber

echo "Building optimized browser..."

if [[ $CARCH == 'aarch64' ]]; then

cat >.mozconfig ${CI_PROJECT_DIR}/mozconfig - <<END
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

cat >.mozconfig ${CI_PROJECT_DIR}/mozconfig - <<END
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.

# Packages the build into a binary tarball
printf "\nPackaging LibreWolf\n";
./mach package;

# Moves the packaged tarball to the specified location
printf "\nMoving Binary Tarball to output location\n";
mv $_SOURCE_CODE_BINARY_TARBALL_LOCATION $OUTPUT_TARBALL;

# Deletes the source code
printf "\nDeleting source code\n";
rm -rf $srcdir;

bgstack15