Skip to content

design: obs-nvenc Rust CUDA/NVENC loader; defer obs-studio-libs prebuilt cache to build deps only #520

Closed

Description

@zackees

Summary

Proposal: an obs-rust/obs-studio-libs cache of prebuilt native libraries, modelled on zackees/soldr-toolchain, to fix CUDA/NVENC breakage across glibc versions and CUDA link layouts.

Recommendation: modified yes.

  1. Do not put CUDA or NVIDIA libraries in the cache. OBS never links or ships the CUDA runtime. plugins/obs-nvenc/cuda-helpers.c:19-21 dlopens only the driver API (libcuda.so.1 / nvcuda.dll) and resolves _v2 symbols by name. plugins/obs-nvenc/nvenc-helpers.c:105-109 and plugins/obs-ffmpeg/obs-ffmpeg.c:262-268 do the same for libnvidia-encode.so.1 / nvEncodeAPI64.dll. These are user-mode driver libraries. They have to match the host kernel module, and NVIDIA's license does not allow redistributing them. libcudart is not involved. The one real breakage, bug: build-aux: NVENC can't load from the Linux AppImage, so NVIDIA users get no GPU encoding #498, was the AppImage's bundled glibc 2.43 meeting a host libcuda that needed glibc private symbols. That is a glibc-closure problem, and it is now handled by bundling all of glibc (build-aux/appimage/assemble-appdir.sh:111-130).
  2. Do build the Rust CUDA/NVENC loader (crate obs-nvenc, below). It replaces the hard-coded single soname with an ordered candidate search, returns typed and diagnosable errors (including GLIBC_x.y not found), and is unit-testable without a GPU.
  3. Create obs-studio-libs later, and only for build-time third-party dependencies that the Linux packages build or install today (FFmpeg built with nv-codec-headers, x264, libvpl, librist, srt, libdatachannel, and so on; see the apt list in .github/workflows/appimage.yaml:122). Each is built once against a manylinux_2_28 (glibc 2.28) baseline and described with zackees/manifest.json. The goal is reproducible packages that stop depending on the build host's glibc. It also opens a later path where the AppImage no longer bundles glibc at all (which bug: build-aux: NVENC can't load from the Linux AppImage, so NVIDIA users get no GPU encoding #498 shows is fragile). Start this only after a measurement shows it pays off in CI time (see infra: CI: PR runs spend most of their time on per-run setup #427). It is not the CUDA fix.

Prior art studied

  • zackees/soldr-toolchain. Code is on main. Data lives on an orphan assets branch: a top-level manifest.json index, a per-tool <tool>/manifest.json, and LFS blobs at <tool>/<version>/<platform>/<file>, with ABI variants as sibling files. A nightly job on main refreshes the catalogue, and consumers read it from raw.githubusercontent.com (CDN, no API rate limit). Immutable sha256/<digest>/... copies stop a CDN from pairing a new catalogue with a stale blob. Catalogue schemas are schemas/catalogue.v{1,2}.schema.json.
  • zackees/manifest.json. The data model is Index → Catalog → Release → EmbeddedSlice. Every cross-document link is an OCI descriptor {url, sha256, size_bytes}. Consumers ask resolve(tool, platform, channel, variant?), where Platform{os, arch, os_version, libc, abi, features[]} matches field by field and a missing field is a wildcard. An asset has either urls[] or multipart parts[]. The project also provides a manifest-resolve CLI, and an EmbeddedSlice can be pulled in with include_str! so resolving needs no network. The glibc baseline maps to libc: "glibc" plus os_version: "2.28", read as the minimum.
  • zackees/transcribe-anything. It does not use a prebuilt-libs cache or a dlopen abstraction. It relies on vendor-built manylinux wheels (PyTorch cu128 plus the nvidia-* wheels, which bundle cudart, cublas and cudnn) in an isolated uv env, and takes only the driver (libcuda.so.1) from the host. On top of that it adds diagnostics: cuda_available.py compares the driver's CUDA version with the wheel's (driver too old leads to an error, and host CUDA libraries on LD_LIBRARY_PATH leads to a warning). check_linux_shared_libraries.py probes sonames with ctypes.CDLL, and util.py caches GPU detection. The lesson for OBS: bundle the runtime libraries, never the driver, and give clear diagnostics when the driver does not match. OBS has no runtime libraries to bundle, so only the diagnostics part carries over.
  • cudarc (dynamic-loading feature) is not adopted. It uses libloading over a candidate list, but it covers the CUDA runtime and math libraries and much more API than the 15 or so driver functions OBS needs. In the versions checked it panics or lazily aborts when the library is missing, while OBS must degrade to "NVENC not supported". libloading is used directly.

