编译 Elixir NIF 时出现错误 `unknown application: :nif_bartender`

问题描述 投票:0回答:1

我正在为 Elixir 绑定到 rustrict ,但是当为 FreeBSD 编译它时(Elixir 1.14.4,OTP 25,我使用的是 serv00 中的服务器),它给了我这个错误:

[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"

这是来自 hex.pm 的 0.1.2 版本,我似乎找不到它是什么。在克隆实际存储库时,我可以完美地运行

mix test
,我什至可以制作一个仅运行审查功能的测试应用程序。它只发生在这个应用程序中。

(调酒师)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

(调酒师)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

(应用程序)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

可以在每个应用程序的 GitHub 页面上找到任何其他代码: https://github.com/stalepretzels/bartender https://github.com/stalepretzels/arcs-backend

如有任何帮助,我们将不胜感激,谢谢!

rust elixir
1个回答
0
投票

关闭。在 Bartender 库的 mix.exs 中使用 Mixfile 而不是最新的 MixProject。更新了它和 lib/bartender.ex 以使用

use Rustler, otp_app: :bartender
而不是
use Rustler, otp_app: :nif_bartender, crate: :bartender
,现在可以使用了。

© www.soinside.com 2019 - 2024. All rights reserved.