beaver-lodge / beaver

MLIR Toolkit in Elixir and Zig.
MIT License
160 stars 7 forks source link

Integrate beaver in a simple CLI yields error #199

Closed glyh closed 1 year ago

glyh commented 1 year ago

Here's the mix.exs:

defmodule Boltex.MixProject do
  use Mix.Project

  def project do
    [
      app: :boltex,
      version: "0.1.0",
      elixir: "~> 1.14",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      escript: [main_module: Boltex.CLI],
    ]
  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
    [
      {:beaver, "~> 0.2"},
    ]
  end
end

And here is the main module I added:

defmodule Boltex.CLI do
  def main(args) do 
    IO.puts "Hello"
  end
end

The program will succeed in creation if I run mixescript.build, but when I run the app I get a bunch of errors:


19:58:03.877 [notice] Application beaver exited: bad return value: {{Beaver.Application, :start_phase, [:mlir_register_all_passes, :normal, []]}, {:EXIT, {:undef, [{Beaver.MLIR.CAPI, :mlirRegisterAllPasses, [], []}, {Beaver.Application, :start_phase, 3, [file: 'lib/beaver/application.ex', line: 13]}, {:application_starter, :run_the_phase, 4, [file: 'application_starter.erl', line: 99]}, {:application_starter, :start_apps, 3, [file: 'application_starter.erl', line: 59]}, {:application_starter, :start, 3, [file: 'application_starter.erl', line: 45]}, {:application_master, :start_the_app, 5, [file: 'application_master.erl', line: 332]}, {:application_master, :start_it_new, 7, [file: 'application_master.erl', line: 315]}]}}}

19:58:03.877 [warning] The on_load function for module Elixir.Beaver.MLIR.CAPI returned:
{%ArgumentError{message: "unknown application: :beaver"},
 [
   {Application, :app_dir, 1, [file: 'lib/application.ex', line: 954]},
   {Application, :app_dir, 2, [file: 'lib/application.ex', line: 981]},
   {Beaver.MLIR.CAPI, :load_rustler_precompiled, 0,
    [file: 'lib/beaver/mlir/capi.ex', ...]},
   {:code_server, :"-handle_on_load/5-fun-0-", 1, [...]}
 ]}

19:58:03.875 [error] Process #PID<0.140.0> raised an exception
** (ArgumentError) unknown application: :beaver
    (elixir 1.14.0) lib/application.ex:954: Application.app_dir/1
    (elixir 1.14.0) lib/application.ex:981: Application.app_dir/2
    (beaver 0.2.19) lib/beaver/mlir/capi.ex:21: Beaver.MLIR.CAPI.load_rustler_precompiled/0
    (kernel 8.5.4) code_server.erl:1317: anonymous fn/1 in :code_server.handle_on_load/5

19:58:03.924 [notice] Application kinda exited: :stopped

19:58:03.924 [notice] Application zig_parser exited: :stopped

19:58:03.925 [notice] Application rustler_precompiled exited: :stopped

19:58:03.925 [notice] Application castore exited: :stopped

19:58:03.927 [notice] Application ssl exited: :stopped

19:58:03.927 [notice] Application public_key exited: :stopped

19:58:03.927 [notice] Application asn1 exited: :stopped

19:58:03.928 [notice] Application inets exited: :stopped

19:58:03.928 [notice] Application crypto exited: :stopped

19:58:03.928 [notice] Application llvm_config exited: :stopped
ERROR! Could not start application beaver: bad return value: {{Beaver.Application, :start_phase, [:mlir_register_all_passes, :normal, []]}, {:EXIT, {:undef, [{Beaver.MLIR.CAPI, :mlirRegisterAllPasses, [], []}, {Beaver.Application, :start_phase, 3, [file: 'lib/beaver/application.ex', line: 13]}, {:application_starter, :run_the_phase, 4, [file: 'application_starter.erl', line: 99]}, {:application_starter, :start_apps, 3, [file: 'application_starter.erl', line: 59]}, {:application_starter, :start, 3, [file: 'application_starter.erl', line: 45]}, {:application_master, :start_the_app, 5, [file: 'application_master.erl', line: 332]}, {:application_master, :start_it_new, 7, [file: 'application_master.erl', line: 315]}]}}}
jackalcooper commented 1 year ago

ive never used escript before. Are there requirements on how apps should be started under escript?

glyh commented 1 year ago

I'm new to Elixir so sorry I don't know about that...

jackalcooper commented 1 year ago

later i will run it with escript to see what is happening

jackalcooper commented 1 year ago

BYW, it is not recommended to use escript for CLI in most of cases

For running live systems, consider using mix run or building releases. See the Application module for more information on systems life-cycles.

jackalcooper commented 1 year ago

resolved by running with an system env, ERL_LIBS=_build/dev/lib [your Escript executable]

Check out the "The ability to use external modules" section of this blog http://davekuhlman.org/elixir-escript-mix.html#toc-entry-4

jackalcooper commented 1 year ago

Again it is not recommended to use escript because it is not a "real" executable like what C++/Rust produced.

glyh commented 1 year ago

Thank you.