Skip to content

libobs: Port the module search paths to obs-core - #1894

Merged
zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/obs-module-paths
Oct 23, 2026
Merged

zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/obs-module-paths

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Refs #1876 (slice 1 of obs-module.c.h; the next slice gets filed on #1846 when this one closes). Unit 9 of #1846.

What and why

The first slice of libobs/obs-module.c.h moves to rust/obs-core: how modules are found on a search path, the data path each one gets, and the lookup behind obs_find_module_file(). Loading (os_dlopen, obs_open_module, obs_init_module, post-load), the module list and the search path list stay C.

Feasibility (checked before any code). Of the target functions, only two touch private state, and neither needs a seam. obs_find_module_file() reads one field, module->data_path, and obs_find_modules2() walks obs->module_paths. Everything else is pure path logic: string building, %module% substitution, os_glob() and os_file_exists(), both already ported to obs-util. The platform-specific parts (get_module_extension() and the macOS bundle hook obs_host_add_module_extension()) are passed in. So C passes the fields in, as #1788 and #1825 did, and keeps the walk:

  • obs_add_module_path, obs_find_modules2/obs_find_modules (the walk over obs->module_paths), obs_get_module_data_path (a field read), find_core_module, obs_module_get_config_path and all of the loading stay in obs-module.c.h. No exported function moves, so there is no rust-exports.d fragment, and the 1766 exported symbols are unchanged.
  • obs_find_data_file is in obs.c.h, not obs-module.c.h, and goes through the platform's find_libobs_data_file, so it is not part of this slice.

Commits:

  • test: Characterize the module search paths: nine cases in test_core_module_load, the existing module test binary, on the unchanged C. They cover the flat and %module% searches, the "lib" fallbacks, %module% substitution (repeated, missing), trailing separators, missing directories, NULL and empty paths, duplicate paths, obs_find_modules next to obs_find_modules2, obs_find_module_file/obs_get_module_data_path (files, directories, NULL/empty files, a leading '/', NULL module, empty/NULL/missing data paths), and the data path obs_load_plugins() gives a plugin.
  • libobs: Move the module search paths into obs-module-paths.c: a behaviour-neutral extraction that changes nothing in the public API. make_data_directory, parse_binary_from_directory, process_found_module, find_modules_in_path and the body of obs_find_module_file move to libobs/obs-module-paths.c.h. There they become three hidden entry points that take the search path's fields, the extension and the hook: obs_module_paths_data_dir, obs_module_paths_find and obs_module_paths_find_file. Two (size_t) casts on non-negative pointer differences let the oracle build under -Wsign-conversion.
  • RED, GREEN, Tier 3, then docs and port_comparison.

Safe core (rust/obs-core/src/module_paths.rs): data_dir, find_file, search_pattern and find. Paths are bytes, with Option for NULL. The C's dstr steps are followed exactly, NULL against empty included: a copy of "" is NULL, and a path cut to nothing is NULL. The file system is a ModuleFs trait (real os_file_exists/os_glob in the shim, a fake in Tier 1), and the host hook is a closure. The module denies clippy's indexing, arithmetic, unwrap and panic lints.

Shim (src/ffi/module_paths.rs): the three C signatures. The hook gets a bmalloc'd struct dstr that it may grow. The callback's struct obs_module_info2 strings are valid for the call, the type is passed through, and returned paths are bmalloc'd. libobs/obs-module-paths.c.h moves to libobs.ported-module-paths (PCH obs-internal.h), and the three symbols are hidden through rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt. obs-core now depends on obs-util.

Kept, characterized, not endorsed:

  • Data paths are reported whether or not they exist, and so is the "lib" fallback.
  • Only one trailing '/' is taken off a data path, and an empty or "/" data path reports no module.
  • A module directory with a '.' in its name is never found.
  • A directory passes for a module binary.
  • The C's ".so" "legacy fallback" is overwritten before it is tried.
  • obs_find_module_file with a NULL or empty file returns the data path itself, and with an empty or NULL data path it looks in the working directory.

The "lib" prefix is matched in ASCII, where the C's toupper follows the C locale.

Intentional differences (also in the parity test header, the core's docs and rust/README.md):

  • An empty or NULL binary directory searches nothing. The C copies it to a NULL dstr and passes that to strstr(). Checked on the unchanged C: obs_add_module_path("", ...) followed by obs_find_modules2() segfaults with the C backend and libobs-c-reference, and returns no modules with the hybrid libobs.
  • A NULL callback searches nothing, and a NULL hook leaves the path as it is (the C calls both). obs-module.c never passes either.

RED → GREEN

  • Characterization: eda6f3e. test_core_module_load 13/13 (4 existing + 9 new) on the C backend libobs, hybrid libobs and libobs-c-reference, before and after the extraction (7d4212b).
  • RED commit: 9127cd0 libobs: Add Tier 1 tests for the module search paths port. obs_core::module_paths (31 tests: the nine C cases 1:1 on a fake file system, plus edge cases and three proptests) fails 30 of 31 on todo!(). The 31st checks the two constants.
  • GREEN: 6b482f9 libobs: Port the module search paths to obs-core. Tier 1 31/31; Tier 2 test_core_module_load 13/13 against hybrid libobs and libobs-c-reference.
  • Tier 3: 92533ac (module_paths_parity.rs, 11 tests). The oracle is the unmodified C file with its entry points renamed. Both sides run on one real tree, with hooks and callbacks that log every call:
    • find over 13 binary directories × 16 data paths × 4 extensions (.so, .dll, "", NULL) × 4 hooks (.so, .dll, none, the Cocoa one): 3328 searches. Every module (binary path, data path, name, type) is compared in order, along with every hook call and its path;
    • data_dir over 20 names × 16 data paths, and find_file over 10 data paths × 13 files;
    • 2048-case proptests for all three;
    • the obs_module_info2 layout.
    • The intentional differences are tested on the shims alone.
  • Mutation check: 18 mutants of the safe core, each reverted (not committed). Each cell is the number of failing tests:
Mutant Tier 1 (of 31) Tier 3 (of 11)
one trailing '/' not taken off 6 4
every trailing '/' taken off 2 3
"lib" case-sensitive 3 4
no "lib" data fallback 10 4
"lib" fallback only if it exists 9 4
first %module% only 2 4
the replacement searched again 2 4
a copy of "" is "", not NULL 5 3
'/' before an empty file 1 1
'/' after a trailing '/' 3 2
the extension on a directory search 10 4
cut at the last %module% 2 2
no lib<name> binary 5 2
the ".so" fallback tried 1 2
the name cut at the first '.' 1 2
"." and ".." not skipped 1 0
the directory flag inverted 18 4
the hook not called 8 3

Tier 3 cannot see the "." and ".." mutant, because a real glob never returns those entries. Tier 1's fake glob does.

  • Local runs used two build trees (OBS_LIBOBS_BACKEND=C, and HYBRID with OBS_BUILD_C_REFERENCE=ON), headless, with a private Xvfb (-noreset), a private D-Bus and a fresh HOME:
Library test_core_module_load Full ctest Exported symbols
C backend libobs 13/13 381/381 (before the rebase onto #1874) IDENTICAL (1766)
hybrid libobs 13/13 385/385 (one rerun: test_pulse_monitor_device failed once under -j4, a default-sink race, and passed 3/3 on its own) IDENTICAL (1766)
libobs-c-reference 13/13 385/385 IDENTICAL (1766)

In hybrid libobs, the three obs_module_paths_* symbols are the Rust shims. The production link has no obs-module-paths.c.h object, and the C reference still has one.

  • Other local checks:
    • soldr cargo test -p obs-data --test obs-tests-core obs_core:: (obs-tests-core, the core category binary): 98/98; the whole binary 829/829. export_list (every shim exported or hidden) 3/3.
    • ci/local_gate.py --lane lint: passed, at the rebased head too. It covers clang-format, gersemi, rustfmt, clippy -D warnings, Dylints, build groups, the test-binary cap and the ifdef ratchet.
    • --lane cross: passed (Windows and macOS clippy/Dylints, and a link of every test binary for x86_64-pc-windows-msvc and aarch64-apple-darwin).
    • ci/test_build_groups.py, ci/test_ported_sources.py and ci/test_oracle_standins.py: passed.
  • port_comparison: soldr cargo bench -p obs-c-oracle --bench port_comparison -- module_paths, 3 passes pinned to one CPU, Linux x86_64, rustc 1.98.1. Both sides make the same os_file_exists/os_glob calls, which dominate the times. The rest of the gap is the shim's NUL-terminated copy for each file-system call. This code runs once per module search at startup.
Benchmark Rust C Rust / C (run range)
module_paths/data_dir 2296 ns 2045 ns 1.190 (1.043-1.229)
module_paths/data_dir_lib 2062 ns 1844 ns 1.161 (1.118-1.203)
module_paths/find_file/hit 2360 ns 2115 ns 1.116 (0.981-1.144)
module_paths/find_file/miss 1777 ns 1947 ns 0.980 (0.887-1.033)
module_paths/find/flat (32 files) 173.5 µs 163.5 µs 1.018 (1.001-1.397)
module_paths/find/module_dirs (16 dirs) 140.6 µs 120.4 µs 1.182 (1.100-1.388)
  • Real app: not applicable (no user-visible change).

Windows/macOS: the shims use obs-util's os_glob/os_file_exists on both, and the cross lane compiles and links them, but they were not run locally. test_core_module_load is Linux-only. On Windows and macOS, PR CI's Rust lanes run Tier 1 and Tier 3.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag changes)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

@rdoupe
rdoupe requested a review from zackees as a code owner October 23, 2026 05:04
Characterization before the module search paths of obs-module.c move to
their own file and are ported to obs-core. Nothing tested how modules
are found: test_core_module_load only loads core modules by name.

Nine cases join test_core_module_load, the module test binary, and use
the public API only, so they also run against the hybrid libobs. Each
starts its own libobs in this process and lays out empty files and
directories under a new root (in TMPDIR, else next to the binary). They
pin:
- a binary directory without %module%: every *.so file in glob order;
  directories (one named dir.so too) and other files are skipped; the
  data path with %module% replaced by the name;
- %module% in the binary directory: every directory where the path up
  to %module% ends, <name>.so, then lib<name>.so; a directory without a
  binary is skipped;
- the "lib" fallback of the data path, in any case;
- every %module% of the data path, and of the binary directory after
  the first, and a data path without %module%;
- one '/' added to a binary directory, one trailing '/' taken off a
  data path;
- a binary directory that does not exist, NULL paths (not added), an
  empty data path and "/";
- a path added twice, and obs_find_modules() next to obs_find_modules2();
- obs_find_module_file() and obs_get_module_data_path(): a file, a
  missing file, a directory, NULL and empty files, a leading '/', a
  NULL module, a trailing '/' on the data path, a data path that does
  not exist, an empty and a NULL data path;
- the data path obs_load_plugins() gives a plugin it loads, "lib"
  fallback included.

Characterized, not endorsed:
- A data path is reported whether or not it exists, and for a "lib"
  name whose data directory does not exist, the one without "lib" is
  reported whether or not it exists.
- A module directory with a '.' in its name is looked up under the name
  up to its last '.', so it is never found.
- A directory passes for a module binary.
- An empty data path, or "/", reports no module at all, and only one
  trailing '/' is taken off a data path.
- obs_find_module_file() with a NULL or empty file returns the data
  path itself; with an empty or NULL data path it looks in the working
  directory.

13 of 13 pass against the C-backend libobs, the hybrid libobs and
libobs-c-reference, under a private Xvfb.

Refs obs-rust#1876
Behavior-neutral extraction before the Rust port: the path logic of
obs-module.c.h moves into libobs/obs-module-paths.c.h and takes what it
needs from its caller, as obs_context_name_dup() takes
&obs->data.unnamed_index (obs-rust#1788), so the port never mirrors struct
obs_module or reads obs->module_paths.

- make_data_directory() becomes obs_module_paths_data_dir(name,
  data_dir), with make_data_dir() beside it.
- find_modules_in_path(omp, callback, param) becomes
  obs_module_paths_find(bin, data, type, ext, add_extension, callback,
  param): the fields of the search path, the module file extension and
  the host's binary extension hook. parse_binary_from_directory() and
  process_found_module() move with it and take the same fields; their
  get_module_extension() and obs_host_add_module_extension() calls
  become ext and add_extension().
- The body of obs_find_module_file() becomes
  obs_module_paths_find_file(data_path, file).
- The two pointer differences that dstr_resize() takes get a (size_t)
  cast, as both are non-negative: the oracle compiles the file under
  -Wsign-conversion.

obs-module.c.h keeps the search path list, the module list and the
loading. obs_find_modules2() walks obs->module_paths as before and
passes each path's bin, data and type with get_module_extension() and
obs_host_add_module_extension; obs_load_plugins() passes its
obs_runtime_module_info the same way (no obs_module_path on the stack);
find_core_module() calls obs_module_paths_data_dir(); and
obs_find_module_file() keeps its NULL module check and passes
module->data_path. The three entry points and the hook's type,
obs_module_add_extension_t, are declared in obs-internal.h without
EXPORT, so they are hidden.

The new file joins libobs.core just before obs-module.c.h, with
libobs.pch.h. No group, PCH or source-sets.json change, and the
exported symbols are unchanged (1766). test_core_module_load: 13 of 13
against the C-backend libobs, the hybrid libobs and
libobs-c-reference.

Refs obs-rust#1876
RED for the port of libobs/obs-module-paths.c.h to rust/obs-core,
module module_paths. The safe core is a stub (todo!()): data_dir()
(obs_module_paths_data_dir), find_file() (obs_module_paths_find_file),
find() (obs_module_paths_find) and search_pattern(), the glob pattern
find() builds. Paths are bytes, Option for NULL. The file system is the
caller's ModuleFs (os_file_exists, os_glob), and the host's extension
hook a closure on the path being built.

tests/obs_core/module_paths.rs ports the nine module search path cases
of test_core_module_load 1:1, under the same names, in the same order,
with the same layouts and expected values, on a fake file system: find()
for obs_find_modules2() over each added path, find_file() for
obs_find_module_file() on a module with that data path. The
"characterized, not endorsed" cases stay pinned.

Edge cases: the glob pattern for every form of binary directory, one
glob per path, a failed glob, "." and ".." entries, the glob's directory
flag, names cut at the last '.', a file name that is only an extension
(a NULL name), names and directories that hold %module% (not replaced
again), the hook's calls and a hook that empties the path, the macOS
extension ("") with the Cocoa hook, the Windows extension without the
".so" fallback, NULL against empty data paths and files, the "lib"
prefix (ASCII, once), and what data_dir() asks the file system. Three
proptests: data_dir() and find_file() against the written-out rule over
any bytes, and a flat search over any set of names. One intentional
difference is pinned: an empty binary directory searches nothing (the C
passes a NULL dstr to strstr()).

The tests are a module of the existing core category binary,
obs-tests-core.

soldr cargo test -p obs-data --test obs-tests-core obs_core::module_paths
fails 30 of 31 with "not yet implemented"; the 31st checks the two
constants.

Refs obs-rust#1876
Ports libobs/obs-module-paths.c.h to the module_paths module of
rust/obs-core. Every module obs_find_modules2() and obs_load_plugins()
find, the data path of every core module and every
obs_find_module_file() (so every module's locale lookup) go through it.
The hybrid libobs drops the C file and links the Rust shims;
obs-module.c.h keeps the search path list, the module list and all of
the loading.

Safe core (src/module_paths.rs), on bytes, Option for NULL:
- data_dir(): every %module% of the data path replaced by the name, one
  trailing '/' taken off, and for a "lib" name (ASCII, any case) whose
  path does not exist, the path for the name without "lib";
- find_file(): the data path, one '/' when it has none and the file is
  not empty, the file; None when that does not exist;
- search_pattern(): the glob of a binary directory: "<dir>/*<ext>", or,
  with %module%, "<dir up to the first %module%>/*" for directories;
- find(): every match of that glob of the right kind, the name up to its
  last '.', "." and ".." skipped; for a module directory the binary is
  <name> plus the host's extension, else lib<name><ext>; reported with
  its data path.
The file system is the caller's ModuleFs and the host's extension hook
a closure. The C's dstr steps are followed exactly, NULL against empty
included (a copy of "" is NULL, a path cut to nothing is NULL). Nothing
panics, indexes or overflows; the module denies clippy's indexing,
arithmetic, unwrap and panic lints.

Kept as the C has it, characterized and not endorsed (obs-rust#1876): data
paths are reported whether or not they exist, and so is the "lib"
fallback; only one trailing '/' is taken off, and an empty or "/" data
path reports no module; a module directory with a '.' in its name is
never found; a directory passes for a binary; the C's ".so" "legacy
fallback" is overwritten before it is tried; find_file() with an empty
file is the data path, and with an empty data path a relative path.
The "lib" prefix is matched in ASCII, where the C's toupper() follows
the C locale.

Shim (src/ffi/module_paths.rs): the three functions with the C
signatures. The file system is libobs's own os_file_exists() and
os_glob() (obs-util's ports). The hook is the caller's
obs_host_add_module_extension(), called with a bmalloc'd struct dstr it
may grow; the callback gets a struct obs_module_info2 whose strings are
valid for the call, with the type passed through. The paths are
bmalloc'd and the caller bfrees them. Intentional differences, for
arguments obs-module.c never passes: an empty or NULL binary directory
searches nothing (the C hands a NULL dstr to strstr() and crashes, as
obs_add_module_path("", ...) did), a NULL callback searches nothing,
and a NULL hook leaves the path as it is.

C side: the file leaves libobs.core for its own group,
libobs.ported-module-paths (LIBOBS_PORTED_SOURCES), whose PCH is
obs-internal.h, so the C reference and the C backend keep compiling it.
The functions are declared in obs-internal.h without EXPORT, so the
shims are hidden: rust-hidden.txt, rust-exports.map and
rust-unexports-macos.txt. libobs-rust already re-exports obs-core's
ffi, and obs-core now depends on obs-util for the file system, bmem and
dstr.

Results: test_core_module_load (13 of 13, under a private Xvfb) passes
against the C-backend libobs, the hybrid libobs and
libobs-c-reference. The exported symbol sets are identical, 1766 in
each. Tier 1: obs_core::module_paths 31 of 31.

Refs obs-rust#1876
The oracle, oracle/module_paths.c, is libobs/obs-module-paths.c.h,
unmodified, with its three functions renamed to oracle_*. The rest
keeps its real names: os_file_exists, os_glob, os_globfree, the dstr
helpers, astrcmpi_n, bmalloc and bfree are obs-util's under cargo test,
so both sides search the same file system and their paths are bfree'd
alike. It also measures struct obs_module_info2 for the layout test.

Tier 3 (tests/obs_core/module_paths_parity.rs), in obs-tests-core,
builds a real tree under a new directory in the temporary directory
(flat plugins with .so, .dll, lib and LIB names, no extension, dotted,
spaced, non-ASCII and, on Linux, non-UTF-8 names, a directory named
dir.so; module directories with and without binaries, lib binaries, a
dotted one, a v.so directory, a bundle directory, a legacy .so, one
named %module%; data directories) and calls both through the C
signatures with the same hooks and callbacks, which log every call.
Compared:

- obs_module_paths_find(): every module reported (binary path, data
  path, name, NULL included, the type passed through), in order, and
  every hook call with the path it got, over 13 binary directories x 16
  data paths (NULL, "", "/", "//", trailing separators, repeated and
  missing %module%, relative ones) x 4 extensions (".so", ".dll", "",
  NULL) x 4 hooks (".so", ".dll", none, the Cocoa one): 3328 searches;
- obs_module_paths_data_dir() over 20 names x 16 data paths, and
  obs_module_paths_find_file() over 10 data paths x 13 files;
- proptests (2048 cases each) over paths built from the tree's names,
  separators, dots and %module% pieces, for all three;
- the obs_module_info2 layout: size, alignment and every offset.

Excluded, the intentional differences, tested on the shims alone: an
empty or NULL binary directory, a NULL callback and a NULL hook. 11 of
11 pass.

Deliberate breaks of the safe core, not committed, each caught (failed
tests of Tier 1, 31, and Tier 3, 11):

| Mutant                                 | Tier 1 | Tier 3 |
| one trailing '/' not taken off         | 6      | 4      |
| every trailing '/' taken off           | 2      | 3      |
| "lib" case-sensitive                   | 3      | 4      |
| no "lib" data fallback                 | 10     | 4      |
| "lib" fallback only if it exists       | 9      | 4      |
| first %module% only                    | 2      | 4      |
| the replacement searched again         | 2      | 4      |
| a copy of "" is "", not NULL           | 5      | 3      |
| '/' before an empty file               | 1      | 1      |
| '/' after a trailing '/'               | 3      | 2      |
| the extension on a directory search    | 10     | 4      |
| cut at the last %module%               | 2      | 2      |
| no lib<name> binary                    | 5      | 2      |
| the ".so" fallback tried               | 1      | 2      |
| the name cut at the first '.'          | 1      | 2      |
| "." and ".." not skipped               | 1      | 0      |
| the directory flag inverted            | 18     | 4      |
| the hook not called                    | 8      | 3      |

Tier 3 cannot see the "." and ".." mutant: a real glob never returns
them. Tier 1's fake one does.

Refs obs-rust#1876
… paths

naming.md: obs-module-paths.c.h, extracted from obs-module.c.h, goes in
rust/obs-core. rust/README.md: the obs-core layout row names it, and the
obs-module-paths.c.h row of the ported table: the swap, what stays in
obs-module.c.h, what C passes in, the behavior kept from the
characterization, the ASCII "lib" match, the intentional differences
and what Tier 3 compares. obs-core's tests are already in the core
category binary, obs-tests-core.

port_comparison: module_paths/{data_dir, data_dir_lib, find_file/hit,
find_file/miss, find/flat, find/module_dirs} on a small real tree (16
plugins, 16 lib plugins, 16 module directories), shim against oracle,
in benches/port_comparison/core.rs (obs-c-oracle now dev-depends on
obs-core). Both sides make the same os_file_exists() and os_glob()
calls, which dominate.

Refs obs-rust#1876
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants