refactor(tst-c): collapse doubled cbindgen feature guards to single - #41
Merged
Conversation
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.
There was a problem hiding this comment.
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 inbindings/c/core/src/lib.rs. - Regenerate
bindings/c/include/tstrans.hso 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.shto 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Collapses the redundant doubled preprocessor guard
#if (defined(TST_HAS_X) && defined(TST_HAS_X))that cbindgen emitted on190 C function prototypes in
bindings/c/include/tstrans.hdown 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")]-gatedmodule (declared in
bindings/c/core/src/lib.rs). cbindgen ANDs the module-path cfgwith 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
#[cfg(feature = "X")]from the extern-C fnsunder
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.tstrans.h; all 190 doubled guards collapse to single guards.scripts/check/c/header-conditional-sections.sh(they described the per-fn cfg asthe gating mechanism; the module cfg is).
Gating is provably unchanged
The module-level gate in
lib.rsremains the sole guard.nmon the cdylib:--no-default-featuresexports zero transport symbols;--features udpexports exactly the 34 udp symbols and 0 rtp/tcp/rist.--no-default-features, each single--features {srt,rtp,udp,tcp,hls,rist},--all-features).tst_*(function-name set is byte-identical apart from theguard collapse (428 prototypes both sides); the top
#define TST_HAS_X 1block isunchanged (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-apiclean ×8;#[non_exhaustive]265; fullbash-ratchet sweep incl. all C-header checks; fuzz check.