Skip to content

Commit fb71cf3

Browse files
committed
Updated scripts for Windows build
1 parent 246b0d4 commit fb71cf3

2 files changed

Lines changed: 137 additions & 24 deletions

File tree

.github/workflows/build.yml

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -352,38 +352,99 @@ jobs:
352352
jansson:x64-windows-release `
353353
uthash:x64-windows-release `
354354
simde:x64-windows-release
355+
356+
# Export VCPKG_ROOT for subsequent steps (build.rs reads it for toolchain)
357+
"VCPKG_ROOT=$vcpkgRoot" | Out-File -Append -Encoding utf8 $env:GITHUB_ENV
358+
Write-Host "Exported VCPKG_ROOT=$vcpkgRoot"
355359

356360
- name: Build (revo-lib) + build.rs builds OBS
357361
shell: pwsh
358362
run: |
359363
$ErrorActionPreference = "Stop"
360-
361-
# Point build.rs/CMake to vcpkg toolchain
362-
$env:VCPKG_ROOT = $env:VCPKG_INSTALLATION_ROOT
363-
$env:VCPKG_TOOLCHAIN_FILE = Join-Path $env:VCPKG_ROOT "scripts\buildsystems\vcpkg.cmake"
364+
365+
# VCPKG_ROOT is written to GITHUB_ENV by the install step above;
366+
# it is already available as a process env var here.
367+
Write-Host "VCPKG_ROOT=$env:VCPKG_ROOT"
368+
Write-Host "CMAKE_SYSTEM_VERSION=$env:CMAKE_SYSTEM_VERSION"
369+
370+
if (-not $env:VCPKG_ROOT -or -not (Test-Path $env:VCPKG_ROOT)) {
371+
throw "VCPKG_ROOT ('$env:VCPKG_ROOT') is not set or does not exist."
372+
}
373+
364374
$env:VCPKG_DEFAULT_TRIPLET = "x64-windows-release"
365-
366-
# IMPORTANT: do NOT force manifests here (it can break classic mode)
367-
# $env:VCPKG_FEATURE_FLAGS = "manifests"
368-
375+
369376
cargo build --release
370377
371-
- name: Package artifact (basic)
378+
- name: Package artifact (prebuilt layout)
372379
shell: pwsh
373380
run: |
374381
$ErrorActionPreference = "Stop"
375-
382+
376383
$arch = "x86_64"
377384
$staging = "libobs-prebuilt-windows-$arch"
378-
New-Item -ItemType Directory -Force -Path $staging | Out-Null
379-
380-
New-Item -ItemType Directory -Force -Path "$staging\target-release" | Out-Null
381-
Copy-Item -Recurse -Force "target\release\*" "$staging\target-release\"
382-
383-
"REVO_OBS_REF=$env:REVO_OBS_REF" | Out-File -Append -Encoding ascii "$staging\build-info.env"
384-
"BUILD_DATE=$(Get-Date -AsUTC -Format o)" | Out-File -Append -Encoding ascii "$staging\build-info.env"
385-
"ARCH=$arch" | Out-File -Append -Encoding ascii "$staging\build-info.env"
386-
385+
386+
$obsSrc = "obs-libobs\obs-studio"
387+
$buildDir = "$obsSrc\build-headless"
388+
$installDir = "$buildDir\install"
389+
390+
New-Item -ItemType Directory -Force -Path "$staging\lib" | Out-Null
391+
New-Item -ItemType Directory -Force -Path "$staging\bin" | Out-Null
392+
New-Item -ItemType Directory -Force -Path "$staging\include\obs" | Out-Null
393+
New-Item -ItemType Directory -Force -Path "$staging\bindings" | Out-Null
394+
395+
# 1) Import lib (obs.lib) – searched by rustc
396+
$obsLib = Get-ChildItem -Recurse "$buildDir" -Filter "obs.lib" -ErrorAction SilentlyContinue | Select-Object -First 1
397+
if ($obsLib) {
398+
Copy-Item $obsLib.FullName "$staging\lib\obs.lib"
399+
Write-Host "Copied obs.lib from $($obsLib.FullName)"
400+
} else {
401+
Write-Warning "obs.lib not found under $buildDir"
402+
}
403+
404+
# 2) DLL (obs.dll) – needed at runtime
405+
$obsDll = Get-ChildItem -Recurse "$buildDir" -Filter "obs.dll" -ErrorAction SilentlyContinue | Select-Object -First 1
406+
if ($obsDll) {
407+
Copy-Item $obsDll.FullName "$staging\bin\obs.dll"
408+
Write-Host "Copied obs.dll from $($obsDll.FullName)"
409+
} else {
410+
Write-Warning "obs.dll not found under $buildDir"
411+
}
412+
413+
# 3) Headers
414+
if (Test-Path "$installDir\include\obs") {
415+
Copy-Item -Recurse "$installDir\include\obs\*" "$staging\include\obs\"
416+
Write-Host "Copied installed headers from $installDir\include\obs"
417+
}
418+
Get-ChildItem "$obsSrc\libobs" -Filter "*.h" | ForEach-Object {
419+
Copy-Item $_.FullName "$staging\include\obs\" -Force
420+
}
421+
# obsconfig.h
422+
$obscfg = Get-ChildItem -Recurse "$buildDir" -Filter "obsconfig.h" -ErrorAction SilentlyContinue | Select-Object -First 1
423+
if ($obscfg) {
424+
Copy-Item $obscfg.FullName "$staging\include\obs\obsconfig.h" -Force
425+
Write-Host "Copied obsconfig.h from $($obscfg.FullName)"
426+
} else {
427+
Write-Warning "obsconfig.h not found"
428+
}
429+
430+
# 4) Bindings
431+
$bindings = Get-ChildItem -Recurse "target" -Filter "libobs_bindings.rs" -ErrorAction SilentlyContinue | Select-Object -First 1
432+
if ($bindings) {
433+
Copy-Item $bindings.FullName "$staging\bindings\libobs_bindings.rs"
434+
Write-Host "Copied bindings from $($bindings.FullName)"
435+
} else {
436+
Write-Error "libobs_bindings.rs not found in target\**\out\"
437+
exit 1
438+
}
439+
440+
# 5) Metadata
441+
"REVO_OBS_REF=$env:REVO_OBS_REF" | Out-File -Append -Encoding ascii "$staging\build-info.env"
442+
"BUILD_DATE=$(Get-Date -AsUTC -Format o)" | Out-File -Append -Encoding ascii "$staging\build-info.env"
443+
"ARCH=$arch" | Out-File -Append -Encoding ascii "$staging\build-info.env"
444+
445+
Write-Host "Artifact layout:"
446+
Get-ChildItem -Recurse $staging | Where-Object { -not $_.Name.EndsWith(".h") } | Sort-Object FullName | ForEach-Object { Write-Host $_.FullName }
447+
387448
"STAGING=$staging" | Out-File -Append -Encoding utf8 $env:GITHUB_ENV
388449
389450
- name: Upload Windows artifact