Design: crate obs-nvenc

Name per docs/rust-port/naming.md: an obs-<area> port named after the directory it ports (plugins/obs-nvenc). Path: rust/obs-nvenc/. It is an rlib re-exported through libobs-rust only when a C shim is added, which is out of scope here (see below).

// src/lib.rs (safe; #![deny(unsafe_code)])
pub enum Library { CudaDriver, NvEncode, Nvml }
pub struct Candidate { pub name: std::ffi::OsString, pub source: CandidateSource }
pub enum CandidateSource { EnvOverride, SonameDefault, SonameUnversioned, DistroPath, WslPath }
pub fn candidates(lib: Library, env: &dyn Env) -> Vec<Candidate>;   // pure, host-neutral data from platform::
pub struct CudaDriver { /* fn table */ }
impl CudaDriver {
    pub fn load() -> Result<Self, LoadError>;                         // walks candidates, first success wins
    pub fn load_from(cands: &[Candidate], dl: &dyn DynLoader) -> Result<Self, LoadError>; // test seam
    pub fn driver_version(&self) -> Result<CudaVersion, CudaError>;  // cuDriverGetVersion
}
#[non_exhaustive]
pub enum LoadError {
    NotFound { tried: Vec<(Candidate, String /*dlerror*/)> },
    GlibcMismatch { candidate: Candidate, required: String },          // parsed from "version `GLIBC_2.44' not found"
    MissingSymbol { library: Library, symbol: &'static str },          // e.g. cuCtxCreate_v2
    DriverTooOld { found: CudaVersion, need: CudaVersion },
}
pub trait DynLoader { fn open(&self, c: &Candidate) -> Result<Box<dyn DynLib>, String>; }

Fallback order (Linux): OBS_CUDA_LIBRARY / OBS_NVENC_LIBRARY env override, then libcuda.so.1, then libcuda.so (dev symlink, last resort), then the multiarch distro paths (/usr/lib/x86_64-linux-gnu, /usr/lib64, /usr/lib/nvidia, /run/opengl-driver/lib on NixOS), then WSL /usr/lib/wsl/lib. libnvidia-encode.so.1 follows the same pattern. Windows: nvcuda.dll, then nvEncodeAPI64.dll / nvEncodeAPI.dll, loaded only from System32 (LOAD_LIBRARY_SEARCH_SYSTEM32, no CWD hijack). macOS: an empty list, returning NotFound immediately.

Symbol resolution: the _v2 names exactly as in cuda-helpers.c. A missing required symbol returns MissingSymbol, while a missing optional symbol leaves None.

Platform boundary: soname lists, search paths, the WSL/NixOS probes and the Windows LoadLibraryExW flags live in src/platform/{unix,windows,macos}.rs, chosen by a single cfg_select! in src/platform/mod.rs that re-exports fn default_candidates(Library) -> Vec<Candidate> and struct SystemLoader: DynLoader. unsafe (the libloading open and symbol transmute) is allowed only in src/platform/ (with a module-level allow and a reason, as in obs_util::platform::windows) and in src/ffi/. Each block has a // SAFETY: comment. dylints/ban_platform_cfg_outside_boundary must pass with no allowlist.

Errors map onto today's C log strings so users and log scrapers see the same text: NotFound produces [NVENC] Test process failed: cuda_lib, plus the list of what was tried and why.

obs-studio-libs design (phase 2, after the measurement)

  • Repo obs-rust/obs-studio-libs, laid out like soldr-toolchain: build recipes and tests on main, catalogue plus blobs on an orphan assets branch, with <lib>/<version>/<os>-<arch>/<lib>-<version>-<os>-<arch>-<libc><ver>.tar.zst. Large blobs are GitHub Release assets with parts[] multipart where they exceed 2 GB; the catalogue is served from raw.githubusercontent.com.

