Skip to main content

libobs_bootstrapper/
build.rs

1/// Emits the linker flags required to delay-load `obs.dll` on Windows.
2///
3/// Call this from the *application's* `build.rs` when the executable links
4/// `libobs`/`libobs-wrapper` directly and wants to bootstrap OBS before the
5/// first OBS symbol is used. Cargo does not propagate `rustc-link-arg` from a
6/// dependency's build script to the final executable, so this helper must run
7/// in the final application's build script.
8///
9/// On non-Windows targets this is a no-op so a cross-platform build script can
10/// call it unconditionally.
11///
12/// # Panics
13///
14/// Panics for Windows toolchains whose delay-load linker convention is not
15/// supported by this helper.
16pub fn emit_windows_obs_delay_load() {
17    let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
18    if target_os != "windows" {
19        return;
20    }
21
22    let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
23    if target_env == "msvc" {
24        println!("cargo:rustc-link-lib=dylib=delayimp");
25        println!("cargo:rustc-link-arg=/DELAYLOAD:obs.dll");
26    } else {
27        panic!("libobs-bootstrapper delay loading currently supports the Windows MSVC target");
28    }
29}