Skip to content

Commit e50f353

Browse files
committed
cleanup
1 parent 77516fd commit e50f353

File tree

5 files changed

+226
-389
lines changed

5 files changed

+226
-389
lines changed
Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,49 @@
11
defmodule Mix.Tasks.Package.Android.Nif do
2+
import Runtimes.Android
23
import Runtimes
34
use Mix.Task
4-
alias Mix.Tasks.Package.Android.Runtime
55
require EEx
66

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)
139
end
1410

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)
2215

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
2523

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}"
2926

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
3434

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)
3937

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
4341
end
4442
end
4543

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)
5147
end
5248
end
5349
end

lib/mix/tasks/package_android_nif2.ex

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)