Packages

Elixir NIF for ZStandard compression.

Current section

Files

Jump to
z_standard mix.exs
Raw

mix.exs

defmodule Mix.Tasks.Compile.ZStandard do
@zstd "v1.4.5"
defp clone do
File.mkdir_p!("priv")
IO.puts("Cloning zstd...")
"git"
|> System.cmd(
[
"clone",
"-c",
"advice.detachedHead=false",
"--depth",
"1",
"--branch",
@zstd,
"https://github.com/facebook/zstd.git",
"./priv/zstd"
],
stderr_to_stdout: true
)
|> post_execute
true
end
def run(_) do
if match?({:win32, _}, :os.type()) do
IO.warn("Windows is not supported.")
exit(1)
end
project = Mix.Project.config()
dest = Mix.Project.compile_path(project)
base = Path.dirname(dest)
build_priv = Path.join(base, "priv")
build_nif = Path.join(build_priv, "z_standard_nif.so")
if File.exists?("./priv/zstd/Makefile") do
{version, 0} = System.cmd("git", ~W(describe --tags), cd: "./priv/zstd")
unless @zstd == String.trim(version) do
File.rm_rf!("./priv")
clone()
end
else
clone()
end
unless File.exists?("./priv/zstd/lib/libzstd.a") do
IO.puts("Building zstd...")
"make"
|> System.cmd(~W(MOREFLAGS=-fPIC -C priv/zstd/lib libzstd.a), stderr_to_stdout: true)
|> post_execute
end
unless File.exists?("./priv/z_standard_nif.so") do
IO.puts("Building NIF...")
"make" |> System.cmd(~W(-C c_src), stderr_to_stdout: true) |> post_execute
end
unless File.exists?(build_nif) do
File.mkdir_p!(build_priv)
File.cp!("./priv/z_standard_nif.so", build_nif)
end
:ok
end
defp post_execute({_, 0}), do: :ok
defp post_execute({log, status}) do
IO.binwrite(log)
exit(status)
end
end
defmodule ZStandard.MixProject do
use Mix.Project
def project do
[
app: :z_standard,
description: "Elixir NIF for ZStandard compression.",
compilers: [:ZStandard] ++ Mix.compilers(),
version: "0.0.2",
elixir: "~> 1.10",
start_permanent: Mix.env() == :prod,
deps: deps(),
package: package(),
# # Testing
# test_coverage: [tool: ExCoveralls],
# preferred_cli_env: [
# coveralls: :test,
# "coveralls.detail": :test,
# "coveralls.post": :test,
# "coveralls.html": :test
# ],
# dialyzer: [ignore_warnings: ".dialyzer", plt_add_deps: true],
# Docs
name: "ZStandard",
source_url: "https://github.com/IanLuites/z_standard",
homepage_url: "https://github.com/IanLuites/z_standard",
docs: [
main: "readme",
extras: ["README.md"]
]
]
end
def package do
[
name: :z_standard,
maintainers: ["Ian Luites"],
licenses: ["MIT"],
files: [
# Nif
"c_src/z_standard_nif.c",
"c_src/Makefile",
# Elixir
"lib/z_standard.ex",
".formatter.exs",
"mix.exs",
"README*",
"LICENSE*"
],
links: %{
"GitHub" => "https://github.com/IanLuites/z_standard"
}
]
end
def application do
[
extra_applications: [:logger]
]
end
defp deps do
[{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}]
end
end