From a70c61cd8b65aac05b65a036645457a2db8e1d4a Mon Sep 17 00:00:00 2001 From: klzgrad Date: Thu, 25 Jan 2018 10:06:30 -0500 Subject: [PATCH] Add build scripts --- src/build.sh | 116 ++++++++++++++++++++++++++++++++++++++++++++ src/get-clang.sh | 117 +++++++++++++++++++++++++++++++++++++++++++++ src/get-openwrt.sh | 55 +++++++++++++++++++++ src/get-sysroot.sh | 70 +++++++++++++++++++++++++++ 4 files changed, 358 insertions(+) create mode 100755 src/build.sh create mode 100755 src/get-clang.sh create mode 100755 src/get-openwrt.sh create mode 100644 src/get-sysroot.sh diff --git a/src/build.sh b/src/build.sh new file mode 100755 index 0000000000..8a99036145 --- /dev/null +++ b/src/build.sh @@ -0,0 +1,116 @@ +#!/bin/sh +set -e + +export TMPDIR="$PWD/tmp" +rm -rf "$TMPDIR" +mkdir -p "$TMPDIR" + +if [ "$1" = debug ]; then + out=out/Debug + flags=" + is_debug=true + is_component_build=true" +else + out=out/Release + flags=" + is_official_build=true + exclude_unwind_tables=true + enable_resource_allowlist_generation=false + symbol_level=0" +fi + +. ./get-sysroot.sh + +# ccache +case "$host_os" in + linux|mac) + if which ccache >/dev/null 2>&1; then + export CCACHE_SLOPPINESS=time_macros + export CCACHE_BASEDIR="$PWD" + export CCACHE_CPP2=yes + CCACHE=ccache + fi + ;; + win) + if [ -f "$HOME"/.cargo/bin/sccache* ]; then + export PATH="$PATH:$HOME/.cargo/bin" + CCACHE=sccache + fi + ;; +esac +if [ "$CCACHE" ]; then + flags="$flags + cc_wrapper=\"$CCACHE\"" +fi + +flags="$flags"' + is_clang=true + use_sysroot=false + + fatal_linker_warnings=false + treat_warnings_as_errors=false + + is_cronet_build=true + chrome_pgo_phase=2 + + enable_base_tracing=false + use_udev=false + use_aura=false + use_ozone=false + use_gio=false + use_gtk=false + use_platform_icu_alternatives=true + use_glib=false + + disable_file_support=true + enable_websockets=false + use_kerberos=false + disable_file_support=true + disable_zstd_filter=false + enable_mdns=false + enable_reporting=false + include_transport_security_state_preload_list=false + enable_device_bound_sessions=false + enable_bracketed_proxy_uris=true + + use_nss_certs=false + + enable_backup_ref_ptr_support=false + enable_dangling_raw_ptr_checks=false +' + +if [ "$WITH_SYSROOT" ]; then + flags="$flags + target_sysroot=\"//$WITH_SYSROOT\"" +fi + +if [ "$host_os" = "mac" ]; then + flags="$flags"' + enable_dsyms=false' +fi + +case "$EXTRA_FLAGS" in +*target_os=\"android\"*) + # default_min_sdk_version=24: 26 introduces unnecessary snew symbols + # is_high_end_android=true: Does not optimize for size, Uses PGO profiles + flags="$flags"' + default_min_sdk_version=24 + is_high_end_android=true' + ;; +esac + +# See https://github.com/llvm/llvm-project/issues/86430 +if [ "$target_os" = "linux" -a "$target_cpu" = "x64" ]; then + flags="$flags"' + use_cfi_icall=false' +fi + + +rm -rf "./$out" +mkdir -p out + +export DEPOT_TOOLS_WIN_TOOLCHAIN=0 + +./gn/out/gn gen "$out" --args="$flags $EXTRA_FLAGS" + +ninja -C "$out" naive diff --git a/src/get-clang.sh b/src/get-clang.sh new file mode 100755 index 0000000000..4525d5e2a4 --- /dev/null +++ b/src/get-clang.sh @@ -0,0 +1,117 @@ +#!/bin/sh +set -ex + +. ./get-sysroot.sh + +if [ "$SYSROOT_ARCH" -a ! -d ./"$WITH_SYSROOT/lib" ]; then + ./build/linux/sysroot_scripts/sysroot_creator.py build "$SYSROOT_ARCH" +fi + +if [ "$OPENWRT_FLAGS" ]; then + ./get-openwrt.sh +fi + +# Clang +# See src/tools/clang/scripts/update.py +case "$host_os" in + linux) WITH_CLANG=Linux_x64;; + win) WITH_CLANG=Win;; + mac) WITH_CLANG=Mac;; +esac +if [ "$host_os" = mac -a "$host_cpu" = arm64 ]; then + WITH_CLANG=Mac_arm64 +fi +mkdir -p third_party/llvm-build/Release+Asserts +cd tools/clang/scripts +CLANG_REVISION=$($PYTHON -c 'import update; print(update.PACKAGE_VERSION)') +cd - +echo $CLANG_REVISION >third_party/llvm-build/Release+Asserts/cr_build_revision +if [ ! -d third_party/llvm-build/Release+Asserts/bin ]; then + mkdir -p third_party/llvm-build/Release+Asserts + clang_path="clang-$CLANG_REVISION.tar.xz" + clang_url="https://commondatastorage.googleapis.com/chromium-browser-clang/$WITH_CLANG/$clang_path" + curl "$clang_url" | tar xJf - -C third_party/llvm-build/Release+Asserts +fi + +# sccache +if [ "$host_os" = win -a ! -f ~/.cargo/bin/sccache.exe ]; then + sccache_url="https://github.com/mozilla/sccache/releases/download/0.2.12/sccache-0.2.12-x86_64-pc-windows-msvc.tar.gz" + mkdir -p ~/.cargo/bin + curl -L "$sccache_url" | tar xzf - --strip=1 -C ~/.cargo/bin +fi + +# GN +# See src/DEPS +case "$host_os" in + linux) WITH_GN=linux-amd64;; + win) WITH_GN=windows-amd64;; + mac) WITH_GN=mac-amd64;; +esac +if [ "$host_os" = mac -a "$host_cpu" = arm64 ]; then + WITH_GN=mac-arm64 +fi +if [ ! -f gn/out/gn ]; then + gn_version=$(grep "'gn_version':" DEPS | cut -d"'" -f4) + mkdir -p gn/out + curl -L "https://chrome-infra-packages.appspot.com/dl/gn/gn/$WITH_GN/+/$gn_version" -o gn.zip + unzip gn.zip -d gn/out + rm gn.zip +fi + +# See src/build/config/compiler/pgo/BUILD.gn +case "$target_os" in + win) + case "$target_cpu" in + arm64) WITH_PGO=win-arm64;; + x64) WITH_PGO=win64;; + *) WITH_PGO=win32;; + esac + ;; + mac) + case "$target_cpu" in + arm64) WITH_PGO=mac-arm;; + *) WITH_PGO=mac;; + esac + ;; + linux|openwrt) + WITH_PGO=linux + ;; + android) + case "$target_cpu" in + arm64) WITH_PGO=android-arm64;; + *) WITH_PGO=android-arm32;; + esac + ;; +esac +if [ "$WITH_PGO" ]; then + PGO_PATH=$(cat chrome/build/$WITH_PGO.pgo.txt) +fi +if [ "$WITH_PGO" -a ! -f chrome/build/pgo_profiles/"$PGO_PATH" ]; then + mkdir -p chrome/build/pgo_profiles + cd chrome/build/pgo_profiles + curl --limit-rate 10M -LO "https://storage.googleapis.com/chromium-optimization-profiles/pgo_profiles/$PGO_PATH" + cd ../../.. +fi + +if [ "$target_os" = android -a ! -d third_party/android_toolchain/ndk ]; then + # https://dl.google.com/android/repository/android-ndk-r25c-linux.zip + android_ndk_version=$(grep 'default_android_ndk_version = ' build/config/android/config.gni | cut -d'"' -f2) + curl -LO https://dl.google.com/android/repository/android-ndk-$android_ndk_version-linux.zip + unzip android-ndk-$android_ndk_version-linux.zip + mkdir -p third_party/android_toolchain/ndk + cd android-ndk-$android_ndk_version + cp -r --parents sources/android/cpufeatures ../third_party/android_toolchain/ndk + cp -r --parents toolchains/llvm/prebuilt ../third_party/android_toolchain/ndk + cd .. + cd third_party/android_toolchain/ndk + find toolchains -type f -regextype egrep \! -regex \ + '.*(lib(atomic|gcc|gcc_real|compiler_rt-extras|android_support|unwind).a|crt.*o|lib(android|c|dl|log|m).so|usr/local.*|usr/include.*)' -delete + # Works around https://github.com/android/ndk/issues/2082 + # .../android/hardware_buffer.h:322:42: error: expression is not an integral constant expression + # 322 | AHARDWAREBUFFER_USAGE_FRONT_BUFFER = 1UL << 32, + # .../android/hardware_buffer.h:322:46: note: shift count 32 >= width of type 'unsigned long' (32 bits) + # 322 | AHARDWAREBUFFER_USAGE_FRONT_BUFFER = 1UL << 32, + sed -i 's/AHARDWAREBUFFER_USAGE_FRONT_BUFFER = 1UL /AHARDWAREBUFFER_USAGE_FRONT_BUFFER = 1ULL /' toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/android/hardware_buffer.h + cd - + rm -rf android-ndk-$android_ndk_version android-ndk-$android_ndk_version-linux.zip +fi diff --git a/src/get-openwrt.sh b/src/get-openwrt.sh new file mode 100755 index 0000000000..4ae0056172 --- /dev/null +++ b/src/get-openwrt.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +set -ex + +eval "$OPENWRT_FLAGS" + +sysroot=$PWD/out/sysroot-build/openwrt/$release/$arch +if [ -d $sysroot/lib ]; then + exit 0 +fi +mkdir -p $sysroot + +case "$arch" in +arm_*) abi=musl_eabi;; +*) abi=musl;; +esac + +if [ "$subtarget" ]; then + SDK_PATH=openwrt-toolchain-$release-$target-${subtarget}_gcc-${gcc_ver}_${abi}.Linux-x86_64 +else + subtarget='generic' + SDK_PATH=openwrt-toolchain-$release-${target}_gcc-${gcc_ver}_${abi}.Linux-x86_64 +fi +SDK_URL=https://downloads.openwrt.org/releases/$release/targets/$target/$subtarget/$SDK_PATH.tar.xz +rm -rf $SDK_PATH +curl $SDK_URL | tar xJf - +cd $SDK_PATH +full_root=toolchain-*_gcc-${gcc_ver}_${abi} +cat >include.txt <&2; exit 1;; +esac + +case "$(uname -m)" in + x86_64|x64) host_cpu=x64;; + x86|i386|i686) host_cpu=x86;; + arm) host_cpu=arm;; + arm64|aarch64|armv8b|armv8l) host_cpu=arm64;; + *) echo "Unsupported host CPU" >&2; exit 1;; +esac + +# See src/build/config/BUILDCONFIG.gn +if [ ! "$target_os" ]; then + target_os="$host_os" +fi + +if [ ! "$target_cpu" ]; then + target_cpu="$host_cpu" +fi + +if which python3 >/dev/null 2>/dev/null; then + PYTHON=python3 +else + PYTHON=python +fi + +# sysroot +case "$target_os" in + linux) + case "$target_cpu" in + x64) SYSROOT_ARCH=amd64;; + x86) SYSROOT_ARCH=i386;; + arm64) SYSROOT_ARCH=arm64;; + arm) SYSROOT_ARCH=armhf;; + mipsel) SYSROOT_ARCH=mipsel;; + mips64el) SYSROOT_ARCH=mips64el;; + riscv64) SYSROOT_ARCH=riscv64;; + esac + if [ "$SYSROOT_ARCH" ]; then + WITH_SYSROOT="out/sysroot-build/bullseye/bullseye_${SYSROOT_ARCH}_staging" + fi + # This is the case where running ./build.sh without EXTRA_FLAGS + # wants to avoid downloading sysroots. + if [ ! "$EXTRA_FLAGS" -a "$target_cpu" = "$host_cpu" ]; then + SYSROOT_ARCH= + WITH_SYSROOT= + fi + ;; + openwrt) + eval "$OPENWRT_FLAGS" + WITH_SYSROOT="out/sysroot-build/openwrt/$release/$arch" + ;; + android) + WITH_SYSROOT= + # https://dl.google.com/android/repository/sys-img/android/sys-img.xml + # https://dl.google.com/android/repository/sys-img/google_apis/sys-img.xml + case "$target_cpu" in + x64) WITH_ANDROID_IMG=x86_64-24_r08;; + x86) WITH_ANDROID_IMG=x86-24_r08;; + arm64) WITH_ANDROID_IMG=arm64-v8a-24_r07;; + arm) WITH_ANDROID_IMG=armeabi-v7a-24_r07;; + esac + ;; +esac