build-custom-car.sh (7729B)
1 #!/bin/bash 2 set -x -e -v 3 4 # This script is for building a custom version of chromium-as-release 5 6 # First argument must be the artifact name 7 ARTIFACT_NAME=$(basename $TOOLCHAIN_ARTIFACT) 8 shift 9 10 # Use the rest of the arguments as the build config for gn 11 CONFIG=$(echo $* | tr -d "'") 12 13 # Android build flag 14 IS_ANDROID=false 15 if [[ "$ARTIFACT_NAME" == *"android"* ]]; then 16 IS_ANDROID=true 17 fi 18 19 mkdir custom_car 20 cd custom_car 21 CUSTOM_CAR_DIR=$PWD 22 23 # Setup depot_tools 24 git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git 25 export PATH="$PATH:$CUSTOM_CAR_DIR/depot_tools" 26 # Bug 1901936 changes to config upstream for depot tools path 27 if [[ $(uname -s) == "Linux" ]]; then 28 export XDG_CONFIG_HOME=$CUSTOM_CAR_DIR 29 fi 30 31 # Log the current revision of depot tools for easier tracking in the future 32 DEPOT_TOOLS_REV=$(cd depot_tools && git rev-parse HEAD && cd ..) 33 echo "Current depot_tools revision: $DEPOT_TOOLS_REV" 34 35 # Set up some env variables depending on the target OS 36 # Linux is the default case, with minor adjustments for 37 # android since it is built with a linux host 38 39 # Final folder structure before compressing is 40 # the same for linux and windows 41 FINAL_BIN_PATH="src/out/Default" 42 43 # Final binary name for autoninja build sequence 44 FINAL_BIN=chrome 45 46 # Unique substring for PGO data for Linux 47 PGO_SUBSTR="chrome-linux-main" 48 49 # Default (non android) fetch name for upstream src 50 FETCH_NAME=chromium 51 52 # Android specific vars 53 if [ "$IS_ANDROID" = true ]; then 54 FETCH_NAME=android 55 PGO_SUBSTR="android64" 56 FINAL_BIN_PATH="src/out/Default/apks" 57 FINAL_BIN=chrome_public_apk 58 fi 59 60 # Logic for macosx64 61 if [[ $(uname -s) == "Darwin" ]]; then 62 # Modify the config with fetched sdk path 63 export MACOS_SYSROOT="$MOZ_FETCHES_DIR/MacOSX26.2.sdk" 64 # Bug 1990712 & 1989676 65 # HACK: Create a stub DarwinBasic.modulemap to satisfy Ninja’s dependency graph. 66 # This file does not exist in Command Line Tools SDKs. It seems only the full 67 # Xcode SDK includes DarwinBasic/DarwinFoundation modulemaps. 68 mkdir -p "$MACOS_SYSROOT/usr/include" 69 touch "$MACOS_SYSROOT/usr/include/DarwinFoundation.modulemap" 70 71 72 # Avoid mixing up the system python and toolchain python in the 73 # python path configuration 74 # https://bugs.python.org/issue22490 75 unset __PYVENV_LAUNCHER__ 76 77 # Set the SDK path for build, which is technically a higher version 78 # than what is associated with the current OS version (10.15). 79 # This should work as long as MACOSX_DEPLOYMENT_TARGET is set correctly 80 CONFIG=$(echo $CONFIG mac_sdk_path='"'$MACOS_SYSROOT'"') 81 82 # Ensure we don't use ARM64 profdata with this unique sub string 83 PGO_SUBSTR="chrome-mac-main" 84 85 # Temporary hacky way for now while we build this on intel workers. 86 # Afterwards we can replace it with a $(uname -m) == "arm64" check. 87 # Bug 1858740 88 if [[ "$ARTIFACT_NAME" == *"macosx_arm"* ]]; then 89 PGO_SUBSTR="chrome-mac-arm-main" 90 fi 91 92 # macOS final build folder is different than linux/win 93 FINAL_BIN_PATH="src/out/Default/Chromium.app" 94 fi 95 96 # Logic for win64 using the mingw environment 97 if [[ $(uname -o) == "Msys" ]]; then 98 # Setup VS 2022 99 . $GECKO_PATH/taskcluster/scripts/misc/vs-setup.sh 100 101 # Setup some environment variables for chromium build scripts 102 export DEPOT_TOOLS_WIN_TOOLCHAIN=0 103 export GYP_MSVS_OVERRIDE_PATH="$MOZ_FETCHES_DIR/VS" 104 export GYP_MSVS_VERSION=2022 105 export vs2022_install="$MOZ_FETCHES_DIR/VS" 106 export WINDOWSSDKDIR="$MOZ_FETCHES_DIR/VS/Windows Kits/10" 107 export DEPOT_TOOLS_UPDATE=1 108 export GCLIENT_PY3=1 109 # Fool GYP 110 touch "$MOZ_FETCHES_DIR/VS/VC/vcvarsall.bat" 111 112 # Construct some of our own dirs and move VS dlls + other files 113 # to a path that chromium build files & scripts are expecting 114 mkdir chrome_dll 115 cd chrome_dll 116 mkdir system32 117 cd ../ 118 pushd "$WINDOWSSDKDIR" 119 mkdir -p Debuggers/x64/ 120 popd 121 mv $MOZ_FETCHES_DIR/VS/VC/Redist/MSVC/14.44.35112/x64/Microsoft.VC143.CRT/* chrome_dll/system32/ 122 mv "$WINDOWSSDKDIR/App Certification Kit/"* "$WINDOWSSDKDIR"/Debuggers/x64/ 123 export WINDIR="$PWD/chrome_dll" 124 125 # Run glcient once first to get some windows deps 126 gclient 127 128 # Ensure we don't use WIN32 profdata with this unique sub string 129 PGO_SUBSTR="chrome-win64-main" 130 fi 131 132 # Get chromium source code and dependencies 133 mkdir chromium 134 cd chromium 135 136 fetch --no-history --nohooks $FETCH_NAME 137 138 # Setup the .gclient file to ensure pgo profiles are downloaded. 139 # For some reason we need to set --name flag even though it already exists. 140 # Currently the gclient.py file does NOT recognize --custom-var as it's own argument 141 gclient config --name src "https://chromium.googlesource.com/chromium/src.git" --custom-var="checkout_pgo_profiles=True" --unmanaged 142 143 cd src 144 145 # Log the current revision of the chromium src for easier tracking in the future 146 CHROMIUM_REV=$(git rev-parse HEAD) 147 echo "Current chromium revision: $CHROMIUM_REV" 148 149 # Amend gclient file 150 if [ "$IS_ANDROID" = true ]; then 151 echo "target_os = [ 'android' ]" >> ../.gclient 152 fi 153 154 if [[ $(uname -o) == "Msys" ]]; then 155 # For fast fetches it seems we will be missing some dummy files in windows. 156 # We can create a dummy this way to satisfy the rest of the build sequence. 157 # This is ok because we are not doing any development here and don't need 158 # the development history, but this file is still needed to proceed. 159 python3 build/util/lastchange.py -o build/util/LASTCHANGE 160 fi 161 162 if [[ $(uname -s) == "Linux" ]] || [[ $(uname -s) == "Darwin" ]]; then 163 # Bug 1847210 164 # Modifications to how the dirname and depot_tools and other env variables 165 # change how cipd is setup for Mac and Linux. 166 # Easily resolved by just running the setup script. 167 source ./third_party/depot_tools/cipd_bin_setup.sh 168 cipd_bin_setup 169 fi 170 171 # Sync again for android, after cipd bin setup 172 if [ "$IS_ANDROID" = true ]; then 173 gclient sync 174 fi 175 176 # Now we can run hooks and fetch PGO + everything else 177 gclient runhooks 178 179 # PGO data should be in src/chrome/build/pgo_profiles/ 180 # with a name like "chrome-{OS}-<some unique identifier>" 181 export PGO_DATA_DIR="$CUSTOM_CAR_DIR/chromium/src/chrome/build/pgo_profiles" 182 for entry in "$PGO_DATA_DIR"/* 183 do 184 if [ -f "$entry" ]; then 185 if [[ "$entry" == *"$PGO_SUBSTR"* ]]; then 186 echo "Found the correct profdata" 187 export PGO_DATA_PATH="$entry" 188 break 189 fi 190 fi 191 done 192 193 PGO_FILE=$PGO_DATA_PATH 194 if [[ $(uname -o) == "Msys" ]]; then 195 # Compute a relative path that the build scripts looks for. 196 # This odd pathing seems to only happen on windows 197 PGO_FILE=${PGO_DATA_PATH#*/*/*/*/*/*/*/*/*/} 198 mv $PGO_DATA_PATH build/config/compiler/pgo/ 199 fi 200 201 CONFIG=$(echo $CONFIG pgo_data_path='"'$PGO_FILE'"') 202 203 # Set up then build chrome 204 gn gen out/Default --args="$CONFIG" 205 autoninja -C out/Default $FINAL_BIN 206 207 # Make artifact smaller for win/linux 208 if [[ $(uname -s) == "Linux" ]] || [[ $(uname -o) == "Msys" ]]; then 209 if [ "$IS_ANDROID" = false ]; then 210 rm -rf out/Default/.ninjadeps 211 rm -rf out/Default/*_deps 212 rm -rf out/Default/gen/* 213 rm -rf out/Default/obj/* 214 rm -rf out/Default/thinlto-cache 215 rm -rf out/Default/*/gen/* 216 rm -rf out/Default/*/obj/* 217 fi 218 fi 219 220 # Gather binary and related files into a zip, and upload it 221 cd .. 222 mkdir chromium 223 224 mv "$FINAL_BIN_PATH" chromium 225 chmod -R +x chromium 226 227 tar -c chromium | python3 $GECKO_PATH/taskcluster/scripts/misc/zstdpy > $ARTIFACT_NAME 228 229 mkdir -p $UPLOAD_DIR 230 mv "$ARTIFACT_NAME" "$UPLOAD_DIR" 231 232 if [ "$IS_ANDROID" = true ]; then 233 # Package up symbols (lib.unstripped) from android build separately. 234 SYM_ARTIFACT="car_android_symbols.tar.zst" 235 SYM_DIR="src/out/Default/lib.unstripped" 236 tar -C "$(dirname "$SYM_DIR")" -c "$(basename "$SYM_DIR")" \ 237 | python3 "$GECKO_PATH/taskcluster/scripts/misc/zstdpy" > "$SYM_ARTIFACT" 238 mv "$SYM_ARTIFACT" "$UPLOAD_DIR" 239 fi