diff --git a/webrtc-sys/libwebrtc/build_linux.sh b/webrtc-sys/libwebrtc/build_linux.sh index ef63dc744..67f625e51 100755 --- a/webrtc-sys/libwebrtc/build_linux.sh +++ b/webrtc-sys/libwebrtc/build_linux.sh @@ -16,6 +16,7 @@ arch="" profile="release" +toolchain="sysroot" while [ "$#" -gt 0 ]; do case "$1" in @@ -35,6 +36,14 @@ while [ "$#" -gt 0 ]; do fi shift 2 ;; + --toolchain) + toolchain="$2" + if [ "$toolchain" != "sysroot" ] && [ "$toolchain" != "host" ]; then + echo "Error: Invalid value for --toolchain. Must be 'sysroot' or 'host'." + exit 1 + fi + shift 2 + ;; *) echo "Error: Unknown argument '$1'" exit 1 @@ -50,20 +59,38 @@ fi echo "Building LiveKit WebRTC - Linux" echo "Arch: $arch" echo "Profile: $profile" +echo "Toolchain: $toolchain" if [ ! -e "$(pwd)/depot_tools" ] then git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git fi +old_path="$PATH" export COMMAND_DIR=$(cd $(dirname $0); pwd) -export PATH="$(pwd)/depot_tools:$PATH" +export PATH="$PATH:$(pwd)/depot_tools" export OUTPUT_DIR="$(pwd)/src/out-$arch-$profile" export ARTIFACTS_DIR="$(pwd)/linux-$arch-$profile" +if [ "$toolchain" = "host" ]; then + export DEPOT_TOOLS_UPDATE=0 + export VPYTHON_BYPASS='manually managed python not supported by chrome operations' +fi + if [ ! -e "$(pwd)/src" ] then - gclient sync -D --no-history + if [ "$toolchain" = "host" ]; then + cd depot_tools + # We don't need those deps to build natively + git apply "$COMMAND_DIR/patches/gclient_ignore_platform_specific_deps.patch" -v --ignore-space-change --ignore-whitespace --whitespace=nowarn + cd .. + gclient sync -D --no-history --nohooks + # manually run some hooks + python3 src/build/landmines.py --landmine-scripts src/tools_webrtc/get_landmines.py --src-dir src + python3 src/build/util/lastchange.py -o src/build/util/LASTCHANGE + else + gclient sync -D --no-history + fi fi cd src @@ -71,6 +98,11 @@ git apply "$COMMAND_DIR/patches/add_licenses.patch" -v --ignore-space-change --i git apply "$COMMAND_DIR/patches/ssl_verify_callback_with_native_handle.patch" -v --ignore-space-change --ignore-whitespace --whitespace=nowarn git apply "$COMMAND_DIR/patches/add_deps.patch" -v --ignore-space-change --ignore-whitespace --whitespace=nowarn +if [ "$toolchain" = "host" ]; then + git apply "$COMMAND_DIR/patches/gn_use_system_python3.patch" -v --ignore-space-change --ignore-whitespace --whitespace=nowarn + git apply "$COMMAND_DIR/patches/generate_licenses_use_system_gn.patch" -v --ignore-space-change --ignore-whitespace --whitespace=nowarn +fi + cd third_party git apply "$COMMAND_DIR/patches/abseil_use_optional.patch" -v --ignore-space-change --ignore-whitespace --whitespace=nowarn cd .. @@ -79,7 +111,9 @@ cd .. mkdir -p "$ARTIFACTS_DIR/lib" -python3 "./src/build/linux/sysroot_scripts/install-sysroot.py" --arch="$arch" +if [ "$toolchain" = "sysroot" ]; then + python3 "./src/build/linux/sysroot_scripts/install-sysroot.py" --arch="$arch" +fi debug="false" if [ "$profile" = "debug" ]; then @@ -112,6 +146,19 @@ if [ "$debug" = "true" ]; then args="${args} is_asan=true is_lsan=true"; fi +if [ "$toolchain" = "host" ]; then + export PATH="$old_path" + [ -n "$CC" ] || export CC=clang + [ -n "$CXX" ] || export CXX=clang++ + [ -n "$AR" ] || export AR=ar + [ -n "$NM" ] || export NM=nm + args="${args} \ + custom_toolchain=\"//build/toolchain/linux/unbundle:default\" \ + host_toolchain=\"//build/toolchain/linux/unbundle:default\" \ + clang_use_chrome_plugins=false \ + use_sysroot=false"; +fi + # generate ninja files gn gen "$OUTPUT_DIR" --root="src" --args="${args}" diff --git a/webrtc-sys/libwebrtc/patches/gclient_ignore_platform_specific_deps.patch b/webrtc-sys/libwebrtc/patches/gclient_ignore_platform_specific_deps.patch new file mode 100644 index 000000000..55efc935d --- /dev/null +++ b/webrtc-sys/libwebrtc/patches/gclient_ignore_platform_specific_deps.patch @@ -0,0 +1,14 @@ +diff --git a/gclient.py b/gclient.py +index 58d5aee..8d798b2 100755 +--- a/gclient.py ++++ b/gclient.py +@@ -1134,6 +1134,9 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): + hooks_cwd = self.root.root_dir + + for dep in deps_to_add: ++ if '${arch}' in dep.name or '${platform}' in dep.name: ++ print("WARN: ignoring platform-specific dep:", dep.name) ++ continue + if dep.verify_validity(): + self.add_dependency(dep) + self._mark_as_parsed([ diff --git a/webrtc-sys/libwebrtc/patches/generate_licenses_use_system_gn.patch b/webrtc-sys/libwebrtc/patches/generate_licenses_use_system_gn.patch new file mode 100644 index 000000000..e5a940d0b --- /dev/null +++ b/webrtc-sys/libwebrtc/patches/generate_licenses_use_system_gn.patch @@ -0,0 +1,12 @@ +--- a/tools_webrtc/libs/generate_licenses.py ++++ b/tools_webrtc/libs/generate_licenses.py +@@ -175,8 +187,7 @@ class LicenseBuilder: + @staticmethod + def _run_gn(buildfile_dir, target): + cmd = [ +- sys.executable, +- os.path.join(find_depot_tools.DEPOT_TOOLS_PATH, 'gn.py'), ++ 'gn', + 'desc', + '--all', + '--format=json', diff --git a/webrtc-sys/libwebrtc/patches/gn_use_system_python3.patch b/webrtc-sys/libwebrtc/patches/gn_use_system_python3.patch new file mode 100644 index 000000000..660d950c6 --- /dev/null +++ b/webrtc-sys/libwebrtc/patches/gn_use_system_python3.patch @@ -0,0 +1,13 @@ +diff --git a/.gn b/.gn +index 5de9689..1913f0b 100644 +--- a/.gn ++++ b/.gn +@@ -13,7 +13,7 @@ buildconfig = "//build/config/BUILDCONFIG.gn" + + # The python interpreter to use by default. On Windows, this will look + # for vpython3.exe and vpython3.bat. +-script_executable = "vpython3" ++script_executable = "python3" + + # The secondary source root is a parallel directory tree where + # GN build files are placed when they can not be placed directly