Skip to content

feat(net): initial SDL3_net bindings#390

Open
revmischa wants to merge 5 commits into
masterfrom
feat/sdl3-net
Open

feat(net): initial SDL3_net bindings#390
revmischa wants to merge 5 commits into
masterfrom
feat/sdl3-net

Conversation

@revmischa

@revmischa revmischa commented May 23, 2026

Copy link
Copy Markdown
Member

sdl3-net-sys 0.6.0 is on crates.io, so this wires up a net feature behind it.

The safe wrapper covers:

  • init() / NetContext (ref-counted init/quit)
  • Address (resolve, status/wait, local addresses, ref-counted clone/drop)
  • StreamSocket (client connect, read/write/drain, pending writes, peer address)
  • Server (bind + non-blocking accept)
  • DatagramSocket and Datagram (send/recv with sender address)
  • wait_until_input_available over a heterogeneous socket slice
  • Packet-loss simulation hooks

examples/net-echo.rs runs a tiny in-process TCP echo to exercise the API end to end.

Upstream pkg-config gotcha

sdl3-net-sys 0.6.0 ships a pkg-config file with an empty prefix=, so the link search path it emits resolves to /lib. The dynamic build is patched around in our own build.rs via DEP_SDL3_NET_OUT_DIR so rustc finds the freshly built libSDL3_net.so. Static linking still fails because the same bug fires inside sdl3-net-sys's own compilation (cargo verifies the static lib exists at sdl3-net-sys link-time, before our build.rs runs), so build-from-source-static intentionally does not pull in net for now. A comment in Cargo.toml explains the situation.

Use --features build-from-source,net to build/test.

Wires up sdl3-net-sys 0.6.0-pre-0 behind a new `net` feature. The
safe wrapper covers init, async hostname resolution with ref-counted
addresses, TCP-style stream sockets (client + server), UDP-style
datagram sockets, and the WaitUntilInputAvailable multiplex.

The sdl3-net-sys prerelease ships a pkg-config file with an empty
`prefix=` so its emitted link search path resolves to `/lib`.
Worked around for dynamic builds via DEP_SDL3_NET_OUT_DIR in build.rs;
static linking (build-from-source-static + net) is left out for now
since the same bug fires inside sdl3-net-sys's own compilation. A
note in Cargo.toml explains the situation. Dynamic build-from-source
+ net works end to end (examples/net-echo.rs covers a tiny echo
round trip).
@revmischa revmischa changed the title feat(net): initial SDL3_net bindings (prerelease) feat: initial SDL3_net bindings (prerelease) May 23, 2026
@revmischa revmischa changed the title feat: initial SDL3_net bindings (prerelease) feat(net): initial SDL3_net bindings (prerelease) May 23, 2026
@revmischa
revmischa requested a review from Copilot May 23, 2026 05:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds initial Rust bindings for the prerelease SDL3_net extension library behind a new net cargo feature, including a safe-ish wrapper layer, build integration, and an end-to-end example.

Changes:

  • Introduce src/sdl3/net wrapper API (init context, address resolution, TCP/UDP sockets, heterogeneous input wait, packet-loss simulation hooks).
  • Wire up the net feature + sdl3-net-sys prerelease dependency, including a build.rs workaround for the upstream pkg-config prefix= bug.
  • Add examples/net-echo.rs and update user-facing docs (README + feature table).

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/sdl3/net/mod.rs New SDL3_net wrapper module (contexts, addresses, stream/datagram sockets, input waiting).
src/sdl3/lib.rs Expose pub mod net behind #[cfg(feature = "net")] and document the feature.
README.md Update extension library support table to reflect prerelease SDL3_net support via net feature.
examples/net-echo.rs Add a small in-process TCP echo example exercising the new API.
Cargo.toml Add optional sdl3-net-sys dependency, net feature, feature wiring, and example gating.
Cargo.lock Lockfile updates for sdl3-net-sys + sdl3-net-src prerelease.
build.rs Add link-search-path workaround using DEP_SDL3_NET_OUT_DIR.

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

Comment thread src/sdl3/net/mod.rs
Comment thread src/sdl3/net/mod.rs Outdated
Comment thread src/sdl3/net/mod.rs Outdated
revmischa added 2 commits May 22, 2026 22:26
- local_addresses: guard against negative/zero count before allocating
  (signed c_int would otherwise wrap to huge usize)
- Waitable: mark unsafe trait, document the safety contract — the trait
  hands raw pointers to NET_WaitUntilInputAvailable, so external impls
  could otherwise trigger UB via a safe API
- Datagram::address: fix doc to reflect the owned/refcounted return
  value (the impl already RefAddress'd)
SDL3_net 3.2.0 shipped, so drop the prerelease pin and mark the feature
as fully supported in the README and crate-level docs.

The pkg-config prefix bug in sdl3-net-sys is still present in 0.6.0, so
the DEP_SDL3_NET_OUT_DIR workaround in build.rs and the carve-out from
build-from-source-static remain in place for now.
@revmischa revmischa changed the title feat(net): initial SDL3_net bindings (prerelease) feat(net): initial SDL3_net bindings Jun 9, 2026
@revmischa
revmischa requested a review from Copilot June 9, 2026 20:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Comment thread Cargo.toml
Comment thread examples/net-echo.rs
Comment thread examples/net-echo.rs
Surface drain failures instead of silently continuing after a socket
error.
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