  • Manifest: zackees/manifest.json Catalog per library, with no new schema. The platform keys are:

    • {os:"linux", arch:"x86_64"|"aarch64", libc:"glibc", os_version:"2.28"} (manylinux_2_28, built in quay.io/pypa/manylinux_2_28_*)
    • {os:"windows", arch:"x86_64", libc:"msvc"}
    • {os:"darwin", arch:"arm64"|"x86_64", os_version:"11.0"}

    The variant flavor holds build options, for example ffmpeg flavor:"nvenc". Channel is latest-stable plus exact versions.

  • Contents: only redistributable third-party build dependencies with SBOM and licence files. Never the NVIDIA driver libraries, the CUDA runtime or the Qt commercial bits.

  • Consumers: CMake FetchContent or a pre-configure script resolves through a checked-in EmbeddedSlice per lane (sha-pinned, so no network resolution), verifies sha256, and extracts into .deps/. CI uses existing workflows only (no new workflow file in obs-studio). The producer workflow lives in the new repo and needs separate sign-off when that repo is created.

Test plan (testing-policy tiers)

  • Tier 1 (Rust, rust/obs-nvenc/tests/): candidates() order for each Library with and without the env override, using a fake Env. load_from with a fake DynLoader: the first candidate fails and the second succeeds; all fail gives NotFound listing every dlerror; dlerror version 'GLIBC_2.44' not found gives GlibcMismatch{required:"GLIBC_2.44"}; a missing cuCtxCreate_v2 gives MissingSymbol; cuDriverGetVersion 11080 against a need of 12000 gives DriverTooOld. These run on every OS with no GPU.
  • Tier 2: none yet, because no C symbol is replaced in this issue. When a later issue ports load_cuda_lib/init_cuda behind ENABLE_RUST_LIBOBS, the unchanged C test and plugin load must pass with the option ON and OFF.
  • Tier 3: a differential test of the candidate outcome against the original C. cuda-helpers.c is compiled into obs-c-oracle with the oracle_ prefix and os_dlopen stubbed to record names, which asserts that the Rust search order starts with the exact name C tries (libcuda.so.1 / nvcuda.dll), so there is no regression on the default path. The mutation check is required and must be stated in the PR.
  • Tier 4: not applicable (no network surface).
  • Packaging (AGENTS.md rule): phase 2 changes what ships. build-aux/appimage/test-appimage.sh must gain a lane that runs the AppImage on a container with a newer glibc than the bundle and asserts that obs-nvenc either loads or logs the typed GlibcMismatch/NotFound reason, with a saved profile that uses NVENC. Show it failing without the change.

Acceptance criteria

