ankane / argon2-kdf

Argon2 key derivation for Ruby
MIT License
8 stars 2 forks source link

Apple M1 Chip Compatibility #3

Closed HamptonMakes closed 3 years ago

HamptonMakes commented 3 years ago

Hi @ankane ! Thank you for your awesome work on this project (blind_index is amazing!)

Currently, this repo only bundles the Mac x86 version of the dylib for argon instead of including an arm64 build. This means when run on a new Mac computer, the following happens:

Fiddle::DLError:
   dlopen(/Users/hcatlin/.rvm/gems/ruby-2.7.2/gems/argon2-kdf-0.1.3/vendor/libargon2.dylib, 9): no suitable image found.  Did find:
        /Users/hcatlin/.rvm/gems/ruby-2.7.2/gems/argon2-kdf-0.1.3/vendor/libargon2.dylib: mach-o, but wrong architecture
        /Users/hcatlin/.rvm/gems/ruby-2.7.2/gems/argon2-kdf-0.1.3/vendor/libargon2.dylib: mach-o, but wrong architecture
ankane commented 3 years ago

Hey @hcatlin, thanks for reporting. I tried adding support on master, but don't have an M1 to test. Can you follow the instructions here and try running the tests with and without Rosetta 2? (want to make sure it works with both)

ankane commented 3 years ago

Sorry for the noise. Moved it to a branch for now. The mac-arm64 branch includes a separate shared library for arm64 and the mac-universal branch includes a universal shared library that should work for both (not sure which approach to take yet). You can test them both with:

git clone https://github.com/ankane/argon2-kdf.git
cd argon2-kdf
bundle install

git checkout mac-arm64
bundle exec rake vendor:mac
bundle exec rake test

git checkout mac-universal
bundle exec rake vendor:mac
bundle exec rake test
HamptonMakes commented 3 years ago

Both were fabulous runs!


hcatlin@Hamptons-MacBook-Air argon2-kdf % git checkout mac-arm64
Branch 'mac-arm64' set up to track remote branch 'mac-arm64' from 'origin'.
Switched to a new branch 'mac-arm64'
hcatlin@Hamptons-MacBook-Air argon2-kdf % bundle exec rake vendor:mac
Downloading libargon2.dylib...
Saved vendor/libargon2.dylib
Downloading libargon2.arm64.dylib...
Saved vendor/libargon2.arm64.dylib
hcatlin@Hamptons-MacBook-Air argon2-kdf % bundle exec rake test
Run options: --seed 39033

# Running:

.........

Fabulous run in 0.584312s, 15.4027 runs/s, 23.9598 assertions/s.

9 runs, 14 assertions, 0 failures, 0 errors, 0 skips
hcatlin@Hamptons-MacBook-Air argon2-kdf % git checkout mac-universal
Branch 'mac-universal' set up to track remote branch 'mac-universal' from 'origin'.
Switched to a new branch 'mac-universal'
hcatlin@Hamptons-MacBook-Air argon2-kdf % bundle exec rake vendor:mac
bundle exec rake test
Downloading libargon2.universal.dylib...
Saved vendor/libargon2.universal.dylib
Run options: --seed 21

# Running:

.........

Fabulous run in 0.540578s, 16.6488 runs/s, 25.8982 assertions/s.

9 runs, 14 assertions, 0 failures, 0 errors, 0 skips```
HamptonMakes commented 3 years ago

Oh, and I ran the universal build in Rosetta 2.


Downloading libargon2.universal.dylib...
Saved vendor/libargon2.universal.dylib
>% arch -x86_64 rake test      
Run options: --seed 29031

# Running:

.........

Fabulous run in 0.524818s, 17.1488 runs/s, 26.6759 assertions/s.

9 runs, 14 assertions, 0 failures, 0 errors, 0 skips```
ankane commented 3 years ago

Great, thanks @hcatlin! Can you try running the mac-arm64 branch with Rosetta 2? Also, can you share the output of the following with and without Rosetta 2?

ruby -e "puts RbConfig::CONFIG['arch']"

(trying to understand how it affects Ruby, if at all)

HamptonMakes commented 3 years ago
Your branch is up to date with 'origin/mac-arm64'.
>% rake vendor:mac
Downloading libargon2.dylib...
Saved vendor/libargon2.dylib
Downloading libargon2.arm64.dylib...
Saved vendor/libargon2.arm64.dylib
>% arch -x86_64 rake test  
Run options: --seed 33246

# Running:

.........

Fabulous run in 0.595237s, 15.1200 runs/s, 23.5200 assertions/s.

9 runs, 14 assertions, 0 failures, 0 errors, 0 skips

And then, on the arch tests for Ruby... my ruby is compiled for arm64, so here is showing the rosetta and non-rosetta runs, plus your requested outputs

>% arch -x86_64 ruby -e "puts RbConfig::CONFIG['arch']"
arch: posix_spawnp: ruby: Bad CPU type in executable
>% ruby -e "puts RbConfig::CONFIG['arch']"
arm64-darwin20
ankane commented 3 years ago

Great, thanks again @hcatlin. Just pushed a new release. Decided to go with separate shared libraries for now (instead of universal), as keeping them separate makes building simpler (and there doesn't seem to be much benefit to combining them).

wbharding commented 2 years ago

Are there any install options needed when installing the gem to ensure the arm64 version of libargon2.dylib is picked over the x86_64 version? My M1 Mac is currently protesting

dlopen(~/.rvm/gems/ruby-2.6.9@gitclear/gems/argon2-kdf-0.1.6/vendor/libargon2.dylib, 0x0009): tried: '~/.rvm/gems/ruby-2.6.9@gitclear/gems/argon2-kdf-0.1.6/vendor/libargon2.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'))

My ruby -v is

ruby 2.6.9p207 (2021-11-24 revision 67954) [arm64-darwin21]

So it seems I'm missing something about how to install argon2-kdf 0.1.6 such that the arm64 libargon2.dylib is selected...any tips would be much appreciated. 🙏 I'll update my post if I figure this out myself.

To answer a Q from a prior message in this thread, my ruby -e "puts RbConfig::CONFIG['arch']" is arm64-darwin21

ankane commented 2 years ago

Hey @wbharding, try 0.1.7 (#6).

wbharding commented 2 years ago

Well that fixed it proper quick. Thanks for the legendary response time! Next time I'll Google the version history first 😄