| 1 | @echo off |
| 2 | |
| 3 | setlocal enabledelayedexpansion |
| 4 | |
| 5 | set arch= |
| 6 | set profile=release |
| 7 | |
| 8 | :arg_loop |
| 9 | if "%1" == "" goto end_arg_loop |
| 10 | if "%1" == "--arch" ( |
| 11 | set "arch=%2" |
| 12 | shift & shift & goto arg_loop |
| 13 | ) |
| 14 | if "%1" == "--profile" ( |
| 15 | set "profile=%2" |
| 16 | shift & shift & goto arg_loop |
| 17 | ) |
| 18 | echo Error: Unknown argument '%1' |
| 19 | exit /b 1 |
| 20 | :end_arg_loop |
| 21 | |
| 22 | if not "!arch!" == "x64" if not "!arch!" == "arm64" ( |
| 23 | echo Error: Invalid value for --arch. Must be 'x64' or 'arm64'. |
| 24 | exit /b 1 |
| 25 | ) |
| 26 | if not "!profile!" == "debug" if not "!profile!" == "release" ( |
| 27 | echo Error: Invalid value for --profile. Must be 'debug' or 'release'. |
| 28 | exit /b 1 |
| 29 | ) |
| 30 | |
| 31 | echo "Building LiveKit WebRTC - Windows" |
| 32 | echo "Arch: !arch!" |
| 33 | echo "Profile: !profile!" |
| 34 | |
| 35 | if not exist depot_tools ( |
| 36 | git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git |
| 37 | ) |
| 38 | |
| 39 | set COMMAND_DIR=%~dp0 |
| 40 | set PATH=%cd%\depot_tools;%PATH% |
| 41 | set DEPOT_TOOLS_WIN_TOOLCHAIN=0 |
| 42 | set GYP_GENERATORS=ninja,msvs-ninja |
| 43 | set GYP_MSVS_VERSION=2022 |
| 44 | set OUTPUT_DIR=src\out-!arch!-!profile! |
| 45 | set ARTIFACTS_DIR=%cd%\win-!arch!-!profile! |
| 46 | set vs2019_install=C:\Program Files\Microsoft Visual Studio\2022\Enterprise |
| 47 | |
| 48 | if not exist src ( |
| 49 | call gclient.bat sync -D --with_branch_heads --with_tags |
| 50 | ) |
| 51 | |
| 52 | cd src |
| 53 | rem Skip a patch that is already applied so the build can be rerun on the same |
| 54 | rem checkout. Stop when a patch neither applies nor is already applied, since |
| 55 | rem carrying on would build a libwebrtc that silently lacks the change. |
| 56 | for %%p in (add_licenses add_deps ssl_verify_callback_with_native_handle external_audio_source) do ( |
| 57 | call git apply --reverse --check --ignore-space-change --ignore-whitespace "%COMMAND_DIR%/patches/%%p.patch" >nul 2>&1 |
| 58 | if errorlevel 1 ( |
| 59 | echo Applying patch: %%p.patch |
| 60 | call git apply -v --ignore-space-change --ignore-whitespace --whitespace=nowarn "%COMMAND_DIR%/patches/%%p.patch" |
| 61 | if errorlevel 1 ( |
| 62 | echo Error: %%p.patch does not apply. Regenerate it against the pinned WebRTC revision, or reset a partially patched checkout with "git checkout -- ." and rerun. |
| 63 | exit /b 1 |
| 64 | ) |
| 65 | ) else ( |
| 66 | echo Patch already applied: %%p.patch |
| 67 | ) |
| 68 | ) |
| 69 | |
| 70 | copy ".vpython3" "..\" |
| 71 | |
| 72 | cd .. |
| 73 | |
| 74 | mkdir "%ARTIFACTS_DIR%\lib" |
| 75 | |
| 76 | set "debug=false" |
| 77 | if "!profile!" == "debug" ( |
| 78 | set "debug=true" |
| 79 | ) |
| 80 | |
| 81 | rem generate ninja for release |
| 82 | call gn.bat gen %OUTPUT_DIR% --root="src" ^ |
| 83 | --args="is_debug=!debug! is_clang=true target_cpu=\"!arch!\" use_custom_libcxx=false rtc_libvpx_build_vp9=true enable_libaom=true rtc_include_tests=false rtc_build_examples=false rtc_build_tools=false is_component_build=false rtc_enable_protobuf=false rtc_use_h264=true ffmpeg_branding=\"Chrome\" symbol_level=0 enable_iterator_debugging=false" |
| 84 | |
| 85 | rem build |
| 86 | ninja.exe -C %OUTPUT_DIR% :default |
| 87 | |
| 88 | rem copy static library for release build |
| 89 | copy "%OUTPUT_DIR%\obj\webrtc.lib" "%ARTIFACTS_DIR%\lib" |
| 90 | |
| 91 | rem generate license |
| 92 | call python3 "%cd%\src\tools_webrtc\libs\generate_licenses.py" ^ |
| 93 | --target :default %OUTPUT_DIR% %OUTPUT_DIR% |
| 94 | |
| 95 | copy "%OUTPUT_DIR%\obj\webrtc.ninja" "%ARTIFACTS_DIR%" |
| 96 | copy "%OUTPUT_DIR%\obj\modules\desktop_capture\desktop_capture.ninja" "%ARTIFACTS_DIR%" |
| 97 | copy "%OUTPUT_DIR%\args.gn" "%ARTIFACTS_DIR%" |
| 98 | copy "%OUTPUT_DIR%\LICENSE.md" "%ARTIFACTS_DIR%" |
| 99 | |
| 100 | rem copy header |
| 101 | xcopy src\*.h "%ARTIFACTS_DIR%\include" /C /S /I /F /H |
| 102 | xcopy src\*.inc "%ARTIFACTS_DIR%\include" /C /S /I /F /H |