Skip to content

hs-bindgen: duplicate Store type from forward declaration in path_info.h #1

@sandydoo

Description

@sandydoo

Problem

When regenerating C API bindings, nix_api_store/path_info.h contains a forward declaration typedef struct Store Store; that is identical to the one in nix_api_store.h. Because hs-bindgen's external binding spec matches on (cname, header) pairs, it treats these as distinct types and generates a duplicate Store type in Generated.Nix.Store.PathInfo.

This means all generated functions that use Store end up referencing one or the other depending on generation order, requiring castPtr at call sites in the high-level bindings.

Current workaround

  • castPtr in Nix/Unsafe/Store.hs (for nix_store_query_path_info_json)
  • castPtr in Nix/Unsafe/Expr.hs (for nix_eval_state_builder_new, since nix_api_expr.h transitively includes path_info.h)

Root cause

hs-bindgen's --external-binding-spec mechanism matches C type declarations by both cname and headers fields. When the same struct Store is forward-declared in multiple headers, the spec entry for one header doesn't suppress generation from the other.

Upstream

This should ideally be fixed in hs-bindgen. No existing issue covers this exact case (searched their tracker). The fix would be to match external binding specs by cname alone (or at least allow header-agnostic matching).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions