philss / rustler_precompiled

Use precompiled NIFs from trusted sources in your Elixir code
181 stars 25 forks source link

Cannot use the released nif version #67

Closed lud-wj closed 3 months ago

lud-wj commented 6 months ago

EDIT Sorry this seems to be fixed already. I did not check the version used by meeseeks. I'l let this open in case there was a slight difference in the problem, but close at will :)

Hello,

I'm trying to use an Elixir library (meeseeks_html5ever) that only publishes nif-2.15 releases.

But my nif version is 2.17, and rustler precompiled

  use RustlerPrecompiled,
    nif_versions: ~w(2.15),

But then I have this error:

** (RuntimeError) precompiled NIF is not available for this NIF version: "2.16".
The available NIF versions are:
 - 2.15

So I dug and found the following code:

   def find_compatible_nif_version(vsn, available) do
    if vsn in available do
      {:ok, vsn}
    else
      [major, minor | _] = parse_version(vsn)

      available
      |> Enum.map(&parse_version/1)
      |> Enum.filter(fn
        [^major, available_minor | _] when available_minor <= minor -> true
        [_ | _] -> false
      end)
      |> case do
        [] -> :error
        match -> {:ok, match |> Enum.max() |> Enum.join(".")}
      end
    end
  end

So this will select "2.16" only, although I configured my versions to ["2.15"].

The problem is that target_config/0 will pass the hardcoded list of all available versions in find_compatible_nif_version(current_nif_version, Config.available_nif_versions()), instead of reducing that list to what I configured.

A very simple fix would be to call case target(target_config(config.nif_versions), config.targets, config.nif_versions) do,

With this signatures: defp target_config(available_nif_versions \\ Config.available_nif_versions()) do

And in there, that call: find_compatible_nif_version(current_nif_version, available_nif_versions)

So I can make a PR but is there a reason not to make this change?

Thank you.

philss commented 3 months ago

Hey, sorry for the delay. Thanks for the details. And yeah, this should be fixed as we are more flexible now. If the NIF is compiled to 2.15, it should work fine for versions above this.