ExWeb3 / ex_keccak

Elixir library for computing Keccak SHA3-256 hashes using a NIF built tiny-keccak Rust crate.
Apache License 2.0
25 stars 20 forks source link

Can't use library for arm architecture #27

Closed JulesGuesnon closed 2 years ago

JulesGuesnon commented 2 years ago

Hello!

I'm using a library that is using this library, and when I run the code I get this error:

[warning] The on_load function for module Elixir.ExKeccak returned:
{:error,
 {:load_failed,
  'Failed to load NIF library: \'dlopen(/Users/julesguesnon/Dev/Tinybones/tinybones-game-server/_build/dev/lib/ex_keccak/priv/native/libexkeccak.so, 0x0002): tried: \'/Users/julesguesnon/Dev/Tinybones/tinybones-game-server/_build/dev/lib/ex_keccak/priv/native/libexkeccak.so\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\')), \'/usr/local/lib/libexkeccak.so\' (no such file), \'/usr/lib/libexkeccak.so\' (no such file), \'/Users/julesguesnon/Dev/Tinybones/tinybones-game-server/deps/ex_keccak/priv/native/libexkeccak.so\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\')), \'/usr/local/lib/libexkeccak.so\' (no such file), \'/usr/lib/libexkeccak.so\' (no such file)\''}}

And IMO the most important part is this one: (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64e\')). It's probably happening because I'm running the code on the Mac M1.

Would it be possible to ship an arm compatible version as well?

JulesGuesnon commented 2 years ago

Actually I tried creating a new rustler nif from scratch and I got the same error, so I'll open an issue on the rustler repo and make a PR if something needs to be updated later

tzumby commented 2 years ago

Hey @JulesGuesnon, my guess is that we probably need another entry similar to this one here for arm ?

https://github.com/tzumby/ex_keccak/blob/master/native/exkeccak/.cargo/config

joshuataylor commented 2 years ago

aarch64 is arm64, it's just another name for it (The naming scheme is confusion, ARM64, ARM64e, AARCH64, Apple Silicon..)

You could also add the following for all Macs:

[target.'cfg(target_os = "macos")']
tzumby commented 2 years ago

that's right, i keep forgetting the m1 is arm. in that case this is odd, i can definitely compile this on my m1.

JulesGuesnon commented 2 years ago

As mentioned in this issue, my toolchain was an x86_64 one, so I changed it to aarch64 and now it's good, thanks for your help!