Skip to content

webrtc-sys: jsep.h forward-declares PeerContext as class (it's a cxx struct) → 4× LNK2019 on windows-msvc (clang-cl) #1154

Description

@wcares

Summary

webrtc-sys/include/livekit/jsep.h:38 forward-declares class PeerContext;, but PeerContext is a cxx shared type defined on the Rust side as a struct (webrtc-sys/src/peer_connection.rs:213pub struct PeerContext(pub Box<dyn Any + Send>);, exposed via the cxx bridge type PeerContext; at line 208). So cxx generates struct PeerContext everywhere it emits C++.

Under the MSVC C++ ABI (x86_64-pc-windows-msvc, building the C++ with clang-cl or cl), the class vs struct tag is part of the mangled name (@V…@ for class vs @U…@ for struct). So:

  • jsep.cpp (which #includes jsep.h → sees class PeerContext) emits/refers to rust::Box<class PeerContext> symbols, while
  • the cxx-generated peer_connection.cc (sees the bridge struct PeerContext) emits rust::Box<struct PeerContext> symbols.

These mangle to different symbols4× LNK2019 unresolved external at link on windows-msvc:

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

GCC and Clang (Linux/macOS, Itanium ABI) ignore the class/struct tag in mangling, so the symbols are identical there and this never surfaces — it's MSVC-ABI-only.

Fix (one word)

webrtc-sys/include/livekit/jsep.h:

 namespace livekit_ffi {

-class PeerContext;
+struct PeerContext;

 class IceCandidate {

jsep.h:38 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. Aligning the forward declaration to struct makes the tag consistent crate-wide.

This is a no-op on Linux/macOS (clang/gcc mangle class == struct), and resolves the link on windows-msvc.

Verification

With this one-line change applied (via a vendored crate + [patch.crates-io]) plus the documented windows-msvc +crt-static rustflag (to match the libwebrtc prebuilt's /MT), a downstream consumer links cleanly with webrtc-sys enabled on x86_64-pc-windows-msvc (CXX=clang-cl) and connects to a LiveKit room at runtime (rust SDK, screen-capture init OK).

Affected: webrtc-sys 0.3.x (verified identical in 0.3.21, 0.3.32, and current main).

Happy to open a PR with the one-line change if that's preferred.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions