Packages

Elixir NIF bindings for the CIX P1 (Arm-China Zhouyi) NPU via the NOE runtime

Current section

Files

Jump to
cix_p1_tpu mix.exs
Raw

mix.exs

defmodule CixP1.MixProject do
use Mix.Project
@version "0.1.2"
@github_url "https://github.com/monoflow-ayvu/cix-p1-tpu"
# MIX_TARGET -> cross triplet. The Nerves system builds aarch64/glibc.
@mix_target_triplets %{
"nerves_system_orangepi6" => {"aarch64", "unknown", "linux-gnu"}
}
def project do
maybe_set_target_triplet_from_mix_target()
[
app: :cix_p1_tpu,
version: @version,
elixir: "~> 1.17",
start_permanent: Mix.env() == :prod,
deps: deps(),
package: package(),
description:
"Elixir NIF bindings for the CIX P1 (Arm-China Zhouyi) NPU via the NOE runtime",
compilers: [:elixir_make] ++ Mix.compilers(),
make_targets: ["all"],
make_clean: ["clean"],
make_precompiler: {:nif, CCPrecompiler},
make_precompiler_url: "#{@github_url}/releases/download/v#{@version}/@{artefact_filename}",
make_precompiler_filename: "cix_p1_nif",
make_precompiler_priv_paths: ["cix_p1_nif.so"],
cc_precompiler: [
compilers: %{
{:unix, :linux} => %{
# Nerves sets TARGET_* so cc_precompiler resolves one of these.
"aarch64-linux-gnu" => {
"aarch64-nerves-linux-gnu-gcc",
"aarch64-nerves-linux-gnu-g++"
},
"aarch64-unknown-linux-gnu" => {
"aarch64-nerves-linux-gnu-gcc",
"aarch64-nerves-linux-gnu-g++"
}
}
}
],
docs: docs(),
name: "CixP1",
source_url: @github_url
]
end
# Map MIX_TARGET to the cross triplet env cc_precompiler expects, unless the
# caller pins it explicitly (CIX_P1_KEEP_TARGET_TRIPLET=1).
defp maybe_set_target_triplet_from_mix_target do
case Map.get(@mix_target_triplets, System.get_env("MIX_TARGET")) do
nil ->
:ok
{arch, vendor, abi} ->
unless keep_external_target_triplet?() do
System.put_env("TARGET_ARCH", arch)
System.put_env("TARGET_VENDOR", vendor)
System.put_env("TARGET_OS", "linux")
System.put_env("TARGET_ABI", if(abi == "linux-gnu", do: "gnu", else: abi))
end
end
end
defp keep_external_target_triplet? do
case System.get_env("CIX_P1_KEEP_TARGET_TRIPLET") do
nil -> false
value -> String.downcase(value) in ["1", "true", "yes"]
end
end
def application do
[
extra_applications: [:logger]
]
end
defp deps do
[
{:elixir_make, "~> 0.8", runtime: false},
{:cc_precompiler, "~> 0.1", runtime: false},
{:nx, "~> 0.7", optional: true},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
]
end
defp package do
files =
~w(c_src lib Makefile mix.exs README.md .formatter.exs)
|> maybe_add_checksum()
[
name: "cix_p1_tpu",
licenses: ["Apache-2.0"],
links: %{"GitHub" => @github_url},
files: files
]
end
defp maybe_add_checksum(files) do
if File.exists?("checksum.exs"), do: ["checksum.exs" | files], else: files
end
defp docs do
[
main: "readme",
extras: ["README.md"]
]
end
end