Skip to content

cmake: Fix dependency download logic#13078

Open
zhangboyang wants to merge 1 commit intoobsproject:masterfrom
zhangboyang:fix_dependency_download_logic
Open

cmake: Fix dependency download logic#13078
zhangboyang wants to merge 1 commit intoobsproject:masterfrom
zhangboyang:fix_dependency_download_logic

Conversation

@zhangboyang
Copy link
Copy Markdown

Description

Previously, if download failure occurred or interrupted by Ctrl-C, the broken file is not removed. This is true for the first case because "message(FATAL_ERROR ..." stops cmake and "file(REMOVE ..." is never reached. After that, if cmake is run second time, SHA256 verification is skipped and the broken file will be used.

This patch fixes this by always checking SHA256 of the downloaded file, using a if clause. Although "file(DOWNLOAD ... EXPECTED_HASH ..." already provides same functionality, using it makes status printing harder.

Error checking of download status is also improved. The if clause now checks equality, according to cmake's documentation.

The redundant "file(REMOVE ..." is also removed.

Motivation and Context

Before applying this patch: first run, download failure

omited...
-- Setting up Pre-Built obs-deps (x64)
-- Downloading https://github.com/obsproject/obs-deps/releases/download/2025-08-23/windows-deps-2025-08-23-x64.zip
-- Downloading https://github.com/obsproject/obs-deps/releases/download/2025-08-23/windows-deps-2025-08-23-x64.zip - done
-- Setting up Pre-Built obs-deps (x64) - done
-- Setting up Pre-Built Qt6 (x64)
-- Downloading https://github.com/obsproject/obs-deps/releases/download/2025-08-23/windows-deps-qt6-2025-08-23-x64.zip
-- Downloading https://github.com/obsproject/obs-deps/releases/download/2025-08-23/windows-deps-qt6-2025-08-23-x64.zip - done
-- Setting up Pre-Built Qt6 (x64) - done
-- Setting up Chromium Embedded Framework (x64)
-- Downloading https://cdn-fastly.obsproject.com/downloads/cef_binary_6533_windows_x64_v2.zip
CMake Error at cmake/common/buildspec_common.cmake:131 (file):
  file DOWNLOAD cannot compute hash on failed download

    from url: "https://cdn-fastly.obsproject.com/downloads/cef_binary_6533_windows_x64_v2.zip"
    status: [92;"Stream error in the HTTP/2 framing layer"]
Call Stack (most recent call first):
  cmake/windows/buildspec.cmake:103 (_check_dependencies)
  cmake/windows/buildspec.cmake:110 (_check_dependencies_windows)
  cmake/windows/defaults.cmake:24 (include)
  CMakeLists.txt:15 (include)


-- Downloading https://cdn-fastly.obsproject.com/downloads/cef_binary_6533_windows_x64_v2.zip - Failure
CMake Error at cmake/common/buildspec_common.cmake:137 (message):
  Unable to download
  https://cdn-fastly.obsproject.com/downloads/cef_binary_6533_windows_x64_v2.zip,
  failed with error: "Stream error in the HTTP/2 framing layer"
Call Stack (most recent call first):
  cmake/windows/buildspec.cmake:103 (_check_dependencies)
  cmake/windows/buildspec.cmake:110 (_check_dependencies_windows)
  cmake/windows/defaults.cmake:24 (include)
  CMakeLists.txt:15 (include)


-- Configuring incomplete, errors occurred!

Second run, broken downloaded file is used and boom

omited...
-- Setting up Pre-Built obs-deps (x64)
-- Setting up Pre-Built obs-deps (x64) - done
-- Setting up Pre-Built Qt6 (x64)
-- Setting up Pre-Built Qt6 (x64) - done
-- Setting up Chromium Embedded Framework (x64)
cmake -E tar: error: ZIP decompression failed (-5)
-- Setting up Chromium Embedded Framework (x64) - done
-- Found SIMDe: C:/Users/zby/Desktop/obs-studio/.deps/obs-deps-2025-08-23-x64/include (found version "0.8.2")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
-- Found FFmpeg: C:/Users/zby/Desktop/obs-studio/.deps/obs-deps-2025-08-23-x64/bin/avformat-61.dll;C:/Users/zby/Desktop/obs-studio/.deps/obs-deps-2025-08-23-x64/bin/avutil-59.dll;C:/Users/zby/Desktop/obs-studio/.deps/obs-deps-2025-08-23-x64/bin/swscale-8.dll;C:/Users/zby/Desktop/obs-studio/.deps/obs-deps-2025-08-23-x64/bin/swresample-5.dll;C:/U
sers/zby/Desktop/obs-studio/.deps/obs-deps-2025-08-23-x64/bin/avcodec-61.dll (found suitable version "7.1", minimum required is "6.1") found components: avformat avutil swscale swresample avcodec
-- Found ZLIB: C:/Users/zby/Desktop/obs-studio/.deps/obs-deps-2025-08-23-x64/lib/zlib.lib (found version "1.3.1")
-- Found Uthash: C:/Users/zby/Desktop/obs-studio/.deps/obs-deps-2025-08-23-x64/include (found version "2.3.0")
-- Found jansson: C:/Users/zby/Desktop/obs-studio/.deps/obs-deps-2025-08-23-x64/lib/jansson.lib (found version "2.14.1")
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
-- Performing Test COMPILER_HAS_DEPRECATED
-- Performing Test COMPILER_HAS_DEPRECATED - Success
-- Found OpenGL: opengl32
-- aja: Using new libajantv2 library
CMake Warning (dev) at cmake/finders/FindLibAJANTV2.cmake:100 (message):
  Failed to find LibAJANTV2 version.
