diff --git a/VERSIONS.md b/VERSIONS.md index 58ae78d3..328255e8 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -124,6 +124,7 @@ Thanks to Dave Cottlehuber @dch for testing. ## 0.12.0 - breakout `zig.get` into its own package to prevent dependency problems. +- versioning of .so files should track the version. This feature should be considered experimental. ## Upcoming - `precompiled` mode that will let you obtain packages with precompiled assets. diff --git a/lib/zig/builder.ex b/lib/zig/builder.ex index 4846a5fa..43adc24b 100644 --- a/lib/zig/builder.ex +++ b/lib/zig/builder.ex @@ -27,8 +27,7 @@ defmodule Zig.Builder do assigns = %{ module: module.module, - # TODO: fix this version setting! - version: Version.parse!("0.0.0"), + version: module.version, beam_dir: Path.join(:code.priv_dir(:zigler), "beam"), link_lib: module.link_lib, include_dir: module.include_dir, diff --git a/lib/zig/module.ex b/lib/zig/module.ex index 265f5f2a..14ff625c 100644 --- a/lib/zig/module.ex +++ b/lib/zig/module.ex @@ -31,6 +31,7 @@ defmodule Zig.Module do :manifest_module, :sema, :parsed, + :version, language: Elixir, nifs: [], ignore: [], @@ -59,6 +60,9 @@ defmodule Zig.Module do base_code_path: nil | Path.t(), manifest: nil | Manifest.t(), manifest_module: nil | module(), + sema: Sema.t(), + parsed: Parser.t(), + version: String.t(), language: Elixir | :erlang, nifs: nif_opts() | [Nif.t()], ignore: [atom()], @@ -132,6 +136,7 @@ defmodule Zig.Module do defp normalize_options(opts) do opts + |> obtain_version # |> normalize_nifs # |> normalize_libs # |> normalize_build_opts @@ -140,6 +145,26 @@ defmodule Zig.Module do # |> EasyC.normalize_aliasing() end + defp obtain_version(opts) do + otp_app = Keyword.fetch!(opts, :otp_app) + Keyword.put_new_lazy(opts, :version, fn -> + cond do + # try checking the mix project first (this is if the project is being compiled for the first time) + function_exported?(Mix.Project, :config, 0) -> + Mix.Project.config() + |> Keyword.fetch!(:version) + |> Version.parse!() + # try checking the application version (this is if we are hot-patching the so file) + tuple = Application.loaded_applications()[otp_app] -> + tuple + |> elem(2) + |> Version.parse!() + :else -> + Version.parse!("0.0.0") + end + end) + end + # defp normalize_nifs(opts) do # Keyword.update!(opts, :nifs, fn # {:auto, opts} ->