Skip to content

Support for fully custom :load_from for escripts #556

@technusm1

Description

@technusm1

Hi, I'm trying to use a single rust function inside my elixir app. I followed the setup instructions according to mix rustler.new and successfully got it working under iex. Unfortunately, I was getting an error when doing the same for escript.build, which is when I found out that rustler uses priv directory which is not accessible to escripts. Luckily, I came across the load_from configuration option and tried it in my module like this:

use Rustler, otp_app: :fizzbuzz, crate: "fizzbuzz", load_from: {:fizzbuzz, "/Users/maheep/Downloads/native/libfizzbuzz"}

Unfortunately, all it does is append the path to Application.app_dir output. Here's the problematic line in rustler.ex:

load_path =
          otp_app
          |> Application.app_dir(path)
          |> to_charlist()

which I changed to:

load_path =
          path
          |> to_charlist()

Doing this change allows me to specify fully custom load_from paths and gets things working for me.

MY QUESTION: Is load_from the correct option to use in my case? If so, do I have any other alternative (I don't think its a good idea to mess with a dependency's code).

MY OS: macOS 13.4.1 Ventura

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions