Skip to content

Commit 7a64cdc

Browse files
committed
Add build scripts
1 parent a125330 commit 7a64cdc

File tree

4 files changed

+385
-0
lines changed

4 files changed

+385
-0
lines changed

src/build.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/sh
2+
set -e
3+
4+
export TMPDIR="$PWD/tmp"
5+
rm -rf "$TMPDIR"
6+
mkdir -p "$TMPDIR"
7+
8+
if [ "$1" = debug ]; then
9+
out=out/Debug
10+
flags="
11+
is_debug=true
12+
is_component_build=true"
13+
else
14+
out=out/Release
15+
flags="
16+
is_official_build=true
17+
exclude_unwind_tables=true
18+
enable_resource_allowlist_generation=false
19+
symbol_level=0"
20+
fi
21+
22+
. ./get-sysroot.sh
23+
24+
# ccache
25+
case "$host_os" in
26+
linux|mac)
27+
if which ccache >/dev/null 2>&1; then
28+
export CCACHE_SLOPPINESS=time_macros
29+
export CCACHE_BASEDIR="$PWD"
30+
export CCACHE_CPP2=yes
31+
CCACHE=ccache
32+
fi
33+
;;
34+
win)
35+
if [ -f "$HOME"/.cargo/bin/sccache* ]; then
36+
export PATH="$PATH:$HOME/.cargo/bin"
37+
CCACHE=sccache
38+
fi
39+
;;
40+
esac
41+
if [ "$CCACHE" ]; then
42+
flags="$flags
43+
cc_wrapper=\"$CCACHE\""
44+
fi
45+
46+
flags="$flags"'
47+
is_clang=true
48+
use_sysroot=false
49+
50+
fatal_linker_warnings=false
51+
treat_warnings_as_errors=false
52+
53+
is_cronet_build=true
54+
chrome_pgo_phase=2
55+
56+
enable_base_tracing=false
57+
use_udev=false
58+
use_aura=false
59+
use_ozone=false
60+
use_gio=false
61+
use_platform_icu_alternatives=true
62+
use_glib=false
63+
64+
disable_file_support=true
65+
enable_websockets=false
66+
use_kerberos=false
67+
disable_file_support=true
68+
disable_zstd_filter=false
69+
enable_mdns=false
70+
enable_reporting=false
71+
include_transport_security_state_preload_list=false
72+
enable_device_bound_sessions=false
73+
enable_bracketed_proxy_uris=true
74+
enable_quic_proxy_support=true
75+
76+
use_nss_certs=false
77+
78+
enable_backup_ref_ptr_support=false
79+
enable_dangling_raw_ptr_checks=false
80+
enable_shadow_metadata=false
81+
'
82+
83+
if [ "$WITH_SYSROOT" ]; then
84+
flags="$flags
85+
target_sysroot=\"//$WITH_SYSROOT\""
86+
fi
87+
88+
if [ "$host_os" = "mac" ]; then
89+
flags="$flags"'
90+
enable_dsyms=false'
91+
fi
92+
93+
case "$EXTRA_FLAGS" in
94+
*target_os=\"android\"*)
95+
# default_min_sdk_version=24: 26 introduces unnecessary snew symbols
96+
# is_high_end_android=true: Does not optimize for size, Uses PGO profiles
97+
flags="$flags"'
98+
default_min_sdk_version=24
99+
is_high_end_android=true'
100+
;;
101+
esac
102+
103+
# See https://github.com/llvm/llvm-project/issues/86430
104+
if [ "$target_os" = "linux" -a "$target_cpu" = "x64" ]; then
105+
flags="$flags"'
106+
use_cfi_icall=false'
107+
fi
108+
109+
110+
rm -rf "./$out"
111+
mkdir -p out
112+
113+
export DEPOT_TOOLS_WIN_TOOLCHAIN=0
114+
115+
./gn/out/gn gen "$out" --args="$flags $EXTRA_FLAGS"
116+
117+
ninja -C "$out" naive

