Skip to content

Commit

Permalink
better versioning pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
ityonemo committed Apr 18, 2024
1 parent 4c74cb3 commit 362d57d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions lib/zig/builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions lib/zig/module.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ defmodule Zig.Module do
:manifest_module,
:sema,
:parsed,
:version,
language: Elixir,
nifs: [],
ignore: [],
Expand Down Expand Up @@ -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()],
Expand Down Expand Up @@ -132,6 +136,7 @@ defmodule Zig.Module do

defp normalize_options(opts) do
opts
|> obtain_version
# |> normalize_nifs
# |> normalize_libs
# |> normalize_build_opts
Expand All @@ -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} ->
Expand Down

0 comments on commit 362d57d

Please sign in to comment.