Packages

An Alternera pipeline step that runs Lua 5.4 compiled to WebAssembly, on the WebAssembly framework.

Current section

Files

Jump to

mix.exs

defmodule AlterneraPluginLua54.MixProject do
  use Mix.Project

  @version "0.9.0"
  @source_url "https://github.com/10e-ab/alternera-wasm"

  def project do
    [
      app: :alternera_plugin_lua54,
      version: @version,
      description:
        "An Alternera pipeline step that runs Lua 5.4 compiled to WebAssembly, on the WebAssembly framework.",
      package: package(),
      docs: docs(),
      source_url: @source_url,
      elixir: "~> 1.19",
      # The LiveView compiler writes the editor's colocated hook, the Lua
      # colouring (`_build/<env>/phoenix-colocated/alternera_plugin_lua54/`),
      # which the proxy's `mix alternera.plugin_assets` imports into its bundle.
      compilers: [:phoenix_live_view] ++ Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # The application compiles the Lua 5.4 module when the package starts, so
  # the first step does not wait for it.
  def application do
    [
      mod: {Alternera.Plugins.Lua54.Application, []},
      extra_applications: [:logger]
    ]
  end

  defp deps do
    [
      sdk(:alternera_plugin_sdk),
      sdk(:alternera_plugin_editor),
      # The WebAssembly runtime, the step and its editor this plugin runs.
      sibling(:alternera_plugin_wasm_framework),
      {:ex_doc, "~> 0.34", only: :dev, runtime: false}
    ]
  end

  defp package do
    [
      licenses: ["Apache-2.0"],
      links: %{"GitHub" => @source_url, "Alternera" => "https://github.com/10e-ab/alternera"},
      files: ~w(lib priv docs mix.exs README.md LICENSE NOTICE)
    ]
  end

  defp docs do
    [
      main: "readme",
      extras: ["README.md"],
      source_ref: "v#{@version}",
      source_url_pattern:
        "#{@source_url}/blob/v#{@version}/alternera_plugin_lua54/%{path}#L%{line}"
    ]
  end

  # A sibling package of this repository: by path here, so the packages
  # change together, and by version in the published package, which a Hex
  # package must be (`ALTERNERA_WASM_PUBLISH=1 mix hex.publish`).
  defp sibling(app) do
    case System.get_env("ALTERNERA_WASM_PUBLISH") do
      unset when unset in [nil, ""] -> {app, path: "../#{app}"}
      _publish -> {app, "~> " <> @version}
    end
  end

  # The SDK's packages from Hex (their source is github.com/10e-ab/alternera-sdk),
  # or from a checkout of that repository when ALTERNERA_SDK_PATH names one,
  # while a contract and this code change together. Overridden only from a
  # checkout, where the SDK's packages name each other by path (a Hex package
  # cannot override).
  defp sdk(app) do
    case System.get_env("ALTERNERA_SDK_PATH") do
      unset when unset in [nil, ""] ->
        {app, "~> 0.9.0"}

      checkout ->
        # Absolute only: Mix evaluates a package's mix.exs from that package's
        # directory, where a relative path names somewhere else.
        if Path.type(checkout) != :absolute,
          do: Mix.raise("ALTERNERA_SDK_PATH must be an absolute path, got: #{checkout}")

        {app, path: Path.join(checkout, Atom.to_string(app)), override: true}
    end
  end
end