|
1 | 1 | defmodule Mix.Tasks.Package.Android.Nif do |
| 2 | + import Runtimes.Android |
2 | 3 | import Runtimes |
3 | 4 | use Mix.Task |
4 | | - alias Mix.Tasks.Package.Android.Runtime |
5 | 5 | require EEx |
6 | 6 |
|
7 | | - def run([]) do |
8 | | - for nif <- Runtimes.default_nifs() do |
9 | | - for arch <- Runtime.default_archs() do |
10 | | - build(arch, Runtimes.get_nif(nif)) |
11 | | - end |
12 | | - end |
| 7 | + def run([nif]) do |
| 8 | + buildall(Map.keys(architectures()), nif) |
13 | 9 | end |
14 | 10 |
|
15 | | - def run(args) do |
16 | | - {git, _tag} = |
17 | | - case args do |
18 | | - [] -> raise "Need git url parameter" |
19 | | - [git] -> {git, nil} |
20 | | - [git, tag] -> {git, tag} |
21 | | - end |
| 11 | + def build(arch, nif) do |
| 12 | + nif = get_nif(nif) |
| 13 | + arch = get_arch(arch) |
| 14 | + env = nif_env(arch) |
22 | 15 |
|
23 | | - build("arm64", Runtimes.get_nif(git)) |
24 | | - end |
| 16 | + # Getting an Elixir version |
| 17 | + if File.exists?(Path.join(elixir_target(arch), "bin")) do |
| 18 | + IO.puts("Elixir already exists...") |
| 19 | + else |
| 20 | + cmd(["scripts/install_elixir.sh", elixir_target(arch)]) |
| 21 | + cmd("mix do local.hex --force && mix local.rebar --force", PATH: env[:PATH]) |
| 22 | + end |
25 | 23 |
|
26 | | - defp build(arch, nif) do |
27 | | - type = Runtime.get_arch(arch).android_type |
28 | | - target = "_build/#{type}-nif-#{nif.name}.zip" |
| 24 | + # Start the builds |
| 25 | + nif_dir = "_build/#{arch.name}/#{nif.basename}" |
29 | 26 |
|
30 | | - if exists?(target) do |
31 | | - :ok |
32 | | - else |
33 | | - image_name = "#{nif.name}-#{arch}" |
| 27 | + if !File.exists?(nif_dir) do |
| 28 | + cmd(~w(git clone #{nif.repo} #{nif_dir}), env) |
| 29 | + end |
| 30 | + |
| 31 | + if nif.tag do |
| 32 | + cmd(~w(cd #{nif_dir} && git checkout #{nif.tag}), env) |
| 33 | + end |
34 | 34 |
|
35 | | - Runtimes.docker_build( |
36 | | - image_name, |
37 | | - Runtime.generate_nif_dockerfile(arch, nif) |
38 | | - ) |
| 35 | + build_nif = Path.absname("scripts/build_nif.sh") |
| 36 | + cmd(~w(cd #{nif_dir} && #{build_nif}), env) |
39 | 37 |
|
40 | | - cmd(~w(docker run --rm |
41 | | - -w /work/#{nif.basename}/ --entrypoint ./package_nif.sh #{image_name} |
42 | | - #{nif.name} > #{target})) |
| 38 | + case static_lib_path(arch, nif) do |
| 39 | + nil -> raise "NIF build failed. Could not locate static lib" |
| 40 | + lib -> lib |
43 | 41 | end |
44 | 42 | end |
45 | 43 |
|
46 | | - def exists?(file) do |
47 | | - case File.stat(file) do |
48 | | - {:error, _} -> false |
49 | | - {:ok, %File.Stat{size: 0}} -> false |
50 | | - _ -> true |
| 44 | + defp buildall(targets, nif) do |
| 45 | + for target <- targets do |
| 46 | + build(target, nif) |
51 | 47 | end |
52 | 48 | end |
53 | 49 | end |
0 commit comments