feat(net): initial SDL3_net bindings#390
Open
revmischa wants to merge 5 commits into
Open
Conversation
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).
Contributor
There was a problem hiding this comment.
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/netwrapper API (init context, address resolution, TCP/UDP sockets, heterogeneous input wait, packet-loss simulation hooks). - Wire up the
netfeature +sdl3-net-sysprerelease dependency, including a build.rs workaround for the upstream pkg-configprefix=bug. - Add
examples/net-echo.rsand 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.
- 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.
Surface drain failures instead of silently continuing after a socket error.
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.
sdl3-net-sys 0.6.0 is on crates.io, so this wires up a
netfeature 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)DatagramSocketandDatagram(send/recv with sender address)wait_until_input_availableover a heterogeneous socket sliceexamples/net-echo.rsruns 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 ownbuild.rsviaDEP_SDL3_NET_OUT_DIRso rustc finds the freshly builtlibSDL3_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), sobuild-from-source-staticintentionally does not pull in net for now. A comment in Cargo.toml explains the situation.Use
--features build-from-source,netto build/test.