  • rust/obs-nvenc exists, is named per naming.md, passes ci/test_naming.py, and ./lint (clippy, fmt, dylints) is clean with no platform-boundary allowlist.
  • RED commit (Tier 1 against todo!() stubs, soldr cargo test failing), then GREEN.
  • Tier 1 covers every LoadError variant and the fallback order on Linux, Windows and macOS lists. It runs in the existing rust-tests job on all three OSes.
  • Tier 3 parity with cuda-helpers.c/nvenc-helpers.c default names, with the mutation check recorded in the PR.
  • No C header, C test or plugin C file is changed. No new workflow file is added.
  • A decision comment on this issue records whether phase 2 (obs-studio-libs) goes ahead, based on measured CI minutes spent on dependency setup (infra: CI: PR runs spend most of their time on per-run setup #427 data).

Implementation checklist

  1. Claim per coordination.md and branch port/obs-nvenc-loader.
  2. Add rust/obs-nvenc/{Cargo.toml,src/lib.rs,src/error.rs,src/candidates.rs,src/platform/{mod.rs,unix.rs,windows.rs,macos.rs}}, add it to the workspace, and add libloading as a workspace dependency (exact pin).
  3. RED: tests/loader.rs with the fake Env/DynLoader cases listed above, against todo!().
  4. GREEN: candidate lists (platform), load_from walk, dlerror parsing for GLIBC_ (pure function in the safe core, which only parses strings), and the symbol table that mirrors cuda_functions[] in cuda-helpers.c (same _v2 names).
  5. SystemLoader in platform/unix.rs and platform/windows.rs via libloading (Windows with LOAD_LIBRARY_SEARCH_SYSTEM32), with // SAFETY: comments.
  6. Tier 3: rust/obs-c-oracle/oracle/cuda_helpers.c wrapper plus a recording os_dlopen stub, and tests/loader_parity.rs.
  7. Opt-in smoke test #[ignore] real_gpu_loads that calls CudaDriver::load() and prints the driver version, for maintainers with NVIDIA hardware.
  8. Run ./lint, ./unittest and the local-gate stamp, then open a PR with Refs #<this>.
  9. Follow-up issues (file them, don't do them here): (a) C shim plus ENABLE_RUST_LIBOBS swap for load_cuda_lib/init_cuda; (b) phase 2 obs-studio-libs once the measurement supports it, which also needs sign-off for the producer workflow in the new repo.

Refs #498 (the original glibc/libcuda breakage), #427 (CI setup time).

Written with Claude Code (Claude Opus 5.5).

Activity

  1. added
    enhancement
    design
    on Oct 13, 2026
  2. zackees commented on Oct 13, 2026

    @zackees
    MemberAuthor

    Claiming: phase 1 (the rust/obs-nvenc loader crate).

    1. Branch port/obs-nvenc-loader from master; add rust/obs-nvenc (candidates, error types, platform loaders via libloading).
    2. RED: Tier 1 tests/loader.rs against todo!() stubs.
    3. GREEN: candidate lists, load_from walk, GLIBC dlerror parsing, cuda_functions[] symbol table.
    4. Tier 3: obs-c-oracle/oracle/cuda_helpers.c + nvenc name parity, with mutation check in the PR.

    Phase 2 (obs-studio-libs) and the C shim are not part of this claim. First PR expected today.

  3. added
    claimed
    on Oct 13, 2026
  4. added a commit that references this issue on Oct 13, 2026
  5. zackees commented on Oct 13, 2026

    @zackees
    MemberAuthor

    Phase 2 go/no-go recorded on #525: no-go for now. Windows and macOS already use prebuilt obs-deps (~10–18 s), and every Flatpak dependency module is already cached. Ubuntu spends ~52 s in apt, of which an FFmpeg/x264 cache would save at most ~20–30 s. Measurements and the revisit trigger are in #525.

  6. removed
    claimed
    on Oct 15, 2026
  7. github-actions commented on Oct 15, 2026

    @github-actions

    Claim bot: claim expired: no progress from @zackees in 48 h. Anyone may claim it now.

  8. vpacher commented on Oct 16, 2026

    @vpacher
    Member

    Not claiming: phase 1 is complete as far as I can see. #529 (loader, RED/GREEN, Tier 3 with mutation check), #592 (C shim swap, fixes #524) and #646 (Tier 2 coverage) are merged, and the phase 2 decision is recorded on #525 (no-go for now). The claim bot expiry above refers to finished work.

    One more data point for real_gpu_loads, which so far ran only on NixOS (DistroPath):

    • Debian 13, NVIDIA GeForce RTX 3060, driver 595.104.02, master 4f270ee
    • soldr cargo test -p obs-nvenc --release --test loader -- --ignored real_gpu_loads --nocapture
    • Output: loaded Candidate { name: "libcuda.so.1", source: SonameDefault }, driver version 13.2, test passes.

    So the default soname path works on a standard FHS distribution too. On the same host, NVENC h264 recording worked with the fork build of 2026-10-15 (aaed86f, ENABLE_RUST_LIBOBS=ON); not yet re-checked on 4f270ee.

    If nothing else is pending, this issue can perhaps be closed.

  9. zackees commented on Oct 16, 2026

    @zackees
    MemberAuthor

    @vpacher thank you, and for the Debian 13 / RTX 3060 real_gpu_loads result.

    I checked it against the merged work: phase 1 is done. #529 (loader crate, RED then GREEN, Tier 3 parity with the mutation check), #592 (C shim swap, closed #524) and #646 (Tier 2 harness with ENABLE_RUST_LIBOBS OFF and ON) are merged. Phase 2 (obs-studio-libs) was decided no-go for now, with the measurements and the trigger to revisit recorded on #525, which stays open for that. Closing this issue as complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    designenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions