Skip to content

Fix compilation failure when used as a hex dependency#4

Merged
einari merged 2 commits into
mainfrom
copilot/fix-compilation-issues-hex-dependency
May 12, 2026
Merged

Fix compilation failure when used as a hex dependency#4
einari merged 2 commits into
mainfrom
copilot/fix-compilation-issues-hex-dependency

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

Elixir expands %Module{} struct literals at compile time via Module.__struct__/1. Because Mix compiles hex dependencies in parallel, cratis_chronicle_contracts modules are not yet loaded when chronicle is compiled, causing failures like:

error: Cratis.Chronicle.Contracts.Events.EventType.__struct__/1 is undefined, cannot expand struct Cratis.Chronicle.Contracts.Events.EventType.

Changes

  • All external struct literals → struct/2 calls: Replaced every %ContractModule{...} literal from cratis_chronicle_contracts and bcl with struct(ContractModule, ...). struct/2 is resolved at runtime, eliminating the compile-time dependency on those modules being loaded.

    # Before
    %EventType{Id: id, Generation: gen}
    
    # After
    struct(EventType, Id: id, Generation: gen)
  • @mongodb_sink_type_id module attribute → private function (projections/registrar.ex, reducers/handler.ex): Module attributes are evaluated at compile time, so the %BclGuid{...} literal was moved into a defp mongodb_sink_type_id/0 that returns the struct at runtime.

    # Before
    @mongodb_sink_type_id %BclGuid{lo: 0x45472BE122202C41, hi: 0x75FD97F7B1F0009C}
    
    # After
    defp mongodb_sink_type_id, do: struct(BclGuid, lo: 0x45472BE122202C41, hi: 0x75FD97F7B1F0009C)

…ix hex dependency compilation

Agent-Logs-Url: https://github.com/Cratis/Chronicle.Elixir/sessions/926b0a87-a494-4686-bf3b-67197451c069

Co-authored-by: einari <134365+einari@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix compilation failure when using cratis_chronicle as hex dependency Fix compilation failure when used as a hex dependency May 12, 2026
Copilot finished work on behalf of einari May 12, 2026 03:37
Copilot AI requested a review from einari May 12, 2026 03:37
@einari einari marked this pull request as ready for review May 12, 2026 03:57
@einari einari merged commit c54d048 into main May 12, 2026
@einari einari deleted the copilot/fix-compilation-issues-hex-dependency branch May 12, 2026 03:59
@einari einari added the patch label May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compilation fails when used as a hex dependency, struct literals cannot be expanded

2 participants