Make pjsip-shim build without a pjproject checkout (fixes #5)#6
Merged
Conversation
pjsip-shim/build.rs hard-coded /tmp/pjproject-2.16 for pjproject's C sources, so `cargo build --release` failed on any fresh checkout with `fatal error: pj/types.h: No such file or directory`. CI never caught it because it built with `--exclude pjsip-shim`. - Gate the pjproject C layer behind an off-by-default `pjproject-cffi` feature; the default build is now pure Rust with no external dependency. - build.rs locates pjproject via PJPROJECT_DIR -> vendored vendor/ dir -> /tmp fallback, and panics with an actionable message when the feature is on but the source is missing (instead of a cryptic cc failure). On macOS the default build lets the inert C symbols resolve at load time so the cdylib still links. - scripts/fetch-pjproject.sh downloads pjproject 2.16 into a git-ignored vendor/ dir that build.rs auto-detects. - CI now builds pjsip-shim by default and adds a pjsip-shim-cffi job that exercises the C layer end-to-end, so this regression can't recur silently. - README documents the pure-Rust default and the optional C layer. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The crate was macOS-only: socket.rs used the BSD/macOS `__error()` errno accessor, the BSD-only sockaddr `sin_len` field, and cast `sin_family` to u8 (it is u16 on Linux). CI had hidden this behind --exclude pjsip-shim. - Add a cross-platform errno_ptr() helper (__error on macOS/BSD, __errno_location on Linux) and route all 18 errno sites through it. - Gate the sin_len assignment to macOS/BSD. - Cast sin_family to libc::sa_family_t so it is u8/u16 as appropriate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
With the feature enabled, the shim failed to link: - On Linux, libpjsip_c_parts.a was linked twice (cc's automatic -l plus a manual --whole-archive by path), producing duplicate symbols. Suppress cc's default metadata and re-link once via cargo's +whole-archive modifier, which maps to --whole-archive (GNU ld) / -force_load (macOS). - pj_getpid and the pj_thread_local_* family are defined in BOTH the Rust shim (pure-Rust fallbacks) and pjproject's os_core_unix.c. Gate the Rust copies behind not(feature = "pjproject-cffi") so exactly one definition exists in each configuration. Also make the pjsip-shim-cffi CI job build-only: the shim's unit tests were written against the Rust stubs and pass null pools/atomics that real pjproject asserts on (SIGABRT); adapting them is tracked separately. The job still guards the build/link path, which is what issue #5 was about. Verified locally on macOS: fetch-pjproject.sh + cargo build -p pjsip-shim --features pjproject-cffi links cleanly; default (feature-off) build unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes #5.
pjsip-shim/build.rshard-coded/tmp/pjproject-2.16for pjproject's C sources, socargo build --releasefailed on any fresh checkout (fatal error: pj/types.h: No such file or directory). CI didn't catch it because it built with--exclude pjsip-shim.Changes
pjproject-cffifeature onpjsip-shim. The default build is now pure Rust with no external dependency —cargo build --releaseworks on a clean checkout.build.rs. Locates pjproject viaPJPROJECT_DIR→ vendoredcrates/pjsip-shim/vendor/pjproject-2.16→/tmp/pjproject-2.16(back-compat). When the feature is on but the source is missing, it panics with an actionable message instead of a crypticccerror. On macOS the default build lets the inert C symbols resolve at load time so the cdylib still links.scripts/fetch-pjproject.sh. Downloads pjproject 2.16 into a git-ignoredvendor/dir thatbuild.rsauto-detects (keeps the GPL source out of git history; run it when you want the C layer).build/build-releasenow includepjsip-shim(guards this regression); newpjsip-shim-cffijob fetches pjproject and exercises the C layer end-to-end. Test/clippy still exclude the shim — its unit tests genuinely need the C layer, and it carries pre-existing warnings that trip-D warnings.pjproject-cffipath.Verification
Reproduced the original failure locally (macOS —
/tmp/pjproject-2.16wasn't present either), then confirmed the fix:cargo build --release --workspace→ ✅ (was the failing command)cargo build --workspace→ ✅cargo build -p pjsip-shim --features pjproject-cffiwith no source → ✅ clean actionable error, not acccrashNote: the
pjproject-cffiC path (and the new CI job) couldn't be exercised locally — no pjproject source here and it's Linux-oriented. The.file()/.include()/.define()calls are unchanged from the previously-working setup, only the directory is parameterized. Worth watching the first run of thepjsip-shim-cffijob.🤖 Generated with Claude Code