Skip to content

Commit

Permalink
gets build.zig generator updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ityonemo committed Apr 22, 2024
1 parent 3c4c357 commit 23cfa5f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
30 changes: 15 additions & 15 deletions lib/zig/templates/build.zig.eex
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ pub fn build(b: *std.Build) void {

const erl_nif = b.createModule(
.{
.source_file = .{.cwd_relative = "<%= Path.join(@beam_dir, "erl_nif.zig")%>"},
.dependencies = &[_]std.Build.ModuleDependency{},
.root_source_file = .{.cwd_relative = "<%= Path.join(@beam_dir, "erl_nif.zig")%>"},
.imports = &[_]std.Build.Module.Import{},
});

erl_nif.addSystemIncludePath(
.{.cwd_relative = "<%= :code.root_dir() %>/erts-<%= :erlang.system_info(:version) %>/include"}
);

const beam = b.createModule(
.{
.source_file = .{.cwd_relative = "<%= Path.join(@beam_dir, "beam.zig")%>"},
.dependencies = &[_]std.Build.ModuleDependency{.{
.root_source_file = .{.cwd_relative = "<%= Path.join(@beam_dir, "beam.zig")%>"},
.imports = &[_]std.Build.Module.Import{.{
.name = "erl_nif",
.module = erl_nif
}}
Expand All @@ -22,8 +26,8 @@ pub fn build(b: *std.Build) void {
<%= for {name, path, deps} <- @packages do %>
const <%= name %> = b.createModule(
.{
.source_file = .{.cwd_relative = "<%= path %>"},
.dependencies = &[_]std.Build.ModuleDependency{
.root_source_file = .{.cwd_relative = "<%= path %>"},
.imports = &[_]std.Build.Module.Import{
<%= for dep <- deps do %>
.{
.name = "<%= dep %>",
Expand All @@ -37,8 +41,8 @@ pub fn build(b: *std.Build) void {
<% module_list = Enum.map(@packages, fn {name, _, _} -> ".#{name}" end) %>

const nif = b.createModule(.{
.source_file = .{.cwd_relative = "<%= @zig_code_path %>"},
.dependencies = &[_]std.Build.ModuleDependency{.{
.root_source_file = .{.cwd_relative = "<%= @zig_code_path %>"},
.imports = &[_]std.Build.Module.Import{.{
.name = "erl_nif",
.module = erl_nif
}, .{
Expand All @@ -64,15 +68,11 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});

const beam_system_dir = "<%= :code.root_dir() %>/erts-<%= :erlang.system_info(:version) %>/include";

lib.addSystemIncludePath(.{.cwd_relative = beam_system_dir});

lib.linkLibC();

lib.addModule("erl_nif", erl_nif);
lib.addModule("beam", beam);
lib.addModule("nif", nif);
lib.root_module.addImport("erl_nif", erl_nif);
lib.root_module.addImport("beam", beam);
lib.root_module.addImport("nif", nif);

<%= for lib <- @link_lib do %>
<%= case lib do %>
Expand Down
2 changes: 1 addition & 1 deletion priv/beam/beam.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ pub fn raise_elixir_exception(comptime module: []const u8, data: anytype, opts:
@compileError("elixir exceptions must be structs");
}

var env_ = options.env(opts);
const env_ = options.env(opts);

const name = comptime name: {
break :name "Elixir." ++ module;
Expand Down
6 changes: 3 additions & 3 deletions priv/beam/get.zig
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ inline fn lowerInt(comptime T: type, src: beam.term, result: anytype, opts: anyt
pub fn get_enum(comptime T: type, src: beam.term, opts: anytype) !T {
const enum_info = @typeInfo(T).Enum;
const IntType = enum_info.tag_type;
const only_one = enum_info.fields.len == 1;
comptime var int_values: [enum_info.fields.len]IntType = undefined;
comptime var only_one = enum_info.fields.len == 1;
comptime for (&int_values, 0..) |*value, index| {
value.* = enum_info.fields[index].value;
};
Expand Down Expand Up @@ -345,7 +345,7 @@ pub fn get_pointer(comptime T: type, src: beam.term, opts: anytype) !T {
switch (pointer_info.size) {
.One => {
const alloc = options.allocator(opts);
var result = try alloc.create(Child);
const result = try alloc.create(Child);
errdefer alloc.destroy(result);
try fill(Child, result, src, opts);
return result;
Expand Down Expand Up @@ -615,7 +615,7 @@ fn fill_struct(comptime T: type, result: *T, src: beam.term, opts: anytype) !voi
var registry: StructRegistry(T) = .{};

while (e.enif_get_list_cell(options.env(opts), list, &head, &tail) == 1) : (list = tail) {
var item: beam.term = .{ .v = head };
const item: beam.term = .{ .v = head };
try get_tuple_to_buf(item, &tuple_buf, opts);
const key = tuple_buf[0];
const value = tuple_buf[1];
Expand Down

0 comments on commit 23cfa5f

Please sign in to comment.