From 068e432f9c7d1a7ea7522977d058da486935ae19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20M=C3=A4nnchen?= Date: Thu, 4 Apr 2024 06:48:14 +0200 Subject: [PATCH] Fix local_zig Option (#446) --- lib/zig/assembler.ex | 3 ++- lib/zig/builder.ex | 2 +- lib/zig/command.ex | 8 ++++---- lib/zig/compiler.ex | 12 ++++++++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/zig/assembler.ex b/lib/zig/assembler.ex index 6b30e518..b4270b2d 100644 --- a/lib/zig/assembler.ex +++ b/lib/zig/assembler.ex @@ -27,7 +27,8 @@ defmodule Zig.Assembler do :stage1, :include_dir, :c_src, - :packages + :packages, + :local_zig ]) opts = Keyword.merge([to: directory], opts) diff --git a/lib/zig/builder.ex b/lib/zig/builder.ex index c1e77822..2747822b 100644 --- a/lib/zig/builder.ex +++ b/lib/zig/builder.ex @@ -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 diff --git a/lib/zig/command.ex b/lib/zig/command.ex index ab517860..5fd2e1ed 100644 --- a/lib/zig/command.ex +++ b/lib/zig/command.ex @@ -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 @@ -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 @@ -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)) diff --git a/lib/zig/compiler.ex b/lib/zig/compiler.ex index 5b917a0a..863a6fd7 100644 --- a/lib/zig/compiler.ex +++ b/lib/zig/compiler.ex @@ -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, @@ -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}")