gleam icon indicating copy to clipboard operation
gleam copied to clipboard

problem with nif erlang package

Open massivefermion opened this issue 2 years ago • 5 comments

A few days ago I decided to write a gleam package for password hashing and I decided on the argon2 algorithm. First, I had to publish an argon2 package for erlang because there wasn't any, so I published argon2. It's a bunch of nifs using the argon2 crate. It works if you use it in your erlang code and also in rebar3 shell

But then I tried to use in a gleam project and it didn't work at all. Some of the functions are not even there(if you type argon2: in gleam shell and press tab, only two of the functions are shown) and the two that are, just freeze and never return. I also opened a rebar3 shell inside build/packages/argon2 and again, there was nothing wrong!

Is it too soon to use nifs for gleam?

massivefermion avatar Mar 05 '22 06:03 massivefermion

Hello! Thanks for the report. No work has been done in to NIFs with Gleam so there may be something we need to do here.

What version of Gleam and Erlang are you using? Does the same package work if you add it as a dependency to a rebar3 project? Are there any errors during compilation?

lpil avatar Mar 06 '22 14:03 lpil

erlang 24.2.1 gleam 0.20.1 yes, it works in a rebar3 project no, it compiles fine, not even a warning! but then it just doesn't work

massivefermion avatar Mar 06 '22 15:03 massivefermion

Fab, thank you.

My theory now is that there's some build directory we need to copy.

lpil avatar Mar 06 '22 15:03 lpil

I'm really sorry, I forgot to mention. That is true. You need to copy the priv directory(that has the argon2.so file in it) to build/dev/erlang/argon2. It already is present inside build/packages/argon2 and if you run gleam publish, it also correctly appears in build/prod/erlang/argon2. But that appears to be just part of the problem because when I manually did it, the original problem was not solved!

massivefermion avatar Mar 06 '22 23:03 massivefermion

Oh dear, I thought we did do that! We'll have no investigate more.

lpil avatar Mar 07 '22 08:03 lpil

I've been unable to reproduce this with current Gleam so I guess we fixed it when working on another bug 👍

lpil avatar Jan 14 '23 18:01 lpil