From d883ae195917de2d4cb8e9b9eb073053871800c4 Mon Sep 17 00:00:00 2001 From: Henri Beauchamp Date: Fri, 5 Sep 2025 23:51:56 +0200 Subject: [PATCH] Restore m114 buildability, fix Linux issues and add Windows 192KHz patch 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 restore m114 buidability. This also makes it possible to keep building this release "indefinitely" (even in a few months or years). 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. - Added 'windows_add_192k.patch', from roxie/m137 branch. - 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 With these changes, I could get m114 to build on my ARM64 SBC. --- build/VERSION | 1 + build/VERSION.head | 1 + build/patches/windows_add_192k.patch | 22 ++++++ build/run.py | 101 +++++++++++++++++---------- 4 files changed, 88 insertions(+), 37 deletions(-) create mode 100644 build/patches/windows_add_192k.patch diff --git a/build/VERSION b/build/VERSION index 4fedf51..eb03f6a 100644 --- a/build/VERSION +++ b/build/VERSION @@ -2,3 +2,4 @@ WEBRTC_BUILD_VERSION=114.5735.08.0 WEBRTC_VERSION=114.5735.08 WEBRTC_READABLE_VERSION=M114.5735@{#7} WEBRTC_COMMIT=8c9aa75abf1aaa4bd79d5aaa70fc000565b9b564 +WEBRTC_LAST_COMMIT_DATE="2024-06-05 23:59:59 +0000" diff --git a/build/VERSION.head b/build/VERSION.head index cf0fb17..14c646b 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="" \ No newline at end of file diff --git a/build/patches/windows_add_192k.patch b/build/patches/windows_add_192k.patch new file mode 100644 index 0000000..e8ab8b5 --- /dev/null +++ b/build/patches/windows_add_192k.patch @@ -0,0 +1,22 @@ +diff --git a/modules/audio_device/win/audio_device_core_win.cc b/modules/audio_device/win/audio_device_core_win.cc +index f1cc0474fc..34eeaacc39 100644 +--- a/modules/audio_device/win/audio_device_core_win.cc ++++ b/modules/audio_device/win/audio_device_core_win.cc +@@ -1881,7 +1881,7 @@ int32_t AudioDeviceWindowsCore::InitPlayout() { + Wfx.wBitsPerSample = 16; + Wfx.cbSize = 0; + +- const int freqs[] = {48000, 44100, 16000, 96000, 32000, 8000}; ++ const int freqs[] = {48000, 44100, 16000, 96000, 32000, 8000, 192000}; + hr = S_FALSE; + + // Iterate over frequencies and channels, in order of priority +@@ -2201,7 +2201,7 @@ int32_t AudioDeviceWindowsCore::InitRecording() { + Wfx.Samples.wValidBitsPerSample = Wfx.Format.wBitsPerSample; + Wfx.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + +- const int freqs[6] = {48000, 44100, 16000, 96000, 32000, 8000}; ++ const int freqs[] = {48000, 44100, 16000, 96000, 32000, 8000, 192000}; + hr = S_FALSE; + + // Iterate over frequencies and channels, in order of priority diff --git a/build/run.py b/build/run.py index 390c75f..da9d21b 100644 --- a/build/run.py +++ b/build/run.py @@ -159,14 +159,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 @@ -187,6 +198,7 @@ def get_depot_tools(source_dir, fetch=False): 'bug_8759_workaround.patch', 'msvc-checks-template.patch', 'disable_mute_of_audio_processing.patch', + 'windows_add_192k.patch', 'crash_on_fatal_error.patch', ], 'windows_x86': [ @@ -199,6 +211,7 @@ def get_depot_tools(source_dir, fetch=False): 'bug_8759_workaround.patch', 'msvc-checks-template.patch', 'disable_mute_of_audio_processing.patch', + 'windows_add_192k.patch', 'crash_on_fatal_error.patch', ], 'windows_arm64': [ @@ -211,6 +224,7 @@ def get_depot_tools(source_dir, fetch=False): 'bug_8759_workaround.patch', 'msvc-checks-template.patch' 'disable_mute_of_audio_processing.patch', + 'windows_add_192k.patch', 'crash_on_fatal_error.patch', ], 'macos_x86_64': [ @@ -349,7 +363,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']: @@ -377,6 +390,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): @@ -390,6 +407,7 @@ def git_get_url_and_revision(dir): 'webrtc_version', 'webrtc_commit', 'webrtc_build_version', + 'webrtc_last_commit_date', ]) @@ -400,6 +418,10 @@ def archive_objects(ar, dir, output): print(files) rm_rf(output) cmd([ar, '-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', [ @@ -418,21 +440,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' - ), } @@ -464,13 +471,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 = [ @@ -492,8 +500,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 @@ -768,15 +779,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', ] @@ -790,12 +797,28 @@ def build_webrtc( 'arm_use_neon=false', 'enable_libaom=false', ] - elif target in ('ubuntu-18.04_x86_64', 'ubuntu-20.04_x86_64', 'ubuntu-22.04_x86_64'): + 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', '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", + 'rtc_use_pipewire=false', 'rtc_include_pulse_audio=false', 'rtc_include_internal_audio_device=true', ] @@ -1147,8 +1170,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' @@ -1194,7 +1220,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) @@ -1205,7 +1232,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'])