Packages

An Elixir SQLite3 library. Fork of exqlite adding preupdate and commit hooks.

Current section

Files

Jump to
sqlite_drv mix.exs
Raw

mix.exs

defmodule Exqlite.MixProject do
  use Mix.Project

  @version "0.44.2"

  def project do
    [
      app: :exqlite,
      version: @version,
      elixir: "~> 1.17",
      compilers: [:elixir_make] ++ Mix.compilers(),
      make_targets: ["all"],
      make_clean: ["clean"],
      make_force_build: Application.get_env(:exqlite, :force_build, false),
      make_precompiler: make_precompiler(),
      make_precompiler_url:
        "https://github.com/ebifriedrice/exqlite/releases/download/v#{@version}/@{artefact_filename}",
      make_precompiler_filename: "sqlite3_nif",
      make_precompiler_nif_versions: make_precompiler_nif_versions(),
      make_env: Application.get_env(:exqlite, :make_env, %{}),
      cc_precompiler: cc_precompiler(),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps(),
      package: package(),
      description: description(),
      test_paths: test_paths(System.get_env("EXQLITE_INTEGRATION")),
      elixirc_paths: elixirc_paths(Mix.env()),
      dialyzer: dialyzer(),

      # Docs
      name: "Exqlite",
      source_url: "https://github.com/ebifriedrice/exqlite",
      homepage_url: "https://github.com/ebifriedrice/exqlite",
      docs: docs()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger]
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:db_connection, "~> 2.1"},
      {:ex_sqlean, "~> 0.8.5", only: [:dev, :test]},
      {:elixir_make, "~> 0.8", runtime: false},
      {:cc_precompiler, "~> 0.1", runtime: false},
      {:ex_doc, "~> 0.27", only: :dev, runtime: false},
      {:temp, "~> 0.4", only: [:dev, :test]},
      {:credo, "~> 1.6", only: [:dev, :test], runtime: false},
      {:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},
      {:table, "~> 0.1.0", optional: true}
    ]
  end

  defp aliases do
    [
      lint: ["format --check-formatted", "credo --all", "dialyzer"]
    ]
  end

  defp description do
    "An Elixir SQLite3 library. Fork of exqlite adding preupdate and commit hooks."
  end

  defp make_precompiler do
    if System.get_env("EXQLITE_USE_SYSTEM") != nil do
      nil
    else
      {:nif, CCPrecompiler}
    end
  end

  defp package do
    [
      files: ~w(
        lib
        .formatter.exs
        mix.exs
        README.md
        LICENSE
        .clang-format
        c_src
        Makefile*
        checksum.exs
      ),
      # The Hex package name deliberately differs from the app name: this is
      # a fork of exqlite published under its own name. Keeping the app as
      # :exqlite (and the Exqlite.* modules) makes the dependency swap
      # drop-in, and precompiled artifact names derive from the app name, so
      # they are unaffected.
      name: "sqlite_drv",
      licenses: ["MIT"],
      links: %{
        "GitHub" => "https://github.com/ebifriedrice/exqlite",
        "Changelog" => "https://github.com/ebifriedrice/exqlite/blob/main/CHANGELOG.md"
      }
    ]
  end

  defp docs do
    [
      main: "readme",
      extras: docs_extras(),
      source_ref: "v#{@version}",
      source_url: "https://github.com/ebifriedrice/exqlite"
    ]
  end

  defp docs_extras do
    [
      "README.md": [title: "Readme"],
      "guides/windows.md": [],
      "C_TESTING.md": [title: "Checking the C NIF"],
      "CHANGELOG.md": []
    ]
  end

  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  defp test_paths(nil), do: ["test"]
  defp test_paths(_any), do: ["integration_test/exqlite"]

  defp dialyzer do
    [
      plt_add_deps: :apps_direct,
      plt_add_apps: ~w(table)a
    ]
  end

  def make_precompiler_nif_versions do
    [
      versions: ["2.17"]
    ]
  end

  defp cc_precompiler do
    [
      cleanup: "clean",
      only_listed_targets:
        System.get_env("CC_PRECOMPILER_ONLY_LISTED_TARGETS") == "true",
      compilers: %{
        {:unix, :linux} => %{
          :include_default_ones => true,
          "x86_64-linux-musl" => "x86_64-linux-musl-",
          "aarch64-linux-musl" => "aarch64-linux-musl-",
          "riscv64-linux-musl" => "riscv64-linux-musl-",
          "aarch64-linux-android" => android_compilers("aarch64-linux-android"),
          "armv7a-linux-androideabi" => android_compilers("armv7a-linux-androideabi")
        },
        {:unix, :darwin} => %{
          # x86_64-apple-darwin is deliberately not listed: Intel macs
          # compile from source. Keeping :include_default_ones out entirely
          # matters — cc_precompiler expands that key back to the default
          # darwin triples when fetching checksums, which would require an
          # Intel artifact that no job builds.
          "aarch64-apple-darwin" =>
            {"gcc", "g++", "<%= cc %> -arch arm64", "<%= cxx %> -arch arm64"}
        },
        {:win32, :nt} => %{
          :include_default_ones => true
        }
      }
    ]
  end

  defp android_compilers(target) do
    api_level = System.get_env("ANDROID_API_LEVEL", "24")

    {
      "#{target}#{api_level}-clang",
      "#{target}#{api_level}-clang++"
    }
  end
end