Skip to content

webrtc-sys: forward-declare PeerContext as struct (fixes 4x LNK2019 on windows-msvc)#1167

Open
wcares wants to merge 1 commit into
livekit:mainfrom
wcares:win-msvc-jsep-fix
Open

webrtc-sys: forward-declare PeerContext as struct (fixes 4x LNK2019 on windows-msvc)#1167
wcares wants to merge 1 commit into
livekit:mainfrom
wcares:win-msvc-jsep-fix

Conversation

@wcares

@wcares wcares commented Jun 12, 2026

Copy link
Copy Markdown

Summary

webrtc-sys/include/livekit/jsep.h forward-declares class PeerContext;, but PeerContext is a cxx shared type defined on the Rust side as pub struct PeerContext (src/peer_connection.rs), so cxx emits struct PeerContext everywhere it generates C++.

Under the MSVC ABI (clang-cl / cl), the class vs struct tag is part of the mangled name, so rust::Box<class PeerContext> (from jsep.cpp, which includes jsep.h) and rust::Box<struct PeerContext> (from the cxx-generated peer_connection.cc) mangle to different symbols → 4 unresolved externals at link on x86_64-pc-windows-msvc:

LNK2019: unresolved external symbol ... rust::Box<PeerContext>::drop / ::from_raw / ...

GCC/Clang on Linux/macOS use the Itanium ABI, which ignores the class/struct tag in mangling, so this never surfaces there — only the MSVC ABI is affected. Verified identical in webrtc-sys 0.3.21 and 0.3.32.

Fix (1 word)

-class PeerContext;
+struct PeerContext;

jsep.h is the only place in the crate that tags PeerContext as class; every other reference uses rust::Box<PeerContext> (untagged) and the cxx bridge declares it struct. Making the forward declaration struct makes the tag consistent crate-wide. No-op on Linux/macOS; fixes the link on windows-msvc.

Verification

With this change applied (via [patch.crates-io]), omnynet-agent links clean with the livekit-av feature ON on x86_64-pc-windows-msvc (clang-cl), in combination with +crt-static for the libwebrtc /MT prebuilt, and runtime-connects to a LiveKit room (rust SDK 0.7.42).

Closes the windows-msvc build failure tracked in #1154.

…n windows-msvc)

include/livekit/jsep.h forward-declares `class PeerContext;`, but PeerContext is a
cxx shared type defined Rust-side as `pub struct PeerContext` (src/peer_connection.rs),
so cxx emits `struct PeerContext` everywhere it generates C++. Under the MSVC ABI
(clang-cl/cl) the class-vs-struct tag is part of the mangled name, so
rust::Box<class PeerContext> (jsep.cpp) and rust::Box<struct PeerContext>
(cxx-generated peer_connection.cc) mangle to different symbols -> 4 unresolved
externals at link on x86_64-pc-windows-msvc. No-op on Linux/macOS (Itanium ABI).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wcares wcares requested a review from cloudwebrtc as a code owner June 12, 2026 13:07
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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