Skip to content

Migrate to Zig 0.15.1#46

Merged
jackalcooper merged 14 commits into
mainfrom
update-zig-015
Oct 4, 2025
Merged

Migrate to Zig 0.15.1#46
jackalcooper merged 14 commits into
mainfrom
update-zig-015

Conversation

@jackalcooper
Copy link
Copy Markdown
Contributor

@jackalcooper jackalcooper commented Oct 4, 2025

Summary by CodeRabbit

  • New Features

    • GDB runner script and CI steps to run example tests under GDB and with stacktrace printing.
    • CI now checks Zig and Elixir formatting.
  • Refactor

    • Simplified NIF error/stack-trace handling and made native imports more directly available.
  • Tests

    • Updated tests to match revised, simpler error messages and stack-trace behavior.
  • Chores

    • CI: bumped Zig setup to 0.15.1 and bumped project version to 0.10.5-dev.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 4, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Updates CI to Zig 0.15.1 and adds GDB/stacktrace example test steps; migrates example build API to use b.addLibrary/root_module; switches Zig code to use erl_nif's C interface and exposes beam/erl_nif; simplifies Zig stack-trace dumping and Elixir error shape; updates tests and adds a gdb helper script.

Changes

Cohort / File(s) Summary
CI workflow
.github/workflows/elixir.yml
Bump Zig setup 0.14.10.15.1; add Zig fmt check; add example test variants: run under GDB (scripts/gdb.sh) and with KINDA_PRINT_STACKTRACE=1; reuse Elixir format/test steps.
Example build script
kinda_example/build.zig
Replace b.addSharedLibrary(...)b.addLibrary(...); set .linkage = .dynamic; create lib.root_module via b.createModule(...); move Darwin RPATH handling to lib.root_module; keep linking/install steps.
Example native sources
kinda_example/native/zig-src/main.zig, kinda_example/native/zig-src/prelude.zig
Rebind imports to use kinda.beam and kinda.erl_nif; obtain c via @import("prelude.zig").c; remove pub usingnamespace c; from prelude.zig (stop re-exporting C symbols).
Elixir error & tests
lib/kinda/error/nif_call.ex, kinda_example/test/kinda_example_test.exs
Kinda.CallError reduced to :message only; message/1 simplified (drop error_return_trace and ANSI reset); tests updated to expect simplified messages and stack-trace hint; removed env-branch assertions.
Zig core: BEAM / NIF API
src/beam.zig, src/erl_nif.zig, src/kinda.zig, src/result.zig
Use @import("erl_nif").c and expose pub const erl_nif and pub const beam; change public term to ERL_NIF_TERM; remove pub usingnamespace e / ErlNifTerm alias; change exported NIF callconv from .C.c; remove buffered stack-trace helper and rely on env-driven dumping; switch some buffers to array_list.Managed/AlignedManaged and adjust format strings.
Scripts
scripts/gdb.sh
Add gdb helper: resolve erlexec from Elixir/Erlang runtime, build full command from Mix dry-run, substitute erl with erlexec, run under gdb producing a backtrace on failure; set -e.
Project metadata
mix.exs
Bump project version "0.10.4-dev""0.10.5-dev".

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Test as Elixir Test
  participant VM as Elixir VM
  participant NIF as Zig NIF (exported)
  participant Beam as beam.zig

  Test->>VM: call exported function (e.g., StrInt.make)
  VM->>NIF: invoke exported(env, argc, args) (callconv .c)
  NIF->>Beam: build/raise error (may request stack dump)
  alt KINDA_DUMP_STACK_TRACE set
    Note right of Beam #f8f9fb: Beam dumps stack trace (env-driven)
    Beam->>Beam: dumpStackTrace(...)
  end
  Beam-->>NIF: return `ERL_NIF_TERM` error
  NIF-->>VM: return error term
  VM-->>Test: raise `Kinda.CallError` (message-only)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Upgrade to Zig 0.14 #41 — Overlapping CI and Zig API changes touching .github/workflows/elixir.yml, kinda_example/build.zig, and core Zig modules; likely closely related.
  • Bump version 0.9.2-dev #28 — Also bumps mix.exs project version; relates to the version change here.
  • 0.10.3-dev #44 — Another PR updating the project version in mix.exs; potentially related to release/versioning work.

Poem

I nibble code where Zig roots run deep,
CI hops higher, tests no longer sleep.
When traces whisper and NIFs take flight,
I twitch my whiskers and keep watch by night.
Carrots for builds and a grateful rabbit bite 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “Migrate to Zig 0.15.1” succinctly describes the primary change of updating the project to use Zig version 0.15.1 and aligns with the version bump and associated code migrations in the changeset. It is concise, clear, and directly related to the main objective of the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69f1a17 and e2ce577.

📒 Files selected for processing (4)
  • .github/workflows/elixir.yml (2 hunks)
  • mix.exs (1 hunks)
  • src/beam.zig (5 hunks)
  • src/kinda.zig (5 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60f4333 and 401e1cc.

📒 Files selected for processing (2)
  • .github/workflows/elixir.yml (2 hunks)
  • scripts/gdb.sh (1 hunks)

Comment thread scripts/gdb.sh
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/kinda.zig (1)

13-13: Use consistent type names for clarity.

The type annotation declares std.array_list.AlignedManaged(u8, null) but line 13 initializes with std.array_list.Managed(u8). While these are equivalent (null alignment defaults to Managed behavior), using different names is inconsistent.

Apply this diff for consistency:

-    storage: std.array_list.AlignedManaged(u8, null) = std.array_list.Managed(u8).init(beam.allocator),
+    storage: std.array_list.Managed(u8) = std.array_list.Managed(u8).init(beam.allocator),
-    storage: std.array_list.AlignedManaged(u8, null),
+    storage: std.array_list.Managed(u8),

Also applies to: 19-19

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd81c9e and 69f1a17.

📒 Files selected for processing (1)
  • src/kinda.zig (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: otp25.0-ex1.18.0 / ubuntu-22.04
  • GitHub Check: otp25.0-ex1.16.2 / ubuntu-22.04
  • GitHub Check: otp25.0-ex1.13.0 / ubuntu-22.04
  • GitHub Check: otp24.2-ex1.13.0 / ubuntu-22.04
🔇 Additional comments (4)
src/kinda.zig (4)

1-3: LGTM! Public API exposure aligns with migration.

The public exports of beam and erl_nif.c enable downstream usage of these modules, consistent with the Zig 0.15.1 migration goals.


117-117: LGTM! Correct migration to Managed type.

The change from std.ArrayList(u8) to std.array_list.Managed(u8) aligns with Zig 0.15.1 API changes, and resource cleanup is properly handled with defer buffer.deinit().


119-122: LGTM! Format specifier updated correctly.

The change from "{?}" to "{any}" aligns with Zig 0.15.1's formatting conventions. The {any} specifier is appropriate for general type formatting in the dump function.


310-310: LGTM! Correct format specifier for integer index.

The change from "{?}" to "{d}" correctly formats the argument index as a decimal integer. This improves error message clarity when argument fetching fails.

@jackalcooper jackalcooper merged commit f05cbce into main Oct 4, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant