Skip to content

refactor(tst-c): collapse doubled cbindgen feature guards to single - #41

Merged
aklofas merged 1 commit into
mainfrom
cbindgen-single-guard-cleanup
Jun 15, 2026
Merged

refactor(tst-c): collapse doubled cbindgen feature guards to single#41
aklofas merged 1 commit into
mainfrom
cbindgen-single-guard-cleanup

Conversation

@aklofas

@aklofas aklofas commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Summary

Collapses the redundant doubled preprocessor guard
#if (defined(TST_HAS_X) && defined(TST_HAS_X)) that cbindgen emitted on
190 C function prototypes in bindings/c/include/tstrans.h down to a single
#if defined(TST_HAS_X).

Root cause: every extern-C fn in the rtp/rtsp/udp/tcp/rist surfaces carried a
per-function #[cfg(feature = "X")] on top of its already-#[cfg(feature="X")]-gated
module (declared in bindings/c/core/src/lib.rs). cbindgen ANDs the module-path cfg
with the item cfg, producing the doubled guard. The SRT and HLS surfaces never had
per-fn cfgs and already produced single guards — they were the correct template.

This resolves the cbindgen double-guard comments raised on PR #40 (deferred
follow-up of the chunk-#2 polish pass).

Change

  • Remove the 190 redundant per-function #[cfg(feature = "X")] from the extern-C fns
    under bindings/c/core/src/{rtp,rtsp,udp,tcp,rist}/** (RTP 83, TCP 39, UDP 34,
    RIST 34). Pure deletions — every removed line exactly duplicated its module's
    feature; no compound cfg (all(...)/not(...)/cross-feature) was touched, and no
    #[cfg(test)] was removed.
  • Regenerate tstrans.h; all 190 doubled guards collapse to single guards.
  • Refresh the now-stale explanatory comments in
    scripts/check/c/header-conditional-sections.sh (they described the per-fn cfg as
    the gating mechanism; the module cfg is).

Gating is provably unchanged

The module-level gate in lib.rs remains the sole guard.

  • nm on the cdylib: --no-default-features exports zero transport symbols;
    --features udp exports exactly the 34 udp symbols and 0 rtp/tcp/rist.
  • All 8 feature modes compile (--no-default-features, each single
    --features {srt,rtp,udp,tcp,hls,rist}, --all-features).
  • The committed header's tst_*( function-name set is byte-identical apart from the
    guard collapse (428 prototypes both sides); the top #define TST_HAS_X 1 block is
    unchanged (still SRT + RTP only).

Verification (local, all green)

fmt; clippy --workspace --all-targets --all-features -D warnings; cargo test --workspace --all-features (3054 passed) and --no-default-features (2674 passed);
doctests; nightly-doc; cargo public-api clean ×8; #[non_exhaustive] 265; full
bash-ratchet sweep incl. all C-header checks; fuzz check.

Every extern-C fn in the rtp/rtsp/udp/tcp/rist C surfaces carried a
per-function #[cfg(feature = "X")] on top of its already-#[cfg]-gated
module. cbindgen ANDs the module-path cfg with the item cfg, emitting a
redundant `#if (defined(TST_HAS_X) && defined(TST_HAS_X))` double-guard on
190 prototypes in tstrans.h (RTP 83, TCP 39, UDP 34, RIST 34). The SRT and
HLS surfaces never had per-fn cfgs and already produced single guards.

Remove the 190 redundant per-function cfgs (pure deletions; every removed
line exactly duplicated its module's feature — no compound cfg was touched)
and regenerate tstrans.h, collapsing all 190 to `#if defined(TST_HAS_X)`.
The module-level gate in lib.rs remains the sole guard, so symbol gating is
unchanged: verified by nm (--no-default-features exports zero transport
symbols; --features udp exports the 34 udp symbols and no rtp/tcp/rist) and
by compiling all eight feature modes. The committed header's function set
is byte-for-byte identical apart from the guard collapse.

Also refresh the now-stale explanatory comments in
header-conditional-sections.sh, which described the per-fn cfg as the
gating mechanism; the module cfg is.

Resolves the cbindgen double-guard comments raised on PR #40.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes redundant per-function Rust #[cfg(feature = "...")] attributes from C-ABI extern functions in feature-gated transport modules (rtp/rtsp/udp/tcp/rist), which eliminates cbindgen’s duplicated preprocessor guards in the generated C header and updates the associated header-check script commentary.

Changes:

  • Delete redundant per-function #[cfg(feature = "...")] on extern "C" transport APIs, relying solely on the already feature-gated modules in bindings/c/core/src/lib.rs.
  • Regenerate bindings/c/include/tstrans.h so doubled guards like #if (defined(TST_HAS_X) && defined(TST_HAS_X)) collapse to #if defined(TST_HAS_X).
  • Refresh explanatory comments in scripts/check/c/header-conditional-sections.sh to reflect module-level gating as the mechanism.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated no comments.

Show a summary per file
File Description
scripts/check/c/header-conditional-sections.sh Updates rationale/comments to match module-level feature gating.
bindings/c/include/tstrans.h Regenerated header with single #if defined(TST_HAS_*) guards.
bindings/c/core/src/udp/sender.rs Removes redundant per-function #[cfg(feature="udp")] on externs.
bindings/c/core/src/udp/receiver.rs Removes redundant per-function #[cfg(feature="udp")] on externs.
bindings/c/core/src/udp/mux_sender.rs Removes redundant per-function #[cfg(feature="udp")] on externs.
bindings/c/core/src/udp/demux_receiver.rs Removes redundant per-function #[cfg(feature="udp")] on externs.
bindings/c/core/src/tcp/sender.rs Removes redundant per-function #[cfg(feature="tcp")] on externs.
bindings/c/core/src/tcp/receiver.rs Removes redundant per-function #[cfg(feature="tcp")] on externs.
bindings/c/core/src/tcp/mux_sender.rs Removes redundant per-function #[cfg(feature="tcp")] on externs.
bindings/c/core/src/tcp/listener.rs Removes redundant per-function #[cfg(feature="tcp")] on externs.
bindings/c/core/src/tcp/demux_receiver.rs Removes redundant per-function #[cfg(feature="tcp")] on externs.
bindings/c/core/src/rtsp/server/stop.rs Removes redundant per-function #[cfg(feature="rtp")] on externs.
bindings/c/core/src/rtsp/server/start.rs Removes redundant per-function #[cfg(feature="rtp")] on externs.
bindings/c/core/src/rtsp/server/mount.rs Removes redundant per-function #[cfg(feature="rtp")] on externs.
bindings/c/core/src/rtsp/server/mount_getters.rs Removes redundant per-function #[cfg(feature="rtp")] on externs.
bindings/c/core/src/rtsp/server/builder.rs Removes redundant per-function #[cfg(feature="rtp")] on externs.
bindings/c/core/src/rtsp/client/session.rs Removes redundant per-function #[cfg(feature="rtp")] on externs.
bindings/c/core/src/rtp/sender.rs Removes redundant per-function #[cfg(feature="rtp")] on externs.
bindings/c/core/src/rtp/receiver.rs Removes redundant per-function #[cfg(feature="rtp")] on externs.
bindings/c/core/src/rtp/mux_sender.rs Removes redundant per-function #[cfg(feature="rtp")] on externs.
bindings/c/core/src/rtp/demux_receiver.rs Removes redundant per-function #[cfg(feature="rtp")] on externs.
bindings/c/core/src/rist/sender.rs Removes redundant per-function #[cfg(feature="rist")] on externs.
bindings/c/core/src/rist/receiver.rs Removes redundant per-function #[cfg(feature="rist")] on externs.
bindings/c/core/src/rist/mux_sender.rs Removes redundant per-function #[cfg(feature="rist")] on externs.
bindings/c/core/src/rist/demux_receiver.rs Removes redundant per-function #[cfg(feature="rist")] on externs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aklofas
aklofas merged commit 1faa1bd into main Jun 15, 2026
32 of 33 checks passed
@aklofas
aklofas deleted the cbindgen-single-guard-cleanup branch June 15, 2026 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants