Error `unknown application: :nif_bartender` when compiling Elixir NIF

23 Views Asked by At

I am making bindings to rustrict for Elixir, but when compiling it for FreeBSD (Elixir 1.14.4, OTP 25, I'm using a server from serv00,) it gives me this error:

[LOGIN@s1]:<~/domains/LOGIN.serv00.net/backend>$ linker=gcc mix compile
==> nif_bartender
Compiling 1 file (.ex)

== Compilation error in file lib/bartender.ex ==
** (ArgumentError) unknown application: :nif_bartender
    (elixir 1.14.4) lib/application.ex:954: Application.app_dir/1
    (elixir 1.14.4) lib/application.ex:981: Application.app_dir/2
    (rustler 0.23.0) lib/rustler/compiler/config.ex:48: Rustler.Compiler.Config.from/3
    (rustler 0.23.0) lib/rustler/compiler.ex:9: Rustler.Compiler.compile_crate/2
    lib/bartender.ex:2: (module)
could not compile dependency :bartender, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile bartender", update it with "mix deps.update bartender" or clean it with "mix deps.clean bartender"

This is version 0.1.2 from hex.pm, and I cant seem to find what it is. I can run mix test perfectly fine when cloning the actual repository, and I can even make a test application that just runs the censor function. It only happens in this app.

(Bartender) mix.exs:

defmodule Bartender.Mixfile do
    use Mix.Project

    def project do
      [
        app: :nif_bartender,
        version: "0.1.2",
        elixir: "~> 1.11",
        start_permanent: Mix.env() == :prod,
        deps: deps(),
        description: description(),
      package: package(),
        aliases: aliases()
      ]
    end

    def application do
      [
        extra_applications: [:logger]
      ]
    end

    defp deps do
      [
        {:rustler, "~> 0.23.0"},
        {:rustler_precompiled, "~> 0.7"},
        {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
      ]
    end

    defp description() do
    "Elixir bindings for the rustrict crate."
  end

  defp package() do
    [
      name: "bartender_filter",
      licenses: ["MIT"],
      files: [
      "lib",
      "native/bartender/.cargo",
      "native/bartender/src",
      "native/bartender/Cargo*",
      "mix.exs"
    ],
      links: %{"GitHub" => "https://github.com/stalepretzels/bartender"}
    ]
  end

    defp aliases do
      [
        fmt: [
          "format",
          "cmd cargo fmt --manifest-path native/bartender/Cargo.toml"
        ]
      ]
    end
  end

(Bartender) lib/bartender.ex:

defmodule Bartender do
    use Rustler, otp_app: :bartender, crate: :bartender
  
    def censor(_input), do: error()
    def is_inappropriate(_input), do: error()
    def is(_input, _filter_input), do: error()
    def isnt(_input, _filter_input), do: error()
  
    defp error, do: :erlang.nif_error(:nif_not_loaded)
end

(App) mix.exs:

defmodule Arcs.MixProject do
  use Mix.Project

  def project do
    [
      app: :arcs,
      version: "3.0.0",
      elixir: "~> 1.14",
      elixirc_paths: elixirc_paths(Mix.env()),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps(),
      test_coverage: [tool: ExCoveralls],
      preferred_cli_env: [
        c: :test,
        coveralls: :test,
        "coveralls.detail": :test,
        "coveralls.json": :test,
        "coveralls.post": :test,
        "coveralls.html": :test,
        t: :test
      ]
    ]
  end

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [
      mod: {Arcs.Application, []},
      extra_applications: [:logger, :runtime_tools, :os_mon]
    ]
  end

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.7.0-rc.2", override: true},
      {:phoenix_ecto, "~> 4.4"},
      {:bartender, "~> 0.1.1", hex: :bartender_filter},
      {:ecto_sql, "~> 3.6"},
      {:phoenix_live_dashboard, "~> 0.7"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 4.0"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:earmark, "~> 1.4"},
      {:phoenix_live_view, "~> 0.20.0"},
      {:heroicons, "~> 0.5"},
      {:floki, ">= 0.30.0", only: :test},
      {:esbuild, "~> 0.5", runtime: Mix.env() == :dev},
      {:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
      {:telemetry_metrics, "~> 0.6"},
      {:telemetry_poller, "~> 1.0"},
      {:jason, "~> 1.2"},
      {:plug_cowboy, "~> 2.5"},

      # Testing
      # tracking test coverage
      {:excoveralls, "~> 0.18.0", only: [:test, :dev]},
      {:auth_plug, "~> 1.5"}
    ]
  end

  # Aliases are shortcuts or tasks specific to the current project.
  # For example, to install project dependencies and perform other setup tasks, run:
  #
  #     $ mix setup
  #
  # See the documentation for `Mix` for more info on aliases.
  defp aliases do
    [
      setup: ["deps.get", "ecto.setup", "assets.setup"],
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
      "assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"],
      "assets.deploy": ["tailwind default --minify", "esbuild default --minify", "phx.digest"],
      c: ["coveralls.html"],
      s: ["phx.server"],
      t: ["test"]
    ]
  end
end

Any other code can be found on the GitHub page for each respective application: https://github.com/stalepretzels/bartender https://github.com/stalepretzels/arcs-backend

Any help would be appreciated, thanks!

1

There are 1 best solutions below

0
Clover Johnson On BEST ANSWER

Closed. Was using Mixfile instead of the more recent MixProject in my mix.exs in the Bartender library. Updated that and the lib/bartender.ex to use use Rustler, otp_app: :bartender instead of use Rustler, otp_app: :nif_bartender, crate: :bartender and it's working now.