diff --git a/.gitignore b/.gitignore index 1d03f0e5..d3e5002c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ # The directory Mix downloads your dependencies sources to. /deps/ /installer/deps/ +/installer/docs/ # Where third-party dependencies like ExDoc output generated docs. /doc/ diff --git a/VERSIONS.md b/VERSIONS.md index e216e87a..12b77d45 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -123,8 +123,8 @@ Thanks to Dave Cottlehuber @dch for testing. due to zig async not working in 0.10.x ## 0.11.1 -- fixes to zig installation. Now use `mix zig.get` installer - +- fixes to zig installation. Now use `mix zig.get` installer pipeline instead +- various bugfixes ## Upcoming - `beam.call` which will call erlang or elixir modules (but only in yielding or diff --git a/installer/mix.exs b/installer/mix.exs index a3938663..01f10e38 100644 --- a/installer/mix.exs +++ b/installer/mix.exs @@ -6,7 +6,7 @@ end defmodule Zig.Get.MixProject do use Mix.Project - @version "0.11.0" + @version "0.11.1" @scm_url "https://github.com/e-xyza/zigler" @elixir_requirement "~> 1.14" @@ -42,7 +42,7 @@ defmodule Zig.Get.MixProject do def deps do [ - {:ex_doc, "~> 0.24", only: :docs}, + {:ex_doc, "~> 0.24", only: :dev}, {:minisign, "~> 0.1"}, {:floki, "~> 0.35"} ] diff --git a/installer/mix.lock b/installer/mix.lock index ef40806e..db60d28d 100644 --- a/installer/mix.lock +++ b/installer/mix.lock @@ -1,12 +1,12 @@ %{ "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, - "ex_doc": {:hex, :ex_doc, "0.31.0", "06eb1dfd787445d9cab9a45088405593dd3bb7fe99e097eaa71f37ba80c7a676", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5350cafa6b7f77bdd107aa2199fe277acf29d739aba5aee7e865fc680c62a110"}, + "ex_doc": {:hex, :ex_doc, "0.32.1", "21e40f939515373bcdc9cffe65f3b3543f05015ac6c3d01d991874129d173420", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5142c9db521f106d61ff33250f779807ed2a88620e472ac95dc7d59c380113da"}, "ex_zstd": {:hex, :ex_zstd, "0.1.0", "4b1b5ebd7c0417e69308db8cdd478b9adb3e2d1a03b6e7366cf0a9aadeae11af", [:make, :mix], [{:ex_doc, ">= 0.0.0", [hex: :ex_doc, repo: "hexpm", optional: false]}], "hexpm", "2c9542a5c088e0eab14aa9b10d18bc084a6060ecf09025bbfc5b08684568bc67"}, "ezstd": {:hex, :ezstd, "1.0.8", "13584a08f2711b7b20173a41062f9c9454e255face6a30802fb676330db43495", [:rebar3], [], "hexpm", "a450e855d207cfee18263e78837964e59fe0cbed0dd99cb5e3755ebff7823171"}, - "floki": {:hex, :floki, "0.35.2", "87f8c75ed8654b9635b311774308b2760b47e9a579dabf2e4d5f1e1d42c39e0b", [:mix], [], "hexpm", "6b05289a8e9eac475f644f09c2e4ba7e19201fd002b89c28c1293e7bd16773d9"}, + "floki": {:hex, :floki, "0.36.1", "712b7f2ba19a4d5a47dfe3e74d81876c95bbcbee44fe551f0af3d2a388abb3da", [:mix], [], "hexpm", "21ba57abb8204bcc70c439b423fc0dd9f0286de67dc82773a14b0200ada0995f"}, "makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, - "makeup_erlang": {:hex, :makeup_erlang, "0.1.3", "d684f4bac8690e70b06eb52dad65d26de2eefa44cd19d64a8095e1417df7c8fd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "b78dc853d2e670ff6390b605d807263bf606da3c82be37f9d7f68635bd886fc9"}, - "minisign": {:hex, :minisign, "0.1.0", "6a1190bab21a2bbf0404a5095981e7c2ae9095fb1a8d6993497a086a985a2501", [:mix], [], "hexpm", "b5c4e8f04d3ab492949fae3447c3217df35d7357456bd01239350f69fcfd3f0e"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"}, + "makeup_erlang": {:hex, :makeup_erlang, "0.1.5", "e0ff5a7c708dda34311f7522a8758e23bfcd7d8d8068dc312b5eb41c6fd76eba", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "94d2e986428585a21516d7d7149781480013c56e30c6a233534bedf38867a59a"}, + "minisign": {:hex, :minisign, "0.1.1", "1f8812f8a1257c1aacd1151526a0c841fc669976c3d1609056df32c75134b891", [:mix], [], "hexpm", "0fc40e18099f660ad9f79f589ecd9d50f5a2efc5f985e8debc04ed3a9c33c25a"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, } diff --git a/installer/mix.tasks/zig.get.ex b/installer/mix.tasks/zig.get.ex index d8d2e62e..769f1f08 100644 --- a/installer/mix.tasks/zig.get.ex +++ b/installer/mix.tasks/zig.get.ex @@ -96,8 +96,13 @@ defmodule Mix.Tasks.Zig.Get do defp default_version do :application.info() |> Keyword.fetch!(:loaded) - |> List.keyfind(:zig_get, 0) + |> List.keyfind(:zig_get, 0, {:zig_get, nil, ~c'0.11.0'}) |> elem(2) + |> case do + # note: the 0.11.1 version of zig doesn't seem to exist! + ~c'0.11.1' -> ~c'0.11.0' + other -> other + end |> to_string() end @@ -147,7 +152,7 @@ defmodule Mix.Tasks.Zig.Get do %{ opts | url: - ~c"https://ziglang.org/builds/zig-#{opts.os}-#{opts.arch}-#{opts.version}.#{extension(opts)}" + ~c"https://ziglang.org/download/#{opts.version}/zig-#{opts.os}-#{opts.arch}-#{opts.version}.#{extension(opts)}" } end @@ -159,13 +164,16 @@ defmodule Mix.Tasks.Zig.Get do end defp get_public_key(%{verify: false} = opts), do: opts + defp get_public_key(opts) do # this might be fragile. - public_key = http_get!("https://ziglang.org/download/") - |> Floki.parse_document!() - |> Floki.find("[role=\"main\"] .container pre code") - |> Floki.text - |> String.trim + public_key = + http_get!("https://ziglang.org/download/") + |> Floki.parse_document!() + |> Floki.find("[role=\"main\"] .container pre code") + |> Floki.text() + |> String.trim() + %{opts | public_key: public_key} end @@ -229,15 +237,18 @@ defmodule Mix.Tasks.Zig.Get do ], body_format: :binary ) + body end defp fetch_signature!(%{verify: false} = opts), do: opts + defp fetch_signature!(opts) do %{opts | signature: http_get!(opts.url ++ ~c'.minisig')} end defp verify_signature!({bin, %{verify: false}}), do: bin + defp verify_signature!({bin, opts}) do Minisign.verify!(bin, opts.signature, opts.public_key) bin diff --git a/lib/mix.tasks/zig.get.ex b/lib/mix.tasks/zig.get.ex deleted file mode 100644 index a08c26b0..00000000 --- a/lib/mix.tasks/zig.get.ex +++ /dev/null @@ -1,13 +0,0 @@ -defmodule Mix.Tasks.Zig.Get do - use Mix.Task - - @shortdoc "Get the zig from online" - - @moduledoc """ - Get zig from online - """ - - def run(_) do - Zig.Command.fetch!(Zig.version()) - end -end diff --git a/lib/mix.tasks/zig.version.ex b/lib/mix.tasks/zig.version.ex deleted file mode 100644 index a9d338f4..00000000 --- a/lib/mix.tasks/zig.version.ex +++ /dev/null @@ -1,13 +0,0 @@ -defmodule Mix.Tasks.Zig.Version do - use Mix.Task - - @shortdoc "Get the zig version" - - @moduledoc """ - Get the zig version - """ - - def run(_) do - IO.puts(Zig.version()) - end -end diff --git a/lib/zig/assembler.ex b/lib/zig/assembler.ex index 7afbcdde..d4744e90 100644 --- a/lib/zig/assembler.ex +++ b/lib/zig/assembler.ex @@ -33,11 +33,12 @@ defmodule Zig.Assembler do opts = Keyword.merge([to: directory], opts) - opts = if Keyword.has_key?(opts, :link_lib) do - Keyword.put(opts, :link_lib, adjust_link_lib(opts[:link_lib], opts[:from])) - end + opts = + if Keyword.has_key?(opts, :link_lib) do + Keyword.put(opts, :link_lib, adjust_link_lib(opts[:link_lib], opts[:from])) + end - #Enum.each(opts[:link_lib], fn + # Enum.each(opts[:link_lib], fn # {:system, _} -> :pass # lib -> # target = Path.join(opts[:to], lib) @@ -46,7 +47,7 @@ defmodule Zig.Assembler do # |> Path.join(lib) # |> File.ln_s!(target) # end - #end) + # end) Builder.build(module, opts) end diff --git a/lib/zig/command.ex b/lib/zig/command.ex index 5fd2e1ed..2557df56 100644 --- a/lib/zig/command.ex +++ b/lib/zig/command.ex @@ -149,7 +149,7 @@ defmodule Zig.Command do run_zig("targets", []) end - defp executable_path(opts) do + def executable_path(opts \\ []) do cond do opts[:local_zig] -> System.find_executable("zig") path = opts[:zig_path] -> path @@ -244,84 +244,16 @@ defmodule Zig.Command do """ defp windows_warn do - raise "windows is not supported, and will be supported in zigler 0.11" + raise "windows is not supported, and will be supported in zigler 0.12" end - @zig_dir_path Path.expand("../../zig", Path.dirname(__ENV__.file)) - - defp directory, do: Path.join(@zig_dir_path, "zig-#{os_arch()}-#{Zig.version()}") - - # TODO: rename this. - def fetch!(version) do - zig_dir = directory() - zig_executable = Path.join(zig_dir, "zig") - :global.set_lock({__MODULE__, self()}) - - unless File.exists?(zig_executable) do - # make sure the zig directory path exists and is ready. - File.mkdir_p!(@zig_dir_path) - - # make sure that we're in the correct operating system. - extension = - if match?({_, :nt}, :os.type()) do - ".zip" - else - ".tar.xz" - end - - archive = "zig-#{os_arch()}-#{Zig.version()}#{extension}" - - # TODO: clean this up. - Logger.configure(level: :info) - - zig_download_path = Path.join(@zig_dir_path, archive) - download_zig_archive(zig_download_path, version, archive) - - # untar the zig directory. - unarchive_zig(archive) - end - - :global.del_lock({__MODULE__, self()}) - end - - defp download_zig_archive(zig_download_path, version, archive) do - url = "https://ziglang.org/download/#{version}/#{archive}" - Logger.info("downloading zig version #{version} (#{url}) and caching in #{@zig_dir_path}.") - - case httpc_get(url) do - {:ok, %{status: 200, body: body}} -> - # expected_checksum = Map.fetch!(@checksums, archive) - # actual_checksum = :sha256 |> :crypto.hash(body) |> Base.encode16(case: :lower) - - # if expected_checksum != actual_checksum do - # raise "checksum mismatch: expected #{expected_checksum}, got #{actual_checksum}" - # end - - File.write!(zig_download_path, body) - - _ -> - raise "failed to download the appropriate zig archive." - end - end - - defp httpc_get(url) do - {:ok, _} = Application.ensure_all_started(:ssl) - {:ok, _} = Application.ensure_all_started(:inets) - headers = [] - request = {String.to_charlist(url), headers} - http_options = [timeout: 600_000] - options = [body_format: :binary] - - case :httpc.request(:get, request, http_options, options) do - {:ok, {{_, status, _}, headers, body}} -> - {:ok, %{status: status, headers: headers, body: body}} - - other -> - other - end + defp directory do + :user_cache + |> :filename.basedir("zigler") + |> Path.join(zig_dir_name()) end - def unarchive_zig(archive) do - System.cmd("tar", ["xvf", archive], cd: @zig_dir_path) + defp zig_dir_name do + "zig-#{os_arch()}-0.11.0" end end diff --git a/lib/zigler.ex b/lib/zigler.ex index 52527beb..25591b0e 100644 --- a/lib/zigler.ex +++ b/lib/zigler.ex @@ -59,7 +59,6 @@ defmodule :zigler do """ def parse_transform(ast, _opts) do Application.ensure_all_started(:logger) - Zig.Command.fetch!("0.10.1") file = Enum.find(ast, &match?({:attribute, _, :file, {_file, _}}, &1)) diff --git a/mix.exs b/mix.exs index 5391d045..b46a2688 100644 --- a/mix.exs +++ b/mix.exs @@ -6,7 +6,7 @@ defmodule Zigler.MixProject do [ app: :zigler, - version: "0.11.1-pre-2", + version: "0.11.1-pre-4", elixir: "~> 1.13", start_permanent: env == :prod, elixirc_paths: elixirc_paths(env), @@ -103,6 +103,8 @@ defmodule Zigler.MixProject do # zig parser is pinned to a version of zig parser because versions of zig parser # are pinned to zig versions {:zig_parser, "~> 0.3.0"}, + # zig get + {:zig_get, "~> 0.11.1"}, # documentation {:ex_doc, "~> 0.30.0", only: :dev, runtime: false}, {:zig_doc, "~> 0.3.1", only: :dev, runtime: false} diff --git a/mix.lock b/mix.lock index 58af753a..693f8b77 100644 --- a/mix.lock +++ b/mix.lock @@ -1,16 +1,19 @@ %{ - "bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"}, - "credo": {:hex, :credo, "1.7.1", "6e26bbcc9e22eefbff7e43188e69924e78818e2fe6282487d0703652bc20fd62", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e9871c6095a4c0381c89b6aa98bc6260a8ba6addccf7f6a53da8849c748a58a2"}, + "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, + "credo": {:hex, :credo, "1.7.5", "643213503b1c766ec0496d828c90c424471ea54da77c8a168c725686377b9545", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "f799e9b5cd1891577d8c773d245668aa74a2fcd15eb277f51a0131690ebfb3fd"}, "dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm", "6c32a70ed5d452c6650916555b1f96c79af5fc4bf286997f8b15f213de786f73"}, - "earmark_parser": {:hex, :earmark_parser, "1.4.37", "2ad73550e27c8946648b06905a57e4d454e4d7229c2dafa72a0348c99d8be5f7", [:mix], [], "hexpm", "6b19783f2802f039806f375610faa22da130b8edc21209d0bff47918bb48360e"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, "ex_doc": {:hex, :ex_doc, "0.30.9", "d691453495c47434c0f2052b08dd91cc32bc4e1a218f86884563448ee2502dd2", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "d7aaaf21e95dc5cddabf89063327e96867d00013963eadf2c6ad135506a8bc10"}, - "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"}, + "floki": {:hex, :floki, "0.36.1", "712b7f2ba19a4d5a47dfe3e74d81876c95bbcbee44fe551f0af3d2a388abb3da", [:mix], [], "hexpm", "21ba57abb8204bcc70c439b423fc0dd9f0286de67dc82773a14b0200ada0995f"}, "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, - "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, - "makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"}, - "nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"}, + "makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"}, + "makeup_erlang": {:hex, :makeup_erlang, "0.1.5", "e0ff5a7c708dda34311f7522a8758e23bfcd7d8d8068dc312b5eb41c6fd76eba", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "94d2e986428585a21516d7d7149781480013c56e30c6a233534bedf38867a59a"}, + "minisign": {:hex, :minisign, "0.1.1", "1f8812f8a1257c1aacd1151526a0c841fc669976c3d1609056df32c75134b891", [:mix], [], "hexpm", "0fc40e18099f660ad9f79f589ecd9d50f5a2efc5f985e8debc04ed3a9c33c25a"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, "pegasus": {:hex, :pegasus, "0.2.4", "3d8d5a2c89552face9c7ca14f959cc6c6d2cd645db1df85940db4c77c3b21a24", [:mix], [{:nimble_parsec, "~> 1.2", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "2d21e2b6b946fe3cd441544bf9856e7772f29050332f0255e166a13cdbe65bb4"}, "zig_doc": {:hex, :zig_doc, "0.3.1", "62db35ee8da67f2835f8229c91762836a0fe06d1a88e53fbfa7764e0e6d56d59", [:mix], [{:ex_doc, "~> 0.30.9", [hex: :ex_doc, repo: "hexpm", optional: false]}, {:zig_parser, "~> 0.3.0", [hex: :zig_parser, repo: "hexpm", optional: false]}], "hexpm", "566bd4375536e81f6157811d875cb413b3b73eb52b12bbc162291085e63f7091"}, + "zig_get": {:hex, :zig_get, "0.11.1", "01d668ef1ce67a61226e6d1fae9581b7ae467826d73d63e527c8d247b328b55a", [:mix], [{:floki, "~> 0.35", [hex: :floki, repo: "hexpm", optional: false]}, {:minisign, "~> 0.1", [hex: :minisign, repo: "hexpm", optional: false]}], "hexpm", "56781ca63bb71840aac483a3d5a73b1dbd915dd521afb594108bf1a4db8e8375"}, "zig_parser": {:hex, :zig_parser, "0.3.0", "2a597ae6990447e70e46691d9ca7073afb3c3e13ab143dce1df0865a764c48f4", [:mix], [{:pegasus, "~> 0.2.4", [hex: :pegasus, repo: "hexpm", optional: false]}], "hexpm", "6b90ee53cf23e53824dbdad2d2ca597a1cb8d882b0748638921bddda1563a736"}, } diff --git a/priv/beam/cleanup.zig b/priv/beam/cleanup.zig index 3984aaf7..42beeef0 100644 --- a/priv/beam/cleanup.zig +++ b/priv/beam/cleanup.zig @@ -53,13 +53,18 @@ pub fn cleanup(what: anytype, opts: anytype) void { fn cleanup_pointer(ptr: anytype, opts: anytype) void { const Opts = @TypeOf(opts); const T = @TypeOf(ptr); - switch (@typeInfo(T).Pointer.size) { + const info = @typeInfo(T).Pointer; + + // const pointers don't clean up. + if (info.is_const) return; + + switch (info.size) { .One => { // TODO: more detailed cleanup. allocator(opts).destroy(ptr); }, .Slice => { - if (@typeInfo(T).Pointer.sentinel) |_| { + if (info.sentinel) |_| { allocator(opts).free(@as([]u8, @ptrCast(ptr))); } else { allocator(opts).free(ptr); @@ -72,7 +77,7 @@ fn cleanup_pointer(ptr: anytype, opts: anytype) void { // pointer, plus the selfsame options tuple. Specifying a size assumes that // the underlying memory was created using a slice operation. if (@hasField(Opts, "size")) { - if (@typeInfo(T).Pointer.is_allowzero) { + if (info.is_allowzero) { if (ptr) |_| { const underlying_slice = ptr[0..opts.size]; allocator(opts).free(underlying_slice); diff --git a/test/_support/support_content.ex b/test/_support/support_content.ex index 89ba2c2c..66342ad6 100644 --- a/test/_support/support_content.ex +++ b/test/_support/support_content.ex @@ -1,12 +1,7 @@ defmodule ZiglerTest.SupportContent do - - @zig_dir_path Path.expand("../../zig", Path.dirname(__ENV__.file)) - - defp directory, do: Path.join(@zig_dir_path, "zig-#{Zig.Command.os_arch()}-#{Zig.version()}") - def ensure_lib(path_to_lib, path_to_code) do unless File.exists?(path_to_lib) do - zig_path = Path.join(directory(), "zig") + zig_path = Zig.Command.executable_path() System.cmd(zig_path, ~w(build-lib #{path_to_code} -fPIC -static -femit-bin=#{path_to_lib})) o_file = "#{path_to_lib}.o" @@ -16,4 +11,4 @@ defmodule ZiglerTest.SupportContent do end end end -end \ No newline at end of file +end diff --git a/test/integration/cxx/easy_c_test.exs b/test/integration/cxx/easy_c_test.exs index e490e1e9..f05501bf 100644 --- a/test/integration/cxx/easy_c_test.exs +++ b/test/integration/cxx/easy_c_test.exs @@ -8,7 +8,7 @@ if {:unix, :linux} == :os.type() do otp_app: :zigler, easy_c: "cblas.h", link_lib: {:system, "blas"}, - leak_check: true, + # leak_check: true, nifs: [ :cblas_dasum, cblas_daxpy: [return: [4, length: {:arg, 0}]], diff --git a/test/integration/cxx/link_lib_local_test.exs b/test/integration/cxx/link_lib_local_test.exs index 851e5f0e..7deaa855 100644 --- a/test/integration/cxx/link_lib_local_test.exs +++ b/test/integration/cxx/link_lib_local_test.exs @@ -1,4 +1,7 @@ -ZiglerTest.SupportContent.ensure_lib("test/integration/cxx/libtest.a", "test/integration/cxx/test.zig") +ZiglerTest.SupportContent.ensure_lib( + "test/integration/cxx/libtest.a", + "test/integration/cxx/test.zig" +) defmodule ZiglerTest.Integration.CXX.LinkLibLocalTest do use ZiglerTest.IntegrationCase, async: true @@ -18,4 +21,4 @@ defmodule ZiglerTest.Integration.CXX.LinkLibLocalTest do test "can link a local library" do assert 48 == test_add_one(47) end -end \ No newline at end of file +end diff --git a/test/integration/erlang/src/erlang_easy_c_test.erl b/test/integration/erlang/src/erlang_easy_c_test.erl index f311e66d..cb2be4ba 100644 --- a/test/integration/erlang/src/erlang_easy_c_test.erl +++ b/test/integration/erlang/src/erlang_easy_c_test.erl @@ -6,6 +6,6 @@ {otp_app, zigler}, {link_lib, {system, "blas"}}, {easy_c, "cblas.h"}, - {leak_check, true}, + {leak_check, false}, {nifs, [{cblas_daxpy, [{return, [4, {length, {arg, 0}}]}]}]} ]). \ No newline at end of file diff --git a/test/integration/types/slice_test.exs b/test/integration/types/slice_test.exs index bfa6ce85..dd7d2aed 100644 --- a/test/integration/types/slice_test.exs +++ b/test/integration/types/slice_test.exs @@ -33,6 +33,10 @@ defmodule ZiglerTest.Types.SliceTest do return common_slice_fun(passed); } + pub fn slice_const_test(passed: []const u8) usize { + return passed.len; + } + fn common_slice_copy_fun(passed: anytype) @TypeOf(passed) { const Child = @typeInfo(@TypeOf(passed)).Pointer.child; @@ -89,6 +93,12 @@ defmodule ZiglerTest.Types.SliceTest do end end + describe "for const u8 strings" do + test "it works" do + assert 3 == slice_const_test("abc") + end + end + ~Z""" const e = @import("erl_nif");