Call Stack (most recent call first):
  plugins/aja/CMakeLists.txt:10 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found LibAJANTV2: optimized;C:/Users/zby/Desktop/obs-studio/.deps/obs-deps-2025-08-23-x64/lib/ajantv2.lib;debug;C:/Users/zby/Desktop/obs-studio/.deps/obs-deps-2025-08-23-x64/lib/ajantv2d.lib (found version "0.0.0")
CMake Warning (dev) at cmake/finders/FindCEF.cmake:85 (message):
  Failed to find Chromium Embedded Framework version.
Call Stack (most recent call first):
  plugins/obs-browser/CMakeLists.txt:12 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at C:/Program Files/CMake/share/cmake-4.2/Modules/FindPackageHandleStandardArgs.cmake:290 (message):
  Could NOT find CEF: Found unsuitable version "0.0.0", but required is at
  least "95" (found CEF_IMPLIB_RELEASE-NOTFOUND)

      Reason given by package: Ensure that location of pre-compiled Chromium Embedded Framework is set as CEF_ROOT_DIR.

Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-4.2/Modules/FindPackageHandleStandardArgs.cmake:652 (_FPHSA_FAILURE_MESSAGE)
  cmake/finders/FindCEF.cmake:182 (find_package_handle_standard_args)
  plugins/obs-browser/CMakeLists.txt:12 (find_package)


-- Configuring incomplete, errors occurred!

How Has This Been Tested?

Win10 x64, Visual C++ 2022 Community, Git-2.52.0, CMake 4.2.3
Manually run cmake few times, it now correctly redownload broken dependency files.

Types of changes

Tweak (non-breaking change to improve existing functionality)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Copy link
Copy Markdown
Member

@PatTheMav PatTheMav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply move the file removal above the FATAL_ERROR message, which ensures that CMake will delete an incomplete or mismatching file?

That way the original assumption (file exists, so prior setup succeeded) is still correct and hashing of large archives or other file operations are skipped.

The main purpose of why this was implemented this way was to make re-configurations of the build system (which happens regularly and often for many maintainers) to be as fast as possible.

Running a hash check for the file on every configuration introduces the kind of overhead the implementation tries to avoid.

@zhangboyang zhangboyang force-pushed the fix_dependency_download_logic branch from b5d870d to efec774 Compare February 3, 2026 07:41
@zhangboyang
Copy link
Copy Markdown
Author

Why not simply move the file removal above the FATAL_ERROR message, which ensures that CMake will delete an incomplete or mismatching file?

That way the original assumption (file exists, so prior setup succeeded) is still correct and hashing of large archives or other file operations are skipped.

If the download progress is interrupted by Ctrl-C, the "file(REMOVE ..." will not be executed even if it is before the "message(FATAL_ERROR". So the broken file is left there and will be used next time. This patch solves the Ctrl-C problem. Although it is generally not safe to use Ctrl-C to interrupt cmake, this patch can make life easier if internet is slow or unstable.

The main purpose of why this was implemented this way was to make re-configurations of the build system (which happens regularly and often for many maintainers) to be as fast as possible.

Running a hash check for the file on every configuration introduces the kind of overhead the implementation tries to avoid.

I refactored my patch, it now use the rename approach. Please have a look :)

Copy link
Copy Markdown
Member

@PatTheMav PatTheMav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a temporary location for the actual download would've indeed been my suggested alternative to keep the intention of the original code to treat the existence of the expected file as the "sentinel" value to skip any extra evaluations, so this seems like the better solution.

Comment thread cmake/common/buildspec_common.cmake Outdated
Comment thread cmake/common/buildspec_common.cmake
Previously, if download failure occurred or interrupted by Ctrl-C, the
broken file is not removed. This is true for the first case because
"message(FATAL_ERROR ..." stops cmake and "file(REMOVE ..." is never
reached. After that, if cmake is run second time, SHA256 verification is
skipped and the broken file will be used.

This patch fixes this by using a temporary intermediate file. The file
data is downloaded into a temporary file first, then the temporary file
is atomically renamed to destination.

Error checking of download status is also improved. The if clause now
checks error code against zero more strictly, according to cmake's
documentation.
@zhangboyang zhangboyang force-pushed the fix_dependency_download_logic branch from efec774 to 58377e2 Compare February 3, 2026 17:44
Copy link
Copy Markdown
Member

@PatTheMav PatTheMav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me.

@RytoEX would appreciate you doing another sanity check/test for this.

@WizardCM WizardCM added kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. area/ci labels Mar 9, 2026
@Warchamp7 Warchamp7 added this to the OBS Studio 32.2 milestone May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ci kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants