Skip to content

Commit b0555a1

Browse files
authored
Refactor update checker to use CurlClient only (#658)
Removed platform-specific URLSessionClient (macOS) and WinRTHttpClient (Windows) implementations in favor of a unified CurlClient for all platforms. Added vcpkg configuration, overlay ports, and custom triplets for dependency management. Updated build scripts, CMake files, and CI workflows to use vcpkg and CurlClient. Improved .gitignore and added gersemi configuration.
1 parent 875ffda commit b0555a1

File tree

19 files changed

+372
-146
lines changed

19 files changed

+372
-146
lines changed

.gersemirc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/master/gersemi/configuration.schema.json
2+
3+
definitions: []
4+
line_length: 120
5+
indent: 2
6+
list_expansion: favour-inlining
7+
unsafe: false
8+
warn_about_unknown_commands: false
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/bin/bash
2+
3+
# Exit the script if a command fails, an undefined variable is used,
4+
# or a command in a pipe fails.
5+
set -euo pipefail
6+
7+
#================================================================
8+
# Configuration
9+
#================================================================
10+
11+
# Project root directory (parent directory of this script)
12+
readonly CMAKE_SOURCE_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)
13+
14+
# vcpkg root directory (uses VCPKG_ROOT env var, falling back to VCPG_INSTALL_ROOT)
15+
readonly VCPKG_ROOT="${VCPKG_ROOT:-$VCPKG_INSTALLATION_ROOT}"
16+
17+
# Names of the triplets for each architecture
18+
readonly TRIPLET_ARM64="arm64-osx-obs"
19+
readonly TRIPLET_X64="x64-osx-obs"
20+
21+
# Root directory where vcpkg will install the build artifacts
22+
readonly VCPKG_BUILD_OUTPUT_DIR="${CMAKE_SOURCE_DIR}/vcpkg_installed"
23+
24+
# Output directory for the final universal libraries and binaries
25+
readonly DIR_UNIVERSAL="${VCPKG_BUILD_OUTPUT_DIR}/universal-osx-obs"
26+
27+
#================================================================
28+
# Logging Helpers
29+
#================================================================
30+
31+
# Constants for colored output
32+
readonly COLOR_BLUE='\033[1;34m'
33+
readonly COLOR_GREEN='\033[1;32m'
34+
readonly COLOR_YELLOW='\033[1;33m'
35+
readonly COLOR_NONE='\033[0m'
36+
37+
log_info() {
38+
echo -e "${COLOR_BLUE}==> ${1}${COLOR_NONE}"
39+
}
40+
41+
log_success() {
42+
echo -e "${COLOR_GREEN}--> ${1}${COLOR_NONE}"
43+
}
44+
45+
log_warn() {
46+
echo -e "${COLOR_YELLOW}!!> ${1}${COLOR_NONE}"
47+
}
48+
49+
#================================================================
50+
# Script Functions
51+
#================================================================
52+
53+
# A robust function to process a directory:
54+
# - Combines *.a files using lipo.
55+
# - Copies all other file types.
56+
# - Preserves subdirectory structure.
57+
# Arg1: The subdirectory name relative to the install root (e.g., "lib", "debug/lib", "tools")
58+
process_directory() {
59+
local subdir="${1}"
60+
log_info "Processing directory: '${subdir}'..."
61+
62+
local dir_arm64="${VCPKG_BUILD_OUTPUT_DIR}/${TRIPLET_ARM64}/${TRIPLET_ARM64}/${subdir}"
63+
local dir_x64="${VCPKG_BUILD_OUTPUT_DIR}/${TRIPLET_X64}/${TRIPLET_X64}/${subdir}"
64+
local dir_universal_out="${DIR_UNIVERSAL}/${subdir}"
65+
66+
if [ ! -d "${dir_arm64}" ]; then
67+
log_warn "Source directory '${dir_arm64}' not found, skipping."
68+
return
69+
fi
70+
71+
# Find all files in the subdirectory, using the arm64 directory as the reference
72+
find "${dir_arm64}" -type f | while read -r file_arm64; do
73+
# Get the relative path from the subdirectory base (e.g., "pkgconfig/libfoo.pc")
74+
local relative_path="${file_arm64#${dir_arm64}/}"
75+
76+
# Construct the path for the x64 and universal files
77+
local file_x64="${dir_x64}/${relative_path}"
78+
local file_universal="${dir_universal_out}/${relative_path}"
79+
80+
# Ensure the destination subdirectory exists
81+
mkdir -p "$(dirname "${file_universal}")"
82+
83+
# Check if the file is a static library (*.a)
84+
if [[ "${file_arm64}" == *.a ]]; then
85+
# This is a static library, try to combine it with lipo
86+
if [ -f "${file_x64}" ]; then
87+
log_success "Combining: ${relative_path}"
88+
lipo -create -output "${file_universal}" "${file_arm64}" "${file_x64}"
89+
else
90+
log_warn "Matching .a file for '${relative_path}' not found in x64 dir. Copying arm64 version."
91+
cp -a "${file_arm64}" "${file_universal}"
92+
fi
93+
else
94+
# Not a static library, so just copy it from the arm64 source
95+
log_success "Copying: ${relative_path}"
96+
cp -a "${file_arm64}" "${file_universal}"
97+
fi
98+
done
99+
}
100+
101+
#================================================================
102+
# Main Logic
103+
#================================================================
104+
105+
main() {
106+
if [ ! -f "${VCPKG_ROOT}/vcpkg" ]; then
107+
echo "Error: vcpkg not found at '${VCPKG_ROOT}'." >&2
108+
echo "Please set the VCPKG_ROOT environment variable or adjust the script." >&2
109+
exit 1
110+
fi
111+
112+
log_info "Starting vcpkg builds for required architectures..."
113+
114+
"${VCPKG_ROOT}/vcpkg" install --triplet "${TRIPLET_ARM64}" --x-install-root="${VCPKG_BUILD_OUTPUT_DIR}/${TRIPLET_ARM64}"
115+
sleep 1
116+
"${VCPKG_ROOT}/vcpkg" install --triplet "${TRIPLET_X64}" --x-install-root="${VCPKG_BUILD_OUTPUT_DIR}/${TRIPLET_X64}"
117+
log_success "vcpkg builds completed."
118+
119+
log_info "Setting up universal directory structure at ${DIR_UNIVERSAL}..."
120+
rm -rf "${DIR_UNIVERSAL}"
121+
mkdir -p "${DIR_UNIVERSAL}"
122+
123+
local arm64_source_dir="${VCPKG_BUILD_OUTPUT_DIR}/${TRIPLET_ARM64}/${TRIPLET_ARM64}"
124+
125+
log_info "Copying top-level architecture-independent directories..."
126+
# cp -a preserves permissions, links, and timestamps, similar to rsync -a
127+
# The '/.' at the end of the source path copies the contents of the directory
128+
cp -a "${arm64_source_dir}/include/." "${DIR_UNIVERSAL}/include/"
129+
if [ -d "${arm64_source_dir}/share" ]; then
130+
cp -a "${arm64_source_dir}/share/." "${DIR_UNIVERSAL}/share/"
131+
fi
132+
log_success "Directories copied."
133+
134+
# Process directories containing binaries and libraries
135+
process_directory "lib"
136+
process_directory "debug/lib"
137+
process_directory "tools"
138+
139+
log_success "All universal files have been created successfully in ${DIR_UNIVERSAL}"
140+
}
141+
142+
# Start script execution
143+
main "$@"

.github/workflows/build-project.yaml

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,18 @@ jobs:
161161
notarizationUser: ${{ secrets.MACOS_NOTARIZATION_USERNAME }}
162162
notarizationPassword: ${{ secrets.MACOS_NOTARIZATION_PASSWORD }}
163163

164-
# - name: Checkout vcpkg repository
165-
# uses: actions/checkout@v5
166-
# with:
167-
# repository: microsoft/vcpkg
168-
# path: ${{ env.VCPKG_ROOT }}
164+
- name: Checkout vcpkg repository
165+
uses: actions/checkout@v5
166+
with:
167+
repository: microsoft/vcpkg
168+
path: ${{ env.VCPKG_ROOT }}
169169

170-
# - name: Bootstrap vcpkg
171-
# working-directory: ${{ env.VCPKG_ROOT }}
172-
# run: ./bootstrap-vcpkg.sh
170+
- name: Bootstrap vcpkg
171+
working-directory: ${{ env.VCPKG_ROOT }}
172+
run: ./bootstrap-vcpkg.sh
173173

174-
# - name: Install mono
175-
# run: brew install mono
174+
- name: Install mono
175+
run: brew install mono
176176

177177
# - name: "Setup NuGet Credentials"
178178
# run: |
@@ -184,8 +184,8 @@ jobs:
184184
# -UserName "${{ github.repository_owner }}" \
185185
# -Password "${{ secrets.GITHUB_TOKEN }}"
186186

187-
# - name: "Install dependencies from vcpkg"
188-
# run: ".github/scripts/install-vcpkg-macos.bash"
187+
- name: "Install dependencies from vcpkg"
188+
run: ".github/scripts/install-vcpkg-macos.bash"
189189