build.rs

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,53 @@ fn main() -> Result<(), Box<dyn Error>> {
253253
let arch = if cfg!(target_arch = "aarch64") { "arm64" } else { "x86_64" };
254254
cmake.arg(format!("-DCMAKE_OSX_ARCHITECTURES={}", arch));
255255

256+
} else if cfg!(target_os = "windows") {
257+
// --- Configure cmake flags (windows) ---
258+
println!("cargo:warning=Step: configure cmake flags (windows)");
259+
260+
// Patch windows/compilerconfig.cmake to remove SDK version check
261+
println!("cargo:warning=Step: patch windows/compilerconfig.cmake");
262+
let win_compilerconfig = obs_src.join("cmake/windows/compilerconfig.cmake");
263+
if win_compilerconfig.exists() {
264+
println!("cargo:warning=Replacing windows/compilerconfig.cmake with no-op");
265+
fs::write(&win_compilerconfig, "# PATCHED: no-op, skip SDK version requirements\n")?;
266+
} else {
267+
println!("cargo:warning=windows/compilerconfig.cmake not found, skipping");
268+
}
269+
270+
// Patch windows/buildspec.cmake to skip pre-built dep downloads (we use vcpkg)
271+
println!("cargo:warning=Step: patch windows/buildspec.cmake to skip downloads");
272+
let buildspec_win = obs_src.join("cmake/windows/buildspec.cmake");
273+
if buildspec_win.exists() {
274+
println!("cargo:warning=Replacing windows/buildspec.cmake with no-op");
275+
fs::write(&buildspec_win, "# PATCHED: no-op, deps provided by vcpkg\n")?;
276+
}
277+
278+
// Windows SDK version: prefer CMAKE_SYSTEM_VERSION env var (set by workflow)
279+
let sdk_ver = env::var("CMAKE_SYSTEM_VERSION")
280+
.unwrap_or_else(|_| "10.0.20348.0".to_string());
281+
println!("cargo:warning=Using Windows SDK: {sdk_ver}");
282+
283+
cmake.arg("-G").arg("Ninja");
284+
cmake.arg(format!("-DCMAKE_SYSTEM_VERSION={sdk_ver}"));
285+
cmake.arg(format!("-DCMAKE_INSTALL_PREFIX={}", install_prefix.display()));
286+
287+
// vcpkg integration
288+
if let Ok(vcpkg_root) = env::var("VCPKG_ROOT") {
289+
let toolchain = PathBuf::from(&vcpkg_root)
290+
.join("scripts/buildsystems/vcpkg.cmake");
291+
println!("cargo:warning=Using vcpkg toolchain: {}", toolchain.display());
292+
cmake.arg(format!("-DCMAKE_TOOLCHAIN_FILE={}", toolchain.display()));
293+
cmake.arg("-DVCPKG_TARGET_TRIPLET=x64-windows-release");
294+
} else {
295+
println!("cargo:warning=VCPKG_ROOT not set, skipping vcpkg toolchain");
296+
}
297+
298+
cmake
299+
.arg("-DENABLE_SCRIPTING=OFF")
300+
.arg("-DENABLE_VIRTUALCAM=OFF")
301+
.arg("-DENABLE_WIN_CRASH_HANDLER=OFF");
302+
256303
} else {
257304
// --- Configure cmake flags (linux) ---
258305
println!("cargo:warning=Step: configure cmake flags (linux)");
@@ -265,7 +312,6 @@ fn main() -> Result<(), Box<dyn Error>> {
265312
// IMPORTANT LINE
266313
run(cmake.current_dir(&build_dir), "cmake configure")?;
267314

268-
269315
// 4) Build only libobs target
270316
let mut build_cmd = Command::new("cmake");
271317
build_cmd
@@ -325,10 +371,16 @@ fn main() -> Result<(), Box<dyn Error>> {
325371
"cargo:rustc-link-search=native={}",
326372
install_prefix.join("lib64").display()
327373
);
328-
println!("cargo:rustc-link-lib=dylib=obs");
329-
println!("cargo:rustc-link-lib=dylib=dl");
330-
println!("cargo:rustc-link-lib=dylib=pthread");
331-
println!("cargo:rustc-link-lib=dylib=m");
374+
if cfg!(target_os = "windows") {
375+
// On Windows the import lib is obs.lib; no dl/pthread/m needed.
376+
println!("cargo:rustc-link-search=native={}", install_prefix.join("bin").display());
377+
println!("cargo:rustc-link-lib=dylib=obs");
378+
} else {
379+
println!("cargo:rustc-link-lib=dylib=obs");
380+
println!("cargo:rustc-link-lib=dylib=dl");
381+
println!("cargo:rustc-link-lib=dylib=pthread");
382+
println!("cargo:rustc-link-lib=dylib=m");
383+
}
332384

333385
println!("cargo:rerun-if-changed={}", wrapper.display());
334386

0 commit comments

Comments
 (0)