P1: align Zig FFI symbol names to the Idris2 ABI#39
Merged
Conversation
The Idris2 ABI in src/interface/abi/Chapeliser/ABI/Foreign.idr is the
source of truth for the C-ABI contract. It declares 12 foreign symbols
via `%foreign "C:c_*, libchapeliser_ffi"`:
c_init, c_shutdown, c_get_total_items, c_load_item, c_store_result,
c_process_item, c_process_chunk, c_reduce, c_is_match, c_key_hash,
c_checkpoint_save, c_checkpoint_load
The Zig FFI reference implementation exported these as
`chapeliser_ref_<stem>` instead. The functions correspond 1:1 by stem
and the Result codes already match, but the symbol names diverged, so
the ABI and FFI would not link (every `c_*` import would be undefined).
Fix (Zig-only, ABI unchanged because it is the source of truth):
- Rename the 12 ABI-declared exports from `chapeliser_ref_<stem>` to
exactly `c_<stem>` in src/interface/ffi/src/main.zig.
- The two extra utility functions (`version`, `build_info`) are NOT
part of the ABI, so they are namespaced as `chapeliser_version` and
`chapeliser_build_info` rather than given `c_` names.
- Update all internal call sites in main.zig tests and the
`extern fn` declarations in test/integration_test.zig accordingly.
No behaviour or result-code values changed.
Verification:
- `zig build test` (main.zig unit tests): pass
- `zig build test-integration` (links the lib, resolves externs): pass
- `idris2 --build chapeliser-abi.ipkg`: exit 0
- Every `C:c_<name>` in Foreign.idr now has a matching
`export fn c_<name>` in main.zig.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH
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.
Problem: ABI ↔ FFI symbol-name drift
The Idris2 ABI in
src/interface/abi/Chapeliser/ABI/Foreign.idris the source of truth for the C-ABI contract. It declares 12 foreign symbols via%foreign "C:c_*, libchapeliser_ffi":c_init,c_shutdown,c_get_total_items,c_load_item,c_store_result,c_process_item,c_process_chunk,c_reduce,c_is_match,c_key_hash,c_checkpoint_save,c_checkpoint_loadThe Zig FFI reference implementation in
src/interface/ffi/src/main.ziginstead exported these aschapeliser_ref_<stem>. The functions correspond 1:1 by stem and theResultcodes already matched, but the symbol names diverged, so the ABI and FFI would not link — everyc_*import the ABI declares would resolve to an undefined symbol.Fix (Zig-only; ABI unchanged because it is the source of truth)
chapeliser_ref_<stem>to exactlyc_<stem>insrc/interface/ffi/src/main.zig.version,build_info) are not part of the ABI, so they are namespaced aschapeliser_version/chapeliser_build_inforather than givenc_names.main.zigtests and theextern fndeclarations insrc/interface/ffi/test/integration_test.zigto match.No behaviour or result-code values changed. Only files under
src/interface/ffi/were touched.Verification
zig build test(main.zig unit tests, 7/7): passzig build test-integration(links the shared lib, so the test'sexterndecls resolve against the renamed exports): passidris2 --build chapeliser-abi.ipkg: exit 0C:c_<name>inForeign.idrnow has a matchingexport fn c_<name>inmain.zig; nochapeliser_ref_references remain.Note: any rust-ci / Hypatia / governance red checks are pre-existing estate-infra issues unrelated to this Zig-only change.
🤖 Generated with Claude Code
https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH
Generated by Claude Code