Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple M1 Chip Compatibility #3

Closed
HamptonMakes opened this issue Dec 26, 2020 · 10 comments
Closed

Apple M1 Chip Compatibility #3

HamptonMakes opened this issue Dec 26, 2020 · 10 comments

Comments

@HamptonMakes
Copy link

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 added a commit that referenced this issue Dec 26, 2020
@ankane
Copy link
Owner

ankane commented Dec 26, 2020

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 added a commit that referenced this issue Dec 27, 2020
ankane added a commit that referenced this issue Dec 27, 2020
@ankane
Copy link
Owner

ankane commented Dec 27, 2020

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
Copy link
Author

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
Copy link
Author

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
Copy link
Owner

ankane commented Dec 27, 2020

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
Copy link
Author

HamptonMakes commented Dec 28, 2020

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
Copy link
Owner

ankane commented Dec 29, 2020

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).

@ankane ankane closed this as completed Dec 29, 2020
@wbharding
Copy link

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
Copy link
Owner

ankane commented Jan 14, 2022

Hey @wbharding, try 0.1.7 (#6).

@wbharding
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants