From 711aafb28ed4eaaed989bc5c284bbfa99b97830c 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 | 71 ++++++++++++++++++++++++++++++++++++++ src/get-clang.sh | 66 +++++++++++++++++++++++++++++++++++ src/get-openwrt.sh | 54 +++++++++++++++++++++++++++++ src/get-sysroot.sh | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 276 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..e79c38d28d --- /dev/null +++ b/src/build.sh @@ -0,0 +1,71 @@ +#!/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 + +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 + + 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 + enable_mdns=false + enable_reporting=false + include_transport_security_state_preload_list=false + use_nss_certs=false +' + +if [ "$WITH_SYSROOT" ]; then + flags="$flags + target_sysroot=\"//$WITH_SYSROOT\"" +fi + +if [ "$USE_AFDO" ]; then + flags="$flags"' + clang_sample_profile_path="//chrome/android/profiles/afdo.prof"' +fi + +rm -rf "./$out" +mkdir -p out + +export DEPOT_TOOLS_WIN_TOOLCHAIN=0 + +./gn/out/gn gen "$out" --args="$flags $EXTRA_FLAGS" --script-executable=$PYTHON + +ninja -C "$out" naive diff --git a/src/get-clang.sh b/src/get-clang.sh new file mode 100755 index 0000000000..883d2be1c2 --- /dev/null +++ b/src/get-clang.sh @@ -0,0 +1,66 @@ +#!/bin/sh +set -ex + +. ./get-sysroot.sh + +if [ "$BUILD_SYSROOT" -a ! -d ./"$WITH_SYSROOT/lib" ]; then + ./build/linux/sysroot_scripts/sysroot-creator-sid-naive.sh "$BUILD_SYSROOT" +fi + +if [ "$OPENWRT_FLAGS" ]; then + ./get-openwrt.sh +fi + +if [ ! -d third_party/llvm-build/Release+Asserts/bin ]; then + mkdir -p third_party/llvm-build/Release+Asserts + clang_path="clang-$CLANG_REVISION.tgz" + clang_url="https://commondatastorage.googleapis.com/chromium-browser-clang/$WITH_CLANG/$clang_path" + curl "$clang_url" | tar xzf - -C third_party/llvm-build/Release+Asserts +fi + +if [ "$USE_AFDO" -a ! -f chrome/android/profiles/afdo.prof ]; then + afdo_path=$(cat chrome/android/profiles/newest.txt) + afdo_url="https://storage.googleapis.com/chromeos-prebuilt/afdo-job/llvm/$afdo_path" + curl "$afdo_url" | bzip2 -cd >chrome/android/profiles/afdo.prof +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 [ "$USE_DSYMUTIL" -a ! -f tools/clang/dsymutil/bin/dsymutil ]; then + mkdir -p tools/clang/dsymutil + dsymutil_path="dsymutil-$CLANG_REVISION.tgz" + dsymutil_url="https://commondatastorage.googleapis.com/chromium-browser-clang-staging/Mac/$dsymutil_path" + curl "$dsymutil_url" | tar xzf - -C tools/clang/dsymutil +fi + +if [ "$USE_SCCACHE" -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 + +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-amd64/+/$gn_version" -o gn.zip + unzip gn.zip -d gn/out + rm gn.zip +fi + +if [ "$USE_ANDROID_NDK" -a ! -d third_party/android_ndk ]; then + android_ndk_version=$(grep android_ndk.git DEPS | cut -d"'" -f10) + git clone --depth=1 --filter=blob:none --no-checkout https://chromium.googlesource.com/android_ndk.git third_party/android_ndk + cd third_party/android_ndk + git sparse-checkout init --cone + git sparse-checkout set sources/android/cpufeatures toolchains/llvm/prebuilt + git -c advice.detachedHead=false checkout "$android_ndk_version" + rm -rf .git + 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 + cd ../.. +fi diff --git a/src/get-openwrt.sh b/src/get-openwrt.sh new file mode 100755 index 0000000000..cf3b992ae6 --- /dev/null +++ b/src/get-openwrt.sh @@ -0,0 +1,54 @@ +#!/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-sdk-$release-$target-${subtarget}_gcc-${gcc_ver}_${abi}.Linux-x86_64 +else + subtarget='generic' + SDK_PATH=openwrt-sdk-$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=staging_dir/toolchain-*_gcc-${gcc_ver}_${abi} +cat >include.txt </dev/null || which python 2>/dev/null) +CLANG_REVISION=$($PYTHON tools/clang/scripts/update.py --print-revision) + +eval "$EXTRA_FLAGS" +case "$ARCH" in + Linux) + if which ccache >/dev/null 2>&1; then + export CCACHE_SLOPPINESS=time_macros + export CCACHE_BASEDIR="$PWD" + export CCACHE_CPP2=yes + CCACHE=ccache + fi + WITH_CLANG=Linux_x64 + WITH_PGO=linux + WITH_GN=linux + case "$target_cpu" in + x64) WITH_QEMU=x86_64;; + x86) WITH_QEMU=i386;; + arm64) WITH_QEMU=aarch64;; + arm) WITH_QEMU=arm;; + mipsel) WITH_QEMU=mipsel;; + mips64el) WITH_QEMU=mips64el;; + esac + if [ "$OPENWRT_FLAGS" ]; then + eval "$OPENWRT_FLAGS" + WITH_SYSROOT="out/sysroot-build/openwrt/$release/$arch" + elif [ "$target_os" = android ]; then + WITH_PGO= + USE_AFDO=y + USE_ANDROID_NDK=y + WITH_SYSROOT= + 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 + else + case "$target_cpu" in + x64) sysroot_path=amd64 BUILD_SYSROOT=BuildSysrootAmd64;; + x86) sysroot_path=i386 BUILD_SYSROOT=BuildSysrootI386;; + arm64) sysroot_path=arm64 BUILD_SYSROOT=BuildSysrootARM64;; + arm) sysroot_path=arm BUILD_SYSROOT=BuildSysrootARM;; + mipsel) sysroot_path=mips BUILD_SYSROOT=BuildSysrootMips;; + mips64el) sysroot_path=mips64el BUILD_SYSROOT=BuildSysrootMips64el;; + esac + if [ "$sysroot_path" ]; then + WITH_SYSROOT="out/sysroot-build/sid/sid_${sysroot_path}_staging" + fi + fi + ;; + MINGW*|MSYS*) + if [ -f "$HOME"/.cargo/bin/sccache* ]; then + export PATH="$PATH:$HOME/.cargo/bin" + CCACHE=sccache + fi + WITH_CLANG=Win + USE_SCCACHE=y + WITH_GN=windows + case "$target_cpu" in + x64) WITH_PGO=win64;; + *) WITH_PGO=win32;; + esac + ;; + Darwin) + if which ccache >/dev/null 2>&1; then + export CCACHE_SLOPPINESS=time_macros + export CCACHE_BASEDIR="$PWD" + export CCACHE_CPP2=yes + CCACHE=ccache + fi + WITH_CLANG=Mac + USE_DSYMUTIL=y + WITH_GN=mac + case "$target_cpu" in + arm64) WITH_PGO=mac-arm;; + *) WITH_PGO=mac;; + esac + ;; +esac +if [ "$WITH_PGO" ]; then + PGO_PATH=$(cat chrome/build/$WITH_PGO.pgo.txt) +fi