From cc6daf3bea03f55a7d9487d2318d31daf2315db3 Mon Sep 17 00:00:00 2001 From: Henri Beauchamp Date: Fri, 5 Sep 2025 18:37:21 +0200 Subject: [PATCH 1/4] Fix Linux linking failures and use appropriate depot_tools version This PR brings the following fixes and changes: - In run.py, fetch a depot_tools version which matches the release date of the WebRTC SDK release we are using (and pin this depot_tools version so that it does not get automatically and spuriously updated by the build system). This ensures that the build will not fail and will use the appropriate parameters (e.g. compiler and linker options) for this particular release. This also makes it possible to build this release "indefinitely" (even in a few months or years) and with these changes backported to m114, it would be possible to build the latter today (tested by me on x86_64 and arm64 Linux systems). Note that a new WEBRTC_LAST_COMMIT_DATE entry has also been added to the VERSION file to hold this date. - In run.py, ensure that the depot_tools Python3 venv is properly bootstrapped (else, the build may fail, depending on what Python3 modules are installed or not on the host system). - In run.py, ensure that 'ranlib' is called to create an index of the native object modules, since (quoted from llvm-ar documentation): "Unlike other implementations of ranlib, llvm-ranlib indexes LLVM bitcode files, not native object modules". This way the Linux WebRTC static library can be successfully linked to a shared library using GNU ld. - 'disable_crel.patch' got added to solve the problem caused by the use of a LLVM linker's idiosyncrasie, making it impossible to link the Linux library with GNU ld. - 'gcc_fpermissive_error.patch' got added to solve compilation failures when building a Linux viewer with gcc, due to a -fpermissive/-Wchanges-meaning error in the WebRTC SDK headers themselves. - Several changes done to run.py so to allow building the library on ARM64 (arm_v8) Linux hosts. Note however that the said hosts will still need an x86_64 emulator installed (e.g. box64) because even though I did add "host_cpu=arm64" to the build parameters, the WebRTC SDK build system still uses an x86_64 LLVM toolset to build on arm64 !!! o.O So far, and while m114 builds just fine with the same method, I could not get m137 to build on my ARM64 SBC due to a double-free() error at link time in box64/lld... --- build/VERSION | 1 + build/VERSION.head | 1 + build/patches/disable_crel.patch | 17 ++++ build/patches/gcc_fpermissive_error.patch | 12 +++ build/run.py | 118 +++++++++++++++------- 5 files changed, 110 insertions(+), 39 deletions(-) create mode 100644 build/patches/disable_crel.patch create mode 100644 build/patches/gcc_fpermissive_error.patch diff --git a/build/VERSION b/build/VERSION index b083d5a..afc723f 100644 --- a/build/VERSION +++ b/build/VERSION @@ -2,3 +2,4 @@ WEBRTC_BUILD_VERSION=137.7151.03.0 WEBRTC_VERSION=137.7151.03 WEBRTC_READABLE_VERSION=M137.7151@{#3} WEBRTC_COMMIT=8538ce3b1ac15f0a1beeb5ef7c9368b73d2c0c92 +WEBRTC_LAST_COMMIT_DATE="2025-05-29 23:59:59 +0000" diff --git a/build/VERSION.head b/build/VERSION.head index cf0fb17..6d73bc5 100644 --- a/build/VERSION.head +++ b/build/VERSION.head @@ -2,3 +2,4 @@ WEBRTC_BUILD_VERSION=HEAD WEBRTC_VERSION=HEAD WEBRTC_READABLE_VERSION=HEAD WEBRTC_COMMIT=HEAD +WEBRTC_LAST_COMMIT_DATE= diff --git a/build/patches/disable_crel.patch b/build/patches/disable_crel.patch new file mode 100644 index 0000000..4cdd70a --- /dev/null +++ b/build/patches/disable_crel.patch @@ -0,0 +1,17 @@ +diff -durN sdk/build/config/compiler/BUILD.gn sdk-patched/build/config/compiler/BUILD.gn +--- sdk/build/config/compiler/BUILD.gn 2025-09-05 09:46:04.536242052 +0200 ++++ sdk-patched/build/config/compiler/BUILD.gn 2025-09-05 11:35:31.534580984 +0200 +@@ -617,13 +617,6 @@ + cflags += [ "-ffp-contract=off" ] + } + +- # Enable ELF CREL (see crbug.com/357878242) for all platforms that use ELF +- # (excluding toolchains that use an older version of LLVM). +- if (is_linux && use_lld && !llvm_android_mainline && +- default_toolchain != "//build/toolchain/cros:target") { +- cflags += [ "-Wa,--crel,--allow-experimental-crel" ] +- } +- + # TODO(crbug.com/413427035): Remove once + # https://github.com/llvm/llvm-project/pull/136867/ is landed. + if (!is_win && !llvm_android_mainline && diff --git a/build/patches/gcc_fpermissive_error.patch b/build/patches/gcc_fpermissive_error.patch new file mode 100644 index 0000000..52ffa1f --- /dev/null +++ b/build/patches/gcc_fpermissive_error.patch @@ -0,0 +1,12 @@ +diff -durN webrtc-m137/p2p/base/port_interface.h webrtc-m137-patched/p2p/base/port_interface.h +--- webrtc-m137/p2p/base/port_interface.h 2025-09-01 14:30:40.000000000 +0200 ++++ webrtc-m137-patched/p2p/base/port_interface.h 2025-09-05 15:07:36.904283022 +0200 +@@ -55,7 +55,7 @@ + virtual ~PortInterface(); + + virtual IceCandidateType Type() const = 0; +- virtual const Network* Network() const = 0; ++ virtual const webrtc::Network* Network() const = 0; + + // Methods to set/get ICE role and tiebreaker values. + virtual void SetIceRole(IceRole role) = 0; diff --git a/build/run.py b/build/run.py index 63f91aa..d19c68c 100644 --- a/build/run.py +++ b/build/run.py @@ -160,14 +160,25 @@ def enum_all_files(dir, dir2): yield os.path.relpath(os.path.join(root, file), dir2) -def get_depot_tools(source_dir, fetch=False): +def get_depot_tools(source_dir, fetch=False, date=''): dir = os.path.join(source_dir, 'depot_tools') if os.path.exists(dir): if fetch: - cmd(['git', 'fetch']) - cmd(['git', 'checkout', '-f', 'origin/HEAD']) + cmd(['git', 'fetch'], cwd=dir) + if date != '': + before = '--before="' + date + '"' + commit = cmdcap(['git', 'rev-list', '--all', '--max-count=1', before], cwd=dir) + cmd(['git', 'checkout', '-f', commit], cwd=dir) + cmd(['python3', os.path.join(dir, 'update_depot_tools_toggle.py'), '--disable'], cwd=dir) + else: + cmd(['git', 'checkout', '-f', 'origin/HEAD'], cwd=dir) else: cmd(['git', 'clone', 'https://chromium.googlesource.com/chromium/tools/depot_tools.git', dir]) + if date != '': + before = '--before="' + date + '"' + commit = cmdcap(['git', 'rev-list', '--all', '--max-count=1', before], cwd=dir) + cmd(['git', 'checkout', '-f', commit], cwd=dir) + cmd(['python3', os.path.join(dir, 'update_depot_tools_toggle.py'), '--disable'], cwd=dir) return dir @@ -284,6 +295,8 @@ def get_depot_tools(source_dir, fetch=False): 'bug_8759_workaround.patch', 'disable_mute_of_audio_processing.patch', 'crash_on_fatal_error.patch', + 'disable_crel.patch', + 'gcc_fpermissive_error.patch', ], 'ubuntu-18.04_armv8': [ 'add_license_dav1d.patch', @@ -292,6 +305,8 @@ def get_depot_tools(source_dir, fetch=False): 'bug_8759_workaround.patch', 'disable_mute_of_audio_processing.patch', 'crash_on_fatal_error.patch', + 'disable_crel.patch', + 'gcc_fpermissive_error.patch', ], 'ubuntu-20.04_armv8': [ 'add_license_dav1d.patch', @@ -300,6 +315,8 @@ def get_depot_tools(source_dir, fetch=False): 'bug_8759_workaround.patch', 'disable_mute_of_audio_processing.patch', 'crash_on_fatal_error.patch', + 'disable_crel.patch', + 'gcc_fpermissive_error.patch', ], 'ubuntu-18.04_x86_64': [ 'add_license_dav1d.patch', @@ -308,6 +325,8 @@ def get_depot_tools(source_dir, fetch=False): 'bug_8759_workaround.patch', 'disable_mute_of_audio_processing.patch', 'crash_on_fatal_error.patch', + 'disable_crel.patch', + 'gcc_fpermissive_error.patch', ], 'ubuntu-20.04_x86_64': [ 'add_license_dav1d.patch', @@ -316,6 +335,8 @@ def get_depot_tools(source_dir, fetch=False): 'bug_8759_workaround.patch', 'disable_mute_of_audio_processing.patch', 'crash_on_fatal_error.patch', + 'disable_crel.patch', + 'gcc_fpermissive_error.patch', ], 'ubuntu-22.04_x86_64': [ 'add_license_dav1d.patch', @@ -324,6 +345,8 @@ def get_depot_tools(source_dir, fetch=False): 'bug_8759_workaround.patch', 'disable_mute_of_audio_processing.patch', 'crash_on_fatal_error.patch', + 'disable_crel.patch', + 'gcc_fpermissive_error.patch', ], } @@ -351,7 +374,6 @@ def get_webrtc(source_dir, patch_dir, version, target, if not os.path.exists(os.path.join(webrtc_source_dir, 'src')): with cd(webrtc_source_dir): - cmd(['gclient']) shutil.copyfile(os.path.join(BASE_DIR, '.gclient'), '.gclient') cmd(['git', 'clone', 'https://github.com/webrtc-sdk/webrtc.git', 'src']) if target in ['android', 'android_prefixed']: @@ -379,6 +401,10 @@ def get_webrtc(source_dir, patch_dir, version, target, depth, dirs = PATCH_INFO.get(patch, (1, ['.'])) dir = os.path.join(src_dir, *dirs) apply_patch(os.path.join(patch_dir, patch), dir, depth) + try: + cmd(['ensure_bootstrap']) + except: + print('Ignore any failure to complete ensure_bootstrap, please (it is just used to import a Python3 venv)') def git_get_url_and_revision(dir): @@ -392,6 +418,7 @@ def git_get_url_and_revision(dir): 'webrtc_version', 'webrtc_commit', 'webrtc_build_version', + 'webrtc_last_commit_date', ]) @@ -401,7 +428,11 @@ def archive_objects(ar, dir, output): files = cmdcap(['find', '.', '-name', '*.o', '-not', '-path', './third_party/nasm/*']).splitlines() print(files) rm_rf(output) - cmd([ar, '-rcs', output, *files]) + cmd([ar, '--format=gnu', '-rcs', output, *files]) + # Create a sorted index of the *native object modules* for the library, + # which is unlike 'llvm-ar s' and is needed to link it against shared + # libraries with most linkers. HB + cmd(['ranlib', output]) MultistrapConfig = collections.namedtuple('MultistrapConfig', [ @@ -420,21 +451,6 @@ def archive_objects(ar, dir, output): arch='armhf', triplet='arm-linux-gnueabihf' ), - 'raspberry-pi-os_armv8': MultistrapConfig( - config_file=['raspberry-pi-os_armv8', 'rpi-raspbian.conf'], - arch='arm64', - triplet='aarch64-linux-gnu' - ), - 'ubuntu-18.04_armv8': MultistrapConfig( - config_file=['ubuntu-18.04_armv8', 'arm64.conf'], - arch='arm64', - triplet='aarch64-linux-gnu' - ), - 'ubuntu-20.04_armv8': MultistrapConfig( - config_file=['ubuntu-20.04_armv8', 'arm64.conf'], - arch='arm64', - triplet='aarch64-linux-gnu' - ), } @@ -466,13 +482,14 @@ def init_rootfs(sysroot: str, config: MultistrapConfig, force=False): COMMON_GN_ARGS = [ - "rtc_use_h264=false", - "is_component_build=false", + 'rtc_use_h264=false', + 'is_component_build=false', 'rtc_build_examples=false', - "use_rtti=true", + 'use_rtti=true', + 'use_thin_lto=false', 'rtc_build_tools=false', - "rtc_enable_protobuf=false", - "treat_warnings_as_errors=false", + 'rtc_enable_protobuf=false', + 'treat_warnings_as_errors=false', ] WEBRTC_BUILD_TARGETS_MACOS_COMMON = [ @@ -494,8 +511,11 @@ def init_rootfs(sysroot: str, config: MultistrapConfig, force=False): def get_build_targets(target): ts = [':default'] - if target not in ('windows_x86_64', 'windows_x86', 'windows_arm64', 'ios', 'macos_x86_64', 'macos_arm64', 'ubuntu-18.04_x86_64', 'ubuntu-20.04_x86_64', 'ubuntu-22.04_x86_64'): - ts += ['buildtools/third_party/libc++'] + # Linux arm targets shall also be excluded, and since even macOS targets + # are excluded below (strange: the viewer is compiled against libc++ under + # macOS...), then no target needs libc++ ! HB + #if target not in ('windows_x86_64', 'windows_x86', 'windows_arm64', 'ios', 'macos_x86_64', 'macos_arm64', 'ubuntu-18.04_x86_64', 'ubuntu-20.04_x86_64', 'ubuntu-22.04_x86_64'): + # ts += ['buildtools/third_party/libc++'] ts += WEBRTC_BUILD_TARGETS.get(target, []) return ts @@ -771,15 +791,11 @@ def build_webrtc( 'use_lld=false', ] elif target in ('raspberry-pi-os_armv6', - 'raspberry-pi-os_armv7', - 'raspberry-pi-os_armv8', - 'ubuntu-18.04_armv8', - 'ubuntu-20.04_armv8'): + 'raspberry-pi-os_armv7'): sysroot = os.path.join(source_dir, 'rootfs') - arm64_set = ("raspberry-pi-os_armv8", "ubuntu-18.04_armv8", "ubuntu-20.04_armv8") gn_args += [ 'target_os="linux"', - f'target_cpu="{"arm64" if target in arm64_set else "arm"}"', + 'target_cpu="arm"', f'target_sysroot="{sysroot}"', 'rtc_use_pipewire=false', ] @@ -793,12 +809,32 @@ def build_webrtc( 'arm_use_neon=false', 'enable_libaom=false', ] + elif target in ('raspberry-pi-os_armv8', + 'ubuntu-18.04_armv8', + 'ubuntu-20.04_armv8'): + gn_args += [ + 'host_os="linux"', + 'target_os="linux"', + 'host_cpu="arm64"', + 'target_cpu="arm64"', + 'use_custom_libcxx=false', + 'use_custom_libcxx_for_host=false', + 'clang_use_chrome_plugins=false', + 'rtc_use_x11=false', + 'rtc_use_pipewire=false', + 'rtc_include_pulse_audio=false', + 'rtc_include_internal_audio_device=true', + ] elif target in ('ubuntu-18.04_x86_64', 'ubuntu-20.04_x86_64', 'ubuntu-22.04_x86_64'): gn_args += [ + 'host_os="linux"', 'target_os="linux"', + 'target_cpu="x64"', + 'use_custom_libcxx=false', + 'use_custom_libcxx_for_host=false', + 'clang_use_chrome_plugins=false', + 'rtc_use_x11=false', 'rtc_use_pipewire=false', - "use_custom_libcxx=false", - "use_custom_libcxx_for_host=false", 'rtc_include_pulse_audio=false', 'rtc_include_internal_audio_device=true', ] @@ -1152,8 +1188,11 @@ def main(): if not hasattr(args, 'op'): parser.error('Required subcommand') - if not check_target(args.target): - raise Exception(f'Target {args.target} is not supported on your platform') + # Do not error out when the Linux distribution used to build the library is + # not known from the build system: we do not care since we use a virtual + # environment for the build... HB + #if not check_target(args.target): + # raise Exception(f'Target {args.target} is not supported on your platform') configuration = 'debug' if args.debug else 'release' @@ -1199,7 +1238,8 @@ def main(): version_info = VersionInfo( webrtc_version=version_file['WEBRTC_VERSION'], webrtc_commit=version_file['WEBRTC_COMMIT'], - webrtc_build_version=version_file['WEBRTC_BUILD_VERSION']) + webrtc_build_version=version_file['WEBRTC_BUILD_VERSION'], + webrtc_last_commit_date=version_file['WEBRTC_LAST_COMMIT_DATE']) if args.op == 'build': mkdir_p(source_dir) @@ -1210,7 +1250,7 @@ def main(): sysroot = os.path.join(source_dir, 'rootfs') init_rootfs(sysroot, MULTISTRAP_CONFIGS[args.target], args.rootfs_fetch_force) - dir = get_depot_tools(source_dir, fetch=args.depottools_fetch) + dir = get_depot_tools(source_dir, fetch=args.depottools_fetch, date=version_info.webrtc_last_commit_date) add_path(dir) if args.target in ['windows_x86_64', 'windows_x86', 'windows_arm64']: cmd(['git', 'config', '--global', 'core.longpaths', 'true']) From 0552c3e66987bd41ba4c79a9098faf329ee1e1ee Mon Sep 17 00:00:00 2001 From: Roxie Linden Date: Wed, 10 Sep 2025 16:27:16 -0700 Subject: [PATCH 2/4] ubuntu 22.04 for build and packaging --- build-cmd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-cmd.sh b/build-cmd.sh index be57185..7aa9934 100755 --- a/build-cmd.sh +++ b/build-cmd.sh @@ -26,7 +26,7 @@ case "$AUTOBUILD_PLATFORM" in autobuild="$AUTOBUILD" ;; linux*) - build_type="ubuntu-20.04_x86_64" + build_type="ubuntu-22.04_x86_64" autobuild="$AUTOBUILD" ;; *) From 0e15f03e2e07cc7ee4cd58f5394da0affaeea413 Mon Sep 17 00:00:00 2001 From: Roxie Linden Date: Wed, 10 Sep 2025 17:00:47 -0700 Subject: [PATCH 3/4] .gclient was no longer being generated, hence a build failure --- build/run.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/run.py b/build/run.py index d19c68c..2031f4c 100644 --- a/build/run.py +++ b/build/run.py @@ -374,6 +374,8 @@ def get_webrtc(source_dir, patch_dir, version, target, if not os.path.exists(os.path.join(webrtc_source_dir, 'src')): with cd(webrtc_source_dir): + os.environ['DEPOT_TOOLS_UPDATE'] = "0" + cmd(['gclient']) shutil.copyfile(os.path.join(BASE_DIR, '.gclient'), '.gclient') cmd(['git', 'clone', 'https://github.com/webrtc-sdk/webrtc.git', 'src']) if target in ['android', 'android_prefixed']: From a6b5ccc93a0dac924c985ca93a5cb7d587620a44 Mon Sep 17 00:00:00 2001 From: Roxie Linden Date: Wed, 10 Sep 2025 17:32:39 -0700 Subject: [PATCH 4/4] Tell gclient sync to sync a specific revision --- build/run.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build/run.py b/build/run.py index 2031f4c..f8789a5 100644 --- a/build/run.py +++ b/build/run.py @@ -374,8 +374,6 @@ def get_webrtc(source_dir, patch_dir, version, target, if not os.path.exists(os.path.join(webrtc_source_dir, 'src')): with cd(webrtc_source_dir): - os.environ['DEPOT_TOOLS_UPDATE'] = "0" - cmd(['gclient']) shutil.copyfile(os.path.join(BASE_DIR, '.gclient'), '.gclient') cmd(['git', 'clone', 'https://github.com/webrtc-sdk/webrtc.git', 'src']) if target in ['android', 'android_prefixed']: @@ -398,7 +396,7 @@ def get_webrtc(source_dir, patch_dir, version, target, cmd(['git', 'branch']) cmd(['git', 'checkout', '-f', version]) cmd(['git', 'clean', '-df']) - cmd(['gclient', 'sync', '-D', '--force', '--reset', '--with_branch_heads', '--jobs=8']) + cmd(['gclient', 'sync', '-D', '--force', '--reset', '--revision', version, '--with_branch_heads', '--jobs=8']) for patch in PATCHES[target]: depth, dirs = PATCH_INFO.get(patch, (1, ['.'])) dir = os.path.join(src_dir, *dirs)