src/get-clang.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/sh
2+
set -ex
3+
4+
. ./get-sysroot.sh
5+
6+
if [ "$SYSROOT_ARCH" -a ! -d ./"$WITH_SYSROOT/lib" ]; then
7+
./build/linux/sysroot_scripts/sysroot_creator.py build "$SYSROOT_ARCH"
8+
fi
9+
10+
if [ "$OPENWRT_FLAGS" ]; then
11+
./get-openwrt.sh
12+
fi
13+
14+
# Clang
15+
# See src/tools/clang/scripts/update.py
16+
case "$host_os" in
17+
linux) WITH_CLANG=Linux_x64;;
18+
win) WITH_CLANG=Win;;
19+
mac) WITH_CLANG=Mac;;
20+
esac
21+
if [ "$host_os" = mac -a "$host_cpu" = arm64 ]; then
22+
WITH_CLANG=Mac_arm64
23+
fi
24+
mkdir -p third_party/llvm-build/Release+Asserts
25+
cd tools/clang/scripts
26+
CLANG_REVISION=$($PYTHON -c 'import update; print(update.PACKAGE_VERSION)')
27+
cd -
28+
echo $CLANG_REVISION >third_party/llvm-build/Release+Asserts/cr_build_revision
29+
if [ ! -d third_party/llvm-build/Release+Asserts/bin ]; then
30+
mkdir -p third_party/llvm-build/Release+Asserts
31+
clang_path="clang-$CLANG_REVISION.tar.xz"
32+
clang_url="https://commondatastorage.googleapis.com/chromium-browser-clang/$WITH_CLANG/$clang_path"
33+
curl "$clang_url" | tar xJf - -C third_party/llvm-build/Release+Asserts
34+
fi
35+
36+
# sccache
37+
if [ "$host_os" = win -a ! -f ~/.cargo/bin/sccache.exe ]; then
38+
sccache_url="https://github.com/mozilla/sccache/releases/download/0.2.12/sccache-0.2.12-x86_64-pc-windows-msvc.tar.gz"
39+
mkdir -p ~/.cargo/bin
40+
curl -L "$sccache_url" | tar xzf - --strip=1 -C ~/.cargo/bin
41+
fi
42+
43+
# GN
44+
# See src/DEPS
45+
case "$host_os" in
46+
linux) WITH_GN=linux-amd64;;
47+
win) WITH_GN=windows-amd64;;
48+
mac) WITH_GN=mac-amd64;;
49+
esac
50+
if [ "$host_os" = mac -a "$host_cpu" = arm64 ]; then
51+
WITH_GN=mac-arm64
52+
fi
53+
if [ ! -f gn/out/gn ]; then
54+
gn_version=$(grep "'gn_version':" DEPS | cut -d"'" -f4)
55+
mkdir -p gn/out
56+
curl -L "https://chrome-infra-packages.appspot.com/dl/gn/gn/$WITH_GN/+/$gn_version" -o gn.zip
57+
unzip gn.zip -d gn/out
58+
rm gn.zip
59+
fi
60+
61+
# See src/build/config/compiler/pgo/BUILD.gn
62+
case "$target_os" in
63+
win)
64+
case "$target_cpu" in
65+
arm64) WITH_PGO=win-arm64;;
66+
x64) WITH_PGO=win64;;
67+
*) WITH_PGO=win32;;
68+
esac
69+
;;
70+
mac)
71+
case "$target_cpu" in
72+
arm64) WITH_PGO=mac-arm;;
73+
*) WITH_PGO=mac;;
74+
esac
75+
;;
76+
linux|openwrt)
77+
WITH_PGO=linux
78+
;;
79+
android)
80+
case "$target_cpu" in
81+
arm64) WITH_PGO=android-arm64;;
82+
*) WITH_PGO=android-arm32;;
83+
esac
84+
;;
85+
esac
86+
if [ "$WITH_PGO" ]; then
87+
PGO_PATH=$(cat chrome/build/$WITH_PGO.pgo.txt)
88+
fi
89+
if [ "$WITH_PGO" -a ! -f chrome/build/pgo_profiles/"$PGO_PATH" ]; then
90+
mkdir -p chrome/build/pgo_profiles
91+
cd chrome/build/pgo_profiles
92+
curl --limit-rate 10M -LO "https://storage.googleapis.com/chromium-optimization-profiles/pgo_profiles/$PGO_PATH"
93+
cd ../../..
94+
fi
95+
96+
if [ "$target_os" = android -a ! -d third_party/android_toolchain/ndk ]; then
97+
# https://dl.google.com/android/repository/android-ndk-r25c-linux.zip
98+
android_ndk_version=$(grep 'default_android_ndk_version = ' build/config/android/config.gni | cut -d'"' -f2)
99+
curl -LO https://dl.google.com/android/repository/android-ndk-$android_ndk_version-linux.zip
100+
unzip android-ndk-$android_ndk_version-linux.zip
101+
mkdir -p third_party/android_toolchain/ndk
102+
cd android-ndk-$android_ndk_version
103+
cp -r --parents sources/android/cpufeatures ../third_party/android_toolchain/ndk
104+
cp -r --parents toolchains/llvm/prebuilt ../third_party/android_toolchain/ndk
105+
cd ..
106+
cd third_party/android_toolchain/ndk
107+
find toolchains -type f -regextype egrep \! -regex \
108+
'.*(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
109+
# Works around https://github.com/android/ndk/issues/2082
110+
# .../android/hardware_buffer.h:322:42: error: expression is not an integral constant expression
111+
# 322 | AHARDWAREBUFFER_USAGE_FRONT_BUFFER = 1UL << 32,
112+
# .../android/hardware_buffer.h:322:46: note: shift count 32 >= width of type 'unsigned long' (32 bits)
113+
# 322 | AHARDWAREBUFFER_USAGE_FRONT_BUFFER = 1UL << 32,
114+
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
115+
cd -
116+
rm -rf android-ndk-$android_ndk_version android-ndk-$android_ndk_version-linux.zip
117+
fi

