【问题标题】:How to use a closed-source Erlang library in an Elixir project?如何在 Elixir 项目中使用闭源 Erlang 库?
【发布时间】:2016-03-10 12:36:58
【问题描述】:

我有一个闭源 Erlang 库,我想在我的 Elixir 项目中使用。该库具有以下目录结构:

  • ebin
    • 包含 1 个 .app 和各种 .beam 文件
  • 隐私
    • 包含此库中已用 C 实现的部分的共享对象文件

从我的 Elixir 项目中使用这个库的推荐方法是什么?

【问题讨论】:

    标签: elixir


    【解决方案1】:

    实现封闭源代码 OTP 依赖的方法可能不止一种,但这里推荐一种应该可行的方法。

    这是一个 git 存储库中的示例关闭依赖项(仅存在 rebar.configebin 文件夹):https://github.com/potatosalad/erlang-closed-example/tree/closed(项目源 is on the master branch)。

    如果您要托管来自 ebinpriv 的封闭源文件并将 rebar.config 文件添加到您自己的 git 存储库,则以下内容应该相同。此外,请确保您的 git 存储库托管在私有的某个地方(除非项目的许可证另有说明)。

    您应该能够将封闭源代码库作为依赖项添加到您的 mix.exs 文件中:

    defmodule Example.Mixfile do
      use Mix.Project
    
      def project do
        [app: :example,
         version: "0.0.1",
         elixir: "~> 1.1",
         build_embedded: Mix.env == :prod,
         start_permanent: Mix.env == :prod,
         deps: deps]
      end
    
      def application do
        [applications: [:logger, :closed]]
      end
    
      defp deps do
        [{:closed, git: "https://github.com/potatosalad/erlang-closed-example.git", branch: "closed"}]
      end
    end
    

    这里有一个完整的示例项目:https://github.com/potatosalad/mix-closed-example

    运行mix deps.get 后,我可以在iex -S mix shell 中执行以下操作:

    iex> :closed.secret()
    "this is a closed source library"
    

    priv 下的共享对象文件也应该可以工作,但取决于操作系统和可用的库版本。

    【讨论】:

    • 感谢您的详细而有帮助的回答。你的方法很好用。
    猜你喜欢
    • 2018-11-26
    • 2016-03-05
    • 2015-12-09
    • 2016-07-19
    • 2014-03-31
    • 1970-01-01
    • 2015-12-16
    • 2016-05-18
    • 2013-11-15
    相关资源
    最近更新 更多