Remove redundant module exports#50
Conversation
WalkthroughRemoves the standalone erl_nif Zig module and rewires NIF usage through src/kinda.zig’s direct @cImport of erl_nif.h. Updates imports in dependent files. Adds build-time detection of ERTS include path via calling erl when ERTS_INCLUDE_DIR is unset. Bumps version in mix.exs. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer
participant B as build.zig
participant Env as Environment
participant ERL as erl (ERTS)
participant K as kinda module
Dev->>B: zig build
B->>Env: read ERTS_INCLUDE_DIR
alt ERTS_INCLUDE_DIR is set
B->>K: add include path from env
else ERTS_INCLUDE_DIR is not set
B->>ERL: run erl to query ERTS include path
ERL-->>B: returns include path
B->>K: add discovered include path
end
note over K: @cImport("erl_nif.h") used by kinda and dependents
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
src/beam.zig (2)
759-767: Off-by-one in get_tuple sliceYou drop the last element by slicing to length-1.
- return term_list[0..(length - 1)]; + return term_list[0..@intCast(length)];
1059-1073: make_c_string: wrong iterator target and includes NUL byteLoop iterates over the wrong symbol and returns a binary including the trailing NUL.
-pub fn make_c_string(environment: env, val: [*c]const u8) term { - const result: e.ERL_NIF_TERM = undefined; - var len: usize = 0; - - // first get the length of the c string. - for (result, 0..) |chr, i| { - if (chr == 0) { - break; - } - len = i; - } - - // punt to the slicing function. - return make_slice(environment, val[0 .. len + 1]); -} +pub fn make_c_string(environment: env, val: [*c]const u8) term { + var len: usize = 0; + // compute strlen(val) without including the trailing NUL + while (val[len] != 0) : (len += 1) {} + return make_slice(environment, val[0..len]); +}src/result.zig (1)
14-14: Wrong calling convention enumUse .C (uppercase), not .c.
- fn exported(env: beam.env, n: c_int, args: [*c]const beam.term) callconv(.c) beam.term { + fn exported(env: beam.env, n: c_int, args: [*c]const beam.term) callconv(.C) beam.term {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
build.zig(1 hunks)mix.exs(1 hunks)src/beam.zig(1 hunks)src/erl_nif.zig(0 hunks)src/kinda.zig(1 hunks)src/result.zig(1 hunks)
💤 Files with no reviewable changes (1)
- src/erl_nif.zig
⏰ 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). (3)
- GitHub Check: otp25.0-ex1.18.0 / ubuntu-22.04
- GitHub Check: otp25.0-ex1.16.2 / ubuntu-22.04
- GitHub Check: otp24.2-ex1.16.2 / ubuntu-22.04
🔇 Additional comments (3)
mix.exs (1)
7-7: Version bump looks goodNo issues found.
src/kinda.zig (1)
1-4: Re-export approach is fine, but avoid import cyclesKeeping erl_nif here is OK. Ensure beam.zig and result.zig import erl_nif via @cImport themselves (not via kinda.zig) to prevent cycles described in their files.
build.zig (1)
8-21: Make ERTS include discovery more robust (trim, absolute path, skip missing erl)
- Trim trailing newlines from
b.runoutput withstd.mem.trimRight.- Use
.absoluteforaddIncludePathinstead of.cwd_relative.- Wrap
b.runincatchto skip whenerlisn’t available.- const erlang_include_path = b.run(&argv); - kinda.addIncludePath(.{ .cwd_relative = erlang_include_path }); + const raw = b.run(&argv) catch { return; }; + const erlang_include_path = std.mem.trimRight(u8, raw, "\r\n"); + if (erlang_include_path.len != 0) { + kinda.addIncludePath(.{ .absolute = erlang_include_path }); + }
Summary by CodeRabbit
New Features
Refactor
Chores