src/get-openwrt.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
eval "$OPENWRT_FLAGS"
6+
7+
sysroot=$PWD/out/sysroot-build/openwrt/$release/$arch
8+
if [ -d $sysroot/lib ]; then
9+
exit 0
10+
fi
11+
mkdir -p $sysroot
12+
13+
case "$arch" in
14+
arm_*) abi=musl_eabi;;
15+
*) abi=musl;;
16+
esac
17+
18+
major=${release%%.*}
19+
if [ "$major" -ge 22 ]; then
20+
path_suffix=toolchain
21+
else
22+
path_suffix=sdk
23+
fi
24+
25+
if [ "$major" -ge 24 ]; then
26+
tarball_suffix=zst
27+
else
28+
tarball_suffix=xz
29+
fi
30+
31+
if [ ! "$subtarget" ]; then
32+
subtarget=generic
33+
fi
34+
35+
if [ "$subtarget" != generic -o "$major" -ge 22 ]; then
36+
SDK_PATH=openwrt-$path_suffix-$release-$target-${subtarget}_gcc-${gcc_ver}_${abi}.Linux-x86_64
37+
else
38+
SDK_PATH=openwrt-$path_suffix-$release-${target}_gcc-${gcc_ver}_${abi}.Linux-x86_64
39+
fi
40+
SDK_URL=https://downloads.openwrt.org/releases/$release/targets/$target/$subtarget/$SDK_PATH.tar.$tarball_suffix
41+
rm -rf $SDK_PATH
42+
if [ $tarball_suffix = xz ]; then
43+
curl $SDK_URL | tar xJf -
44+
elif [ $tarball_suffix = zst ]; then
45+
curl $SDK_URL | tar --zstd -xf -
46+
fi
47+
48+
full_root=toolchain-*_gcc-${gcc_ver}_${abi}
49+
50+
if [ "$major" -lt 22 ]; then
51+
mv $SDK_PATH/staging_dir/$full_root $SDK_PATH
52+
fi
53+
54+
cd $SDK_PATH
55+
cat >include.txt <<EOF
56+
./include
57+
./lib/*.o
58+
./lib/gcc/*/libgcc.a
59+
./lib/gcc/*/libgcc_eh.a
60+
./lib/libatomic.so*
61+
./lib/libatomic.a
62+
./lib/libc.so
63+
./lib/libc.a
64+
./lib/libdl.a
65+
./lib/ld-*
66+
./lib/libgcc_s.*
67+
./lib/libm.a
68+
./lib/libpthread.a
69+
./lib/libresolv.a
70+
./lib/librt.a
71+
./usr
72+
EOF
73+
tar cf - -C $full_root --hard-dereference . | tar xf - -C $sysroot --wildcards --wildcards-match-slash -T include.txt
74+
rm -rf include.txt
75+
cd ..
76+
rm -rf $SDK_PATH
77+
78+
# LLVM does not accept muslgnueabi as the target triple environment
79+
if [ -d "$sysroot/lib/gcc/arm-openwrt-linux-muslgnueabi" ]; then
80+
mv "$sysroot/lib/gcc/arm-openwrt-linux-muslgnueabi" "$sysroot/lib/gcc/arm-openwrt-linux-musleabi"
81+
fi

src/get-sysroot.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
eval "$EXTRA_FLAGS"
2+
3+
case "$(uname)" in
4+
MINGW*|MSYS*) host_os=win;;
5+
Linux) host_os=linux;;
6+
Darwin) host_os=mac;;
7+
*) echo "Unsupported host OS" >&2; exit 1;;
8+
esac
9+
10+
case "$(uname -m)" in
11+
x86_64|x64) host_cpu=x64;;
12+
x86|i386|i686) host_cpu=x86;;
13+
arm) host_cpu=arm;;
14+
arm64|aarch64|armv8b|armv8l) host_cpu=arm64;;
15+
*) echo "Unsupported host CPU" >&2; exit 1;;
16+
esac
17+
18+
# See src/build/config/BUILDCONFIG.gn
19+
if [ ! "$target_os" ]; then
20+
target_os="$host_os"
21+
fi
22+
23+
if [ ! "$target_cpu" ]; then
24+
target_cpu="$host_cpu"
25+
fi
26+
27+
if which python3 >/dev/null 2>/dev/null; then
28+
PYTHON=python3
29+
else
30+
PYTHON=python
31+
fi
32+
33+
# sysroot
34+
case "$target_os" in
35+
linux)
36+
case "$target_cpu" in
37+
x64) SYSROOT_ARCH=amd64;;
38+
x86) SYSROOT_ARCH=i386;;
39+
arm64) SYSROOT_ARCH=arm64;;
40+
arm) SYSROOT_ARCH=armhf;;
41+
mipsel) SYSROOT_ARCH=mipsel;;
42+
mips64el) SYSROOT_ARCH=mips64el;;
43+
riscv64) SYSROOT_ARCH=riscv64;;
44+
esac
45+
if [ "$SYSROOT_ARCH" ]; then
46+
WITH_SYSROOT="out/sysroot-build/bullseye/bullseye_${SYSROOT_ARCH}_staging"
47+
fi
48+
# This is the case where running ./build.sh without EXTRA_FLAGS
49+
# wants to avoid downloading sysroots.
50+
if [ ! "$EXTRA_FLAGS" -a "$target_cpu" = "$host_cpu" ]; then
51+
SYSROOT_ARCH=
52+
WITH_SYSROOT=
53+
fi
54+
;;
55+
openwrt)
56+
eval "$OPENWRT_FLAGS"
57+
WITH_SYSROOT="out/sysroot-build/openwrt/$release/$arch"
58+
;;
59+
android)
60+
WITH_SYSROOT=
61+
# https://dl.google.com/android/repository/sys-img/android/sys-img.xml
62+
# https://dl.google.com/android/repository/sys-img/google_apis/sys-img.xml
63+
case "$target_cpu" in
64+
x64) WITH_ANDROID_IMG=x86_64-24_r08;;
65+
x86) WITH_ANDROID_IMG=x86-24_r08;;
66+
arm64) WITH_ANDROID_IMG=arm64-v8a-24_r07;;
67+
arm) WITH_ANDROID_IMG=armeabi-v7a-24_r07;;
68+
esac
69+
;;
70+
esac

0 commit comments

Comments
 (0)