Ubuntu-20.04下编译WebRTC
记录一下Ubuntu-20.04下编译WebRTC流程.
1. 编译环境
网络原因, 使用腾讯云服务器(香港)下载源码编译.
操作系统: Ubuntu Server 20.04 LTS 64位
CPU: 2核
内存: 4GB
公网带宽: 100Mbps
实例计费模式: 按量计费
网络计费模式: 按流量计费
实例配置: 计算型C4 - 2核 4G
使用ssh登陆服务器
Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-96-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Wed 11 May 2022 10:38:43 PM CST
System load: 0.85 Processes: 132
Usage of /: 7.4% of 49.16GB Users logged in: 0
Memory usage: 6% IPv4 address for eth0: 172.19.0.3
Swap usage: 0%
当前工作路径
ubuntu@VM-0-3-ubuntu:~$ pwd
/home/ubuntu
2. 安装开发工具
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH="$PATH:/home/ubuntu/depot_tools"
3. 获取源码
下载和同步我这里大概用了30分钟.
ubuntu@VM-0-3-ubuntu:~$ pwd
/home/ubuntu
ubuntu@VM-0-3-ubuntu:~$ mkdir webrtc-checkout
ubuntu@VM-0-3-ubuntu:~$ cd webrtc-checkout/
ubuntu@VM-0-3-ubuntu:~/webrtc-checkout$ fetch --nohooks webrtc
Running: gclient root
Updating depot_tools...
WARNING: Your metrics.cfg file was invalid or nonexistent. A new one will be created.
Running: gclient config --spec 'solutions = [
{
"name": "src",
"url": "https://webrtc.googlesource.com/src.git",
"deps_file": "DEPS",
"managed": False,
"custom_deps": {},
},
]
'
Updating depot_tools...
Running: gclient sync --nohooks --with_branch_heads
Updating depot_tools...
________ running 'git -c core.deltaBaseCacheLimit=2g clone --no-checkout --progress https://webrtc.googlesource.com/src.git /home/ubuntu/webrtc-checkout/_gclient_src_db2poiqq' in '/home/ubuntu/webrtc-checkout'
Cloning into '/home/ubuntu/webrtc-checkout/_gclient_src_db2poiqq'...
remote: Sending approximately 334.42 MiB ...
remote: Counting objects: 8, done
remote: Finding sources: 100% (8/8)
remote: Total 405508 (delta 298274), reused 405503 (delta 298274)
Receiving objects: 100% (405508/405508), 334.27 MiB | 12.37 MiB/s, done.
Resolving deltas: 100% (298274/298274), done.
Syncing projects: 23% (10/43) src/testing
[0:03:27] Still working on:
[0:03:27] src/third_party
[0:03:27] src/tools
[0:03:37] Still working on:
[0:03:37] src/third_party
[0:03:37] src/tools
[0:03:47] Still working on:
[0:03:47] src/third_party
[0:03:47] src/tools
...
[0:10:51] Still working on:
[0:10:51] src/third_party
[0:10:51] src/tools
Syncing projects: 32% (14/43) src/tools/resultdb:infra/tools/result_adapter/${platform}
[0:11:51] Still working on:
[0:11:51] src/third_party
...
[0:15:31] Still working on:
[0:15:31] src/third_party
[0:15:34] Still working on:
[0:15:34] src/third_party
Syncing projects: 100% (43/43), done.
Running: git submodule foreach 'git config -f $toplevel/.git/config submodule.$name.ignore all'
Running: git config --add remote.origin.fetch '+refs/tags/*:refs/tags/*'
Running: git config diff.ignoreSubmodules all
同步
ubuntu@VM-0-3-ubuntu:~/webrtc-checkout$ gclient sync
Updating depot_tools...
Syncing projects: 100% (43/43), done.
________ running 'python3 src/build/linux/sysroot_scripts/install-sysroot.py --arch=i386' in '/home/ubuntu/webrt c-checkout'
Installing Debian bullseye i386 root image: /home/ubuntu/webrtc-checkout/src/build/linux/debian_bullseye_i386-sy sroot
Downloading https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/efd2baea14d4aa1d7ee1fa2f8f59 0eda3d96c567/debian_bullseye_i386_sysroot.tar.xz
Hook 'python3 src/build/linux/sysroot_scripts/install-sysroot.py --arch=i386' took 12.56 secs
Running hooks: 25% ( 7/27) sysroot_x64
________ running 'python3 src/build/linux/sysroot_scripts/install-sysroot.py --arch=amd64' in '/home/ubuntu/webr tc-checkout'
Installing Debian bullseye amd64 root image: /home/ubuntu/webrtc-checkout/src/build/linux/debian_bullseye_amd64- sysroot
Downloading https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/3c87f6561722292471f6d5e38df0 e554f0f4f31c/debian_bullseye_amd64_sysroot.tar.xz
Hook 'python3 src/build/linux/sysroot_scripts/install-sysroot.py --arch=amd64' took 12.84 secs
Running hooks: 40% (11/27) clang
________ running 'python3 src/tools/clang/scripts/update.py' in '/home/ubuntu/webrtc-checkout'
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Linux_x64/clang-llvmorg-15-init-9576 -g75f9e83a-3.tgz .......... Done.
Running hooks: 66% (18/27) clang_format_linux
________ running 'python3 src/third_party/depot_tools/download_from_google_storage.py --no_resume --platform=lin ux* --no_auth --bucket chromium-clang-format -s src/buildtools/linux64/clang-format.sha1' in '/home/ubuntu/webrt c-checkout'
0> Downloading src/buildtools/linux64/clang-format@dd736afb28430c9782750fc0fd5f0ed497399263...
Downloading 1 files took 17.201289 second(s)
Hook 'python3 src/third_party/depot_tools/download_from_google_storage.py --no_resume '--platform=linux*' --no_a uth --bucket chromium-clang-format -s src/buildtools/linux64/clang-format.sha1' took 17.25 secs
Running hooks: 81% (22/27) test_fonts
________ running 'download_from_google_storage --no_resume --extract --no_auth --bucket chromium-fonts -s src/th ird_party/test_fonts/test_fonts.tar.gz.sha1' in '/home/ubuntu/webrtc-checkout'
0> Downloading src/third_party/test_fonts/test_fonts.tar.gz@336e775eec536b2d785cc80eff6ac39051931286...
0> Extracting 33 entries from src/third_party/test_fonts/test_fonts.tar.gz to src/third_party/test_fonts/test_fo nts
Downloading 1 files took 9.864572 second(s)
Running hooks: 85% (23/27) msan_chained_origins
________ running 'python3 src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --bu cket chromium-instrumented-libraries -s src/third_party/instrumented_libraries/binaries/msan-chained-origins.tgz .sha1' in '/home/ubuntu/webrtc-checkout'
0> Downloading src/third_party/instrumented_libraries/binaries/msan-chained-origins.tgz@cab726298bae9c7c4ffb97bf 22d85a299932ca2f...
Downloading 1 files took 25.797409 second(s)
Hook 'python3 src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --bucket chromiu m-instrumented-libraries -s src/third_party/instrumented_libraries/binaries/msan-chained-origins.tgz.sha1' took 25.85 secs
Running hooks: 88% (24/27) msan_no_origins
________ running 'python3 src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --bu cket chromium-instrumented-libraries -s src/third_party/instrumented_libraries/binaries/msan-no-origins.tgz.sha1 ' in '/home/ubuntu/webrtc-checkout'
0> Downloading src/third_party/instrumented_libraries/binaries/msan-no-origins.tgz@3fe3aebfd1316618500622c5f2d2d ba0faacc52f...
Downloading 1 files took 23.636476 second(s)
Hook 'python3 src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --bucket chromiu m-instrumented-libraries -s src/third_party/instrumented_libraries/binaries/msan-no-origins.tgz.sha1' took 23.68 secs
Running hooks: 100% (27/27), done.
查看源码文件大小
ubuntu@VM-0-3-ubuntu:~/webrtc-checkout$ pwd
/home/ubuntu/webrtc-checkout
ubuntu@VM-0-3-ubuntu:~/webrtc-checkout$ du -sh *
18G src
4. 编译
使用gn
生成Ninja
项目文件
ubuntu@VM-0-3-ubuntu:~/webrtc-checkout$ pwd
/home/ubuntu/webrtc-checkout
ubuntu@VM-0-3-ubuntu:~/webrtc-checkout$ ls
src
ubuntu@VM-0-3-ubuntu:~/webrtc-checkout$ cd src/
ubuntu@VM-0-3-ubuntu:~/webrtc-checkout/src$ gn gen out/Release --args='is_debug=false'
Done. Made 1654 targets from 312 files in 1324ms
编译
编译了将近一个小时
若想构建所有内容使用:ninja all -C out/Default
ubuntu@VM-0-3-ubuntu:~/webrtc-checkout/src$ ninja -C out/Release
ninja: Entering directory `out/Release'
[7649/7649] STAMP obj/default.stamp
ubuntu@VM-0-3-ubuntu:~/webrtc-checkout/src$ du -sh out/
907M out/
5. 打包下载
等待下载, 这个流量计费.
ubuntu@VM-0-3-ubuntu:~$ cd /home/
ubuntu@VM-0-3-ubuntu:/home$ pwd
/home
ubuntu@VM-0-3-ubuntu:/home$ sudo tar zcvf ubuntu.tar.gz ubuntu
...
ubuntu@VM-0-3-ubuntu:/home$ du -sh ubuntu.tar.gz
14G ubuntu.tar.gz
6. 本地编译
在 Ubuntu 21.04 中测试可以编译.
这里编译和服务器上编译差不多, 简单记录下流程.
解压
tar zxvf ubuntu.tar.gz
导入depot_tools
路径到PATH
环境变量
export PATH="$PATH:/workdir/depot_tools"
编译
cd /workdir/webrtc-checkout/src
ninja -C out/Release
运行测试demo
./out/Release/peerconnection_server