update-cgo-pragmas
go generate script
This script updates the cgo pragmas for each C function call site in the Go source files. It should be run after any change to the C function signatures in the Rust code, and after any change to the Go source files that adds or removes calls to C functions.
The script scans for calls to C functions in the Go source files, identifies the corresponding cgo declaration (import "C"), and injects the appropriate cgo pragmas for each C function call site.
The script relies on the convention that C function calls are made via identifiers with the prefix `_Cfunc_`, which is the default naming scheme used by cgo for C function calls. For example, a call to `C.fwd_get_from_revision` would be identified as a call to the C function `fwd_get_from_revision` via the identifier `_Cfunc_fwd_get_from_revision`.
The script ensures that each C function has at most one callsite.
The script also removes any old cgo pragmas that do not match the current set of C functions being called, to ensure that the source files are clean and up-to-date.
The pragmas are injected in declaration order, i.e., the first C function call site in the file will have its pragmas injected first. This is deterministic as it relies on the order of AST traversal. Pre-sorting the C functions by name before injection is not necessary; however, refactoring the source would result in a different injection order.