Skip to content

Commit

Permalink
Configure and compile the app in the mix task "rustler_precompiled.do…
Browse files Browse the repository at this point in the history
…wnload" (#76)

* Start the app in the mix task "rustler_precompiled.download"

Also ensure the module is compiled or the beam file for it exists.

* Change app start to app config

* Change access style to use the Access behaviour
  • Loading branch information
philss committed Jun 25, 2024
1 parent 4bb2416 commit a5cd67e
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lib/mix/tasks/rustler_precompiled.download.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ defmodule Mix.Tasks.RustlerPrecompiled.Download do
This is useful when you are developing a new NIF that does not support all platforms.
This task also accept the `--print` flag to print the checksums.
Since v0.7.2 we configure the app invoking this mix task by default. This means that
the app you are invoking this task from will be compiled and run the "release" configuration.
We need to compile the app to make sure the module name is correct.
To avoid that, use the `--no-config` flag.
"""

use Mix.Task
Expand All @@ -24,6 +29,7 @@ defmodule Mix.Tasks.RustlerPrecompiled.Download do
all: :boolean,
only_local: :boolean,
print: :boolean,
no_config: :boolean,
ignore_unavailable: :boolean
]

Expand All @@ -33,12 +39,26 @@ defmodule Mix.Tasks.RustlerPrecompiled.Download do

{options, _args, _invalid} = OptionParser.parse(flags, strict: @switches)

unless options[:no_config] do
Mix.Task.run("app.config", [])
end

case Code.ensure_compiled(module) do
{:module, _module} ->
:ok

{:error, error} ->
IO.puts(
"Could not ensure that module is compiled. Be sure that the name is correct. Reason: #{inspect(error)}"
)
end

urls =
cond do
Keyword.get(options, :all) ->
options[:all] ->
RustlerPrecompiled.available_nif_urls(module)

Keyword.get(options, :only_local) ->
options[:only_local] ->
RustlerPrecompiled.current_target_nif_urls(module)

true ->
Expand All @@ -47,7 +67,7 @@ defmodule Mix.Tasks.RustlerPrecompiled.Download do

result = RustlerPrecompiled.download_nif_artifacts_with_checksums!(urls, options)

if Keyword.get(options, :print) do
if options[:print] do
result
|> Enum.map(fn map ->
{Path.basename(Map.fetch!(map, :path)), Map.fetch!(map, :checksum)}
Expand Down

0 comments on commit a5cd67e

Please sign in to comment.