Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meeseeks (and Rustler) doesn't work with escript.build #23

Closed
Eiji7 opened this issue Aug 18, 2017 · 9 comments
Closed

Meeseeks (and Rustler) doesn't work with escript.build #23

Eiji7 opened this issue Aug 18, 2017 · 9 comments

Comments

@Eiji7
Copy link

Eiji7 commented Aug 18, 2017

Hey, I just called &Meeseeks.all/2 function with css like:

import Meeseeks.CSS
Meeseeks.all("html code", css("css selector"))

but I got:

{%Protocol.UndefinedError{description: "", protocol: String.Chars,
  value: {:error, :bad_name}},
 [{String.Chars, :impl_for!, 1,
   [file: '/home/ubuntu/bob/tmp/3251921048f5d8e3ff92bd4156013d87/elixir/lib/elixir/lib/string/chars.ex',
    line: 3]},
  {String.Chars, :to_string, 1,
   [file: '/home/ubuntu/bob/tmp/3251921048f5d8e3ff92bd4156013d87/elixir/lib/elixir/lib/string/chars.ex',
    line: 22]},
  {Rustler, :compile_config, 2, [file: 'lib/rustler.ex', line: 74]},
  {MeeseeksHtml5ever.Native, :__init__, 0,
   [file: 'lib/meeseeks_html5ever/native.ex', line: 4]},
  {:code_server, :"-handle_on_load/5-fun-0-", 1,
   [file: 'code_server.erl', line: 1333]}]}

My dependencies:

* rustler 0.10.1 (Hex package) (mix)
  locked at 0.10.1 (rustler) cedcce8b
  ok
* meeseeks_html5ever 0.6.1 (Hex package) (mix)
  locked at 0.6.1 (meeseeks_html5ever) 3d7f3c4b
  ok
* meeseeks 0.7.2 (Hex package) (mix)
  locked at 0.7.2 (meeseeks) 6410eda0
  ok

Erlang: 20.0
Elixir: 1.5.1-otp-20
Rust: stable - rustc 1.19.0 (0ade33941 2017-07-17)
All installed using asdf.
Let me know if you need more info about my input data.
Edit: I got exactly same error when I changed all to one function name.

@mischov
Copy link
Owner

mischov commented Aug 18, 2017

If you could provide more info about the input that caused that it would be great.

@Eiji7
Copy link
Author

Eiji7 commented Aug 18, 2017

I fetched HTML code of this page: http://www.onepiece.wbijam.pl/pierwsza_seria.html
and tried to load links using selector table.lista a

@mischov
Copy link
Owner

mischov commented Aug 18, 2017

html = """ 
<The Page Source> 
""""
d = Meeseeks.parse(html)
Meeseeks.all(d, css("table.lista a"))

Returns a list of results for me.

Can you try running Meeseeks.parse on the HTML and seeing if it works?

@mischov
Copy link
Owner

mischov commented Aug 18, 2017

The Rustler line referenced in the error is: https://github.com/hansihe/rustler/blob/master/rustler_mix/lib/rustler.ex#L74

Is there any reason that that line would cause a problem for you?

@Eiji7
Copy link
Author

Eiji7 commented Aug 18, 2017

I found a problem. It works in iex, but not when compiled using mix escript.build.

defmodule Sample do
  import Meeseeks.CSS

  def main([main_url]) do
    Meeseeks.parse HTTPoison.get!(main_url).body
    # minified version - works in iex
  end
end

and here is mix.exs:

defmodule Sample.Mixfile do
  use Mix.Project

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

  def project, do: [
    app: :sample,
    deps: [
      {:httpoison, "~> 0.13"},
      {:meeseeks, "~> 0.7.2"}
    ],
    elixir: "~> 1.5",
    escript: [main_module: Sample],
    start_permanent: Mix.env == :prod,
    version: "0.1.0",
  ]
end
# also minified

rest is as same as after calling: mix new sample.

@mischov
Copy link
Owner

mischov commented Aug 18, 2017

It looks like that problem might result from a combination of escript.build and Rustler.

The escript.build docs notes the following:

Note: escripts do not support projects and dependencies that need to store or read artifacts from the priv directory.

And the line I linked to above from Rustler, the one in the error, reads

priv_dir = otp_app |> :code.priv_dir() |> to_string()

@Eiji7
Copy link
Author

Eiji7 commented Aug 18, 2017

@mischov: oh, is there any other way to compile my project to binary file that could work with rustler?

@Eiji7 Eiji7 changed the title Protocol.UndefinedError when calling Meeseeks.all function Protocol.UndefinedError after compiling rustler Aug 18, 2017
@Eiji7 Eiji7 changed the title Protocol.UndefinedError after compiling rustler Protocol.UndefinedError after compiling rustler with task escript.build Aug 18, 2017
@mischov
Copy link
Owner

mischov commented Aug 18, 2017

Well, escripts don't work with NIFs (source), so not in a way that involves an escript.

@mischov mischov changed the title Protocol.UndefinedError after compiling rustler with task escript.build Meeseeks (and Rustler) don't work with escript.build Aug 18, 2017
@mischov
Copy link
Owner

mischov commented Aug 18, 2017

I don't really know what your use case and restrictions are, but your best bet is probably to make an Erlang/OTP release with something like Distillery.

I am going to close this issue, but feel free to continue commenting if you have more questions or if you want to describe your eventual solution.

@mischov mischov closed this as completed Aug 18, 2017
@mischov mischov changed the title Meeseeks (and Rustler) don't work with escript.build Meeseeks (and Rustler) doesn't work with escript.build Aug 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants