fix(sight): sync FFI header + drift guard + example#667
Merged
Conversation
4 tasks
a454256 to
366a7b9
Compare
cbindgen 0.27 does not recognize Rust 2024's `#[unsafe(no_mangle)]` and silently skips every exported function, so cbindgen.toml's `after_includes` block hand-maintains the C declarations. That block had drifted from src/ffi.rs: declared the deleted `agentsight_config_add_domain_rule` and was missing `agentsight_config_add_https` / `agentsight_config_add_http`. Re-sync the declarations to match the actual 16 FFI exports and rewrite the NOTE to (a) separate the two independent workarounds in play (`item_types=["structs"]` is required for a clean public header, even once cbindgen learns the new attribute), and (b) flag that any drift guard built on top will catch NAME divergence only — signature drift (return type, parameter types/order) still has to be kept in lockstep by hand. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The hand-maintained C declarations in cbindgen.toml have no automatic check against src/ffi.rs, which is how the header silently fell out of sync in the first place. Add a build-time guard that extracts every `pub [unsafe] extern "C" fn agentsight_*` from ffi.rs, every `<type> agentsight_*(` line from the generated header, and panics with the symmetric difference (missing-in-header / stale-in-header) when the two name sets disagree. Runs in build.rs so no .github/workflows change is needed. Reverse-tested three drift modes that the guard must catch — deleted declaration (count delta), renamed function (count preserved), and duplicate-with-drop (count preserved): all panic with precise lists. The previous count-only guard would have silently passed the latter two. The guard panic message and the cbindgen.toml note both explicitly say NAMES only — signature drift (return type / parameter types / order) is not detected and must still be maintained by hand. Also adds a crate-local .gitignore for the generated include/ so a `git add .` from the repo root cannot accidentally stage it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`agentsight_config_add_domain_rule` was removed from the FFI surface (split into `add_https` for SSL probe attachment and `add_http` for plain-HTTP capture); the example was still calling the deleted symbol and would not link. Switch to `add_https` (the same semantics as the old domain rule) and add the missing `-I./include` to the docstring gcc command so copy-paste compiles. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
366a7b9 to
7187515
Compare
Contributor
Author
|
FFI header sync fix (161 lines). Ensures cbindgen output stays consistent with Rust API changes. |
chengshuyi
approved these changes
Jun 8, 2026
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.
What
The hand-maintained C declarations in
cbindgen.toml'safter_includesblock had drifted from the actual FFI surface insrc/ffi.rs:agentsight_config_add_domain_ruleagentsight_config_add_https/agentsight_config_add_httpexamples/agentsight_example.cstill called the deleted symbol (would not link)Root cause: cbindgen 0.27 does not recognize Rust 2024's
#[unsafe(no_mangle)]attribute and silently skips every exported function, so the toml hasitem_types = ["structs"]and the function list is pasted manually — with no mechanical check.Changes (3 commits)
chore(sight): sync FFI header with current ffi.rs— re-syncs the tomlafter_includesblock to match the actual 16 FFI exports; rewrites the NOTE to separate the two independent workarounds (item_types=["structs"]is required even after a cbindgen upgrade, to keep unrelatedpub consts out of the public header).feat(sight): add drift guard for FFI header—build.rsextracts everypub [unsafe] extern "C" fn agentsight_*fromsrc/ffi.rsand every<type> agentsight_*(declaration from the generated header, then panics with the symmetric difference (missing-in-header / stale-in-header) when the two NAME sets disagree. No.github/workflowschange needed. Also adds a crate-local.gitignorefor the generatedinclude/.fix(sight): update FFI example for current API— replaces the deletedagentsight_config_add_domain_rulecall withagentsight_config_add_httpsand adds-I./includeto the docstringgcccommand.What is intentionally NOT changed
src/ffi.rs— actual exports unchanged; this PR only realigns the header.cbindgen.tomlenumerating the cleanup steps for when it lands.include/agentsight.h— still generated, not tracked..github/workflows/— drift detection runs inbuild.rs, not CI YAML.Testing
cargo buildclean.missing / stalelist for (a) deleted declaration, (b) renamed function (count preserved — the count-only iteration would have silently passed), (c) duplicate-with-drop (count preserved). All three reverse cases tried in-tree before commit; restored after.cargo build --releaseclean;gcc -I./include -L./target/release -lagentsightlinks the example;nmshows all 13 example-used FFI symbols resolved againstlibagentsight.so(including the newagentsight_config_add_https).Known limits (called out in code + commit)
The drift guard checks NAMES only — signature drift (return type, parameter types/order/count) is not detected automatically. Both the panic message and the cbindgen.toml note say this verbatim, so a green guard cannot be misread as a full ABI assertion.
Independent of #661–#666.