Skip to content

Allow libwebrtc to build with host toolchain on Linux #648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions webrtc-sys/libwebrtc/build_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

arch=""
profile="release"
toolchain="sysroot"

while [ "$#" -gt 0 ]; do
case "$1" in
Expand All @@ -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
Expand All @@ -50,27 +59,50 @@ 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
git apply "$COMMAND_DIR/patches/add_licenses.patch" -v --ignore-space-change --ignore-whitespace --whitespace=nowarn
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 ..
Expand All @@ -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
Expand Down Expand Up @@ -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}"

Expand Down
Original file line number Diff line number Diff line change
@@ -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([
12 changes: 12 additions & 0 deletions webrtc-sys/libwebrtc/patches/generate_licenses_use_system_gn.patch
Original file line number Diff line number Diff line change
@@ -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',
13 changes: 13 additions & 0 deletions webrtc-sys/libwebrtc/patches/gn_use_system_python3.patch
Original file line number Diff line number Diff line change
@@ -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
Loading