Skip to content

Commit

Permalink
Fix local_zig Option (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
maennchen authored Apr 4, 2024
1 parent 69d9b85 commit 068e432
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/zig/assembler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ defmodule Zig.Assembler do
:stage1,
:include_dir,
:c_src,
:packages
:packages,
:local_zig
])

opts = Keyword.merge([to: directory], opts)
Expand Down
2 changes: 1 addition & 1 deletion lib/zig/builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Zig.Builder do
build_zig_path = Path.join(opts[:to], "build.zig")

File.write!(build_zig_path, build_file)
Command.fmt(build_zig_path)
Command.fmt(build_zig_path, opts)

Logger.debug("wrote build.zig to #{build_zig_path}")
end
Expand Down
8 changes: 4 additions & 4 deletions lib/zig/command.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ defmodule Zig.Command do
sema_command = "run #{sema_file} #{deps} #{mods} -lc #{link_opts(opts)}"

# Need to make this an OK tuple
{:ok, run_zig(sema_command, stderr_to_stdout: true)}
{:ok, run_zig(sema_command, Keyword.put(opts, :stderr_to_stdout, true))}
end

defp package_deps(packages) do
Expand All @@ -118,8 +118,8 @@ defmodule Zig.Command do
|> Enum.map_join(" ", &"-I #{&1}")
end

def fmt(file) do
run_zig("fmt #{file}", [])
def fmt(file, opts \\ []) do
run_zig("fmt #{file}", opts)
end

def compile(module, opts) do
Expand All @@ -132,7 +132,7 @@ defmodule Zig.Command do

lib_dir = Path.join(so_dir, "lib")

run_zig("build --prefix #{so_dir}", cd: assembly_dir)
run_zig("build --prefix #{so_dir}", Keyword.put(opts, :cd, assembly_dir))

src_lib_name = Path.join(lib_dir, src_lib_name(module))
dst_lib_name = Path.join(lib_dir, dst_lib_name(module))
Expand Down
12 changes: 10 additions & 2 deletions lib/zig/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ defmodule Zig.Compiler do

with true <- assembled,
assemble_opts =
Keyword.take(opts, [:link_lib, :build_opts, :stage1, :include_dir, :c_src, :packages]),
Keyword.take(opts, [
:link_lib,
:build_opts,
:stage1,
:include_dir,
:c_src,
:packages,
:local_zig
]),
assemble_opts = Keyword.merge(assemble_opts, from: code_dir),
Assembler.assemble(module, assemble_opts),
true <- precompiled,
Expand Down Expand Up @@ -128,7 +136,7 @@ defmodule Zig.Compiler do
Zig.Module.render_zig(nif_functions, resource_opts, callbacks, module)
)

Command.fmt(nif_src_path)
Command.fmt(nif_src_path, opts)

Logger.debug("wrote module.zig to #{nif_src_path}")

Expand Down

0 comments on commit 068e432

Please sign in to comment.