190190
- name: Build Plugin 🧱
191191
uses: ./.github/actions/build-plugin
@@ -270,12 +270,12 @@ jobs:
270270
repository: microsoft/vcpkg
271271
path: ${{ env.VCPKG_ROOT }}
272272

273-
# - name: Bootstrap vcpkg
274-
# working-directory: ${{ env.VCPKG_ROOT }}
275-
# run: ./bootstrap-vcpkg.sh
273+
- name: Bootstrap vcpkg
274+
working-directory: ${{ env.VCPKG_ROOT }}
275+
run: ./bootstrap-vcpkg.sh
276276

277-
# - name: Install mono
278-
# run: sudo apt-get -y install mono-devel
277+
- name: Install mono
278+
run: sudo apt-get -y install mono-devel
279279

280280
# - name: "Setup NuGet Credentials"
281281
# run: |
@@ -289,8 +289,8 @@ jobs:
289289
# mono "$NUGET_PATH" setapikey "${{ secrets.GITHUB_TOKEN }}" \
290290
# -Source "https://nuget.pkg.github.com/kaito-tokyo/index.json"
291291

292-
# - name: "Install dependencies from vcpkg"
293-
# run: "$VCPKG_ROOT/vcpkg install --triplet x64-linux-obs"
292+
- name: "Install dependencies from vcpkg"
293+
run: "$VCPKG_ROOT/vcpkg install --triplet x64-linux-obs"
294294

295295
- name: Build Plugin 🧱
296296
uses: ./.github/actions/build-plugin
@@ -358,17 +358,17 @@ jobs:
358358
"pluginName=${ProductName}" >> $env:GITHUB_OUTPUT
359359
"pluginVersion=${ProductVersion}" >> $env:GITHUB_OUTPUT
360360
361-
# - name: Checkout vcpkg repository
362-
# uses: actions/checkout@v5
363-
# with:
364-
# repository: microsoft/vcpkg
365-
# path: ${{ env.VCPKG_ROOT }}
361+
- name: Checkout vcpkg repository
362+
uses: actions/checkout@v5
363+
with:
364+
repository: microsoft/vcpkg
365+
path: ${{ env.VCPKG_ROOT }}
366366

367-
# - name: "Bootstrap vcpkg"
368-
# working-directory: "${{ env.VCPKG_ROOT }}"
369-
# shell: "pwsh"
370-
# run: |
371-
# .\bootstrap-vcpkg.bat
367+
- name: "Bootstrap vcpkg"
368+
working-directory: "${{ env.VCPKG_ROOT }}"
369+
shell: "pwsh"
370+
run: |
371+
.\bootstrap-vcpkg.bat
372372
373373
# - name: "Setup NuGet Credentials on Windows"
374374
# shell: pwsh
@@ -384,9 +384,9 @@ jobs:
384384
# & $NUGET_EXE_PATH setapikey "${{ secrets.GITHUB_TOKEN }}" `
385385
# -Source "https://nuget.pkg.github.com/kaito-tokyo/index.json"
386386

387-
# - name: "Install dependencies from vcpkg"
388-
# shell: bash
389-
# run: "$VCPKG_ROOT/vcpkg install --triplet x64-windows-static-md-obs"
387+
- name: "Install dependencies from vcpkg"
388+
shell: bash
389+
run: "$VCPKG_ROOT/vcpkg install --triplet x64-windows-static-md-obs"
390390

391391
- name: Build Plugin 🧱
392392
uses: ./.github/actions/build-plugin

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@
99
!/docs
1010
!/pages
1111
!/src
12+
!/vcpkg-overlay-ports
13+
!/vcpkg-triplets
1214
!.clang-format
1315
!.cmake-format.json
16+
!.gersemirc
1417
!.gitignore
1518
!buildspec.json
1619
!CMakeLists.txt
1720
!CMakePresets.json
1821
!LICENSE
1922
!README.md
23+
!vcpkg-configuration.json
24+
!vcpkg.json
2025

2126
# Exclude lock files
2227
*.lock.json

CMakeLists.txt

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ project(${_name} VERSION ${_version})
77
option(ENABLE_FRONTEND_API "Use obs-frontend-api for UI functionality" OFF)
88
option(ENABLE_QT "Use Qt functionality" OFF)
99

10+
set(VCPKG_TARGET_TRIPLET "" CACHE STRING "Vcpkg target triplet to use")
11+
option(USE_PKGCONFIG "Use pkg-config to find dependencies" OFF)
12+
13+
option(USE_SYSTEM_ONNXRUNTIME "Use system ONNX Runtime" OFF)
14+
option(DISABLE_ONNXRUNTIME_GPU "Disables GPU support of ONNX Runtime (Only valid on Linux)" OFF)
15+
set(USE_SYSTEM_OPENCV OFF CACHE STRING "Use system OpenCV")
16+
1017
include(compilerconfig)
1118
include(defaults)
1219
include(helpers)
@@ -34,9 +41,35 @@ if(ENABLE_QT)
3441
)
3542
endif()
3643

37-
set(USE_SYSTEM_ONNXRUNTIME OFF CACHE STRING "Use system ONNX Runtime")
44+
if(NOT VCPKG_TARGET_TRIPLET STREQUAL "")
45+
# Use vcpkg to find dependencies (Official binary)
46+
47+
message(STATUS "Using vcpkg with target triplet: ${VCPKG_TARGET_TRIPLET}")
48+
49+
list(PREPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}")
50+
51+
find_package(CURL CONFIG REQUIRED)
52+
elseif(USE_PKGCONFIG)
53+
# Use pkg-config to find dependencies (Arch Linux, etc.)
54+
55+
message(STATUS "Using pkg-config to find dependencies")
3856

39-
set(DISABLE_ONNXRUNTIME_GPU OFF CACHE STRING "Disables GPU support of ONNX Runtime (Only valid on Linux)")
57+
find_package(PkgConfig REQUIRED)
58+
59+
# CURL
60+
pkg_check_modules(PC_CURL REQUIRED libcurl)
61+
add_library(CURL::libcurl INTERFACE IMPORTED)
62+
target_link_libraries(CURL::libcurl INTERFACE ${PC_CURL_LIBRARIES})
63+
target_include_directories(CURL::libcurl INTERFACE ${PC_CURL_INCLUDE_DIRS})
64+
target_compile_definitions(CURL::libcurl INTERFACE ${PC_CURL_CFLAGS_OTHER})
65+
target_link_directories(CURL::libcurl INTERFACE ${PC_CURL_LIBRARY_DIRS})
66+
else()
67+
# Let system find dependencies (Fallback)
68+
69+
message(STATUS "Using system to find dependencies")
70+
71+
find_package(CURL REQUIRED)
72+
endif()
4073

4174
if(DISABLE_ONNXRUNTIME_GPU)
4275
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE DISABLE_ONNXRUNTIME_GPU)
@@ -61,7 +94,6 @@ else()
6194
include(cmake/FetchOnnxruntime.cmake)
6295
endif()
6396

64-
set(USE_SYSTEM_OPENCV OFF CACHE STRING "Use system OpenCV")
6597
if(USE_SYSTEM_OPENCV)
6698
if(OS_LINUX)
6799
find_package(OpenCV REQUIRED COMPONENTS core imgproc)
@@ -75,18 +107,8 @@ else()
75107
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OpenCV)
76108
endif()
77109

78-
if(APPLE)
79-
add_subdirectory(src/update-checker/URLSessionClient)
80-
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE URLSessionClient)
81-
# add Foundation framework
82-
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "-framework Foundation")
83-
elseif(MSVC)
84-
add_subdirectory(src/update-checker/WinRTHttpClient)
85-
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE WinRTHttpClient)
86-
elseif(UNIX)
87-
add_subdirectory(src/update-checker/CurlClient)
88-
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE CurlClient)
89-
endif()
110+
add_subdirectory(src/update-checker/CurlClient)
111+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE CurlClient)
90112

91113
target_sources(
92114
${CMAKE_PROJECT_NAME}

CMakePresets.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"CMAKE_OSX_ARCHITECTURES": "arm64;x86_64",
3434
"CODESIGN_IDENTITY": "$penv{CODESIGN_IDENT}",
3535
"CODESIGN_TEAM": "$penv{CODESIGN_TEAM}",
36-
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
36+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
37+
"VCPKG_TARGET_TRIPLET": "universal-osx-obs"
3738
}
3839
},
3940
{
@@ -62,7 +63,8 @@
6263
"architecture": "x64,version=10.0.22621",
6364
"warnings": {"dev": true, "deprecated": true},
6465
"cacheVariables": {
65-
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
66+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
67+
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md-obs"
6668
}
6769
},
6870
{
@@ -89,7 +91,8 @@
8991
"warnings": {"dev": true, "deprecated": true},
9092
"cacheVariables": {
9193
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
92-
"CMAKE_INSTALL_LIBDIR": "lib/CMAKE_SYSTEM_PROCESSOR-linux-gnu"
94+
"CMAKE_INSTALL_LIBDIR": "lib/CMAKE_SYSTEM_PROCESSOR-linux-gnu",
95+
"VCPKG_TARGET_TRIPLET": "x64-linux-obs"
9396
}
9497
},
9598
{

0 commit comments

Comments
 (0)