setup-ruby: Library not loaded libgmp.10.dylib on self-hosted macos M1

using: self-hosted macOS (M1 chip)

- name: Install ruby
  uses: ruby/setup-ruby@v1
  env:
    ImageOS: macos1015

1st libgmp.10.dylib error:

The installation failed on “Print Ruby version” step with the error below:

Reason: tried: '/usr/local/opt/gmp/lib/libgmp.10.dylib' (no such file), '/usr/local/lib/libgmp.10.dylib' (no such file), '/usr/lib/libgmp.10.dylib' (no such file)

image

I have gmp installed with homebrew and hence the libgmp.10.dylib is located under /opt/homebrew/Cellar/gmp/6.2.1_1/lib/libgmp.10.dylib

2nd libgmp.10.dylib error

I manually installed gmp to ensure /usr/local/lib/libgmp.10.dylib will be available

but then, got a new error:

'/usr/local/lib/libgmp.10.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')),

image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 20 (7 by maintainers)

Most upvoted comments

I’m not entirely sure a symlink is accepted (depends on https://github.com/actions/toolkit/tree/main/packages/tool-cache), but it’s worth a try.

It won’t. The tool checks the .../actions-runner/_work/_tool/Ruby/{version}/{os_architecture} for existing cache and if it doesn’t exist this action will download a new on into the hostedtoolcache folder and overwrite whatever is there.

Since Github Actions supports M1 self hosted runners it would be nice for this action to have the MacOS arm builds. However automating that is obviously hard since Github doesn’t have any MacOS arm runners.

After some more headache with this problem I don’t think @Shahaed python script will solve the issue for me. I already have an arm64 built binary of Ruby installed on the machine via rbenv. The python script only seem to care about homebrew installs.

So my solution was to create a symlinks in /Users/runner/hostedtoolcache to the rbenv install of Ruby similar to how @Shahaed python script does for homebrew installed Cellars.

Then I have a script that is run before runner jobs that will execute ln -fs /Users/runner/hostedtoolcache/Ruby /Users/runner/actions-runner/_work/_tool

So in short

# create symlinks in hostedtoolcache to rbenv install
ln -s /Users/runner/.rbenv/versions/3.1.2 /Users/runner/hostedtoolcache/Ruby/3.1.2/arm64
ln -s /Users/runner/.rbenv/versions/3.1.2 /Users/runner/hostedtoolcache/Ruby/3.1.2/x86
ln -s /Users/runner/.rbenv/versions/3.1.2 /Users/runner/hostedtoolcache/Ruby/3.1.2/x64
touch /Users/runner/hostedtoolcache/Ruby/3.1.2/arm64.complete
touch /Users/runner/hostedtoolcache/Ruby/3.1.2/x86.complete
touch /Users/runner/hostedtoolcache/Ruby/3.1.2/x64.complete

# have a script run at job startup by the github runner that runs the following command
ln -fs /Users/runner/hostedtoolcache/Ruby /Users/runner/actions-runner/_work/_tool

This can be a temporary solution for those with rbenv ruby until this action, setup-ruby, have solved arm64 macos builds that are pulled down by the action.

any plan to support M1 in the near future ?

We’d need M1 GitHub-hosted runners for that, so I can build the releases. Until then, no, but it might work if installing Rosetta 2 and the needed dependencies with amd64 Homebrew. I might consider adding a way to build your own ruby and use it with setup-ruby, but that seems a separate issue somewhat.

According to https://tenderlovemaking.com/2022/01/07/homebrew-rosetta-and-ruby.html, /usr/local should be amd64 Homebrew, and so /usr/local/lib/libgmp.10.dylib should be amd64 but it seems aarch64 in your case. So I guess you manually copied /opt/homebrew/Cellar/gmp/6.2.1_1/lib/libgmp.10.dylib to /usr/local/lib/libgmp.10.dylib, which is pretty wrong, do not mix architectures like that please.

To run under Rosetta you should install amd64 Homebrew (as explained in the blog post) and install gmp in amd64 Homebrew.

This is no exactly correct. There are 3 different homebrew folders:

/usr/local/opt - x86 on x86 devices /usr/local/homebrew/opt - x86 on arm64 devices /opt/homebrew - arm65 on arm64 devices

Anyways, I now have the action working on M1. You can follow https://medium.com/mkdir-awesome/how-to-install-x86-64-homebrew-packages-on-apple-m1-macbook-54ba295230f to install brew for x86 and enable Rosetta.

Afterwards use the new brew to install the required packages arch -x86_64 /usr/local/homebrew/bin/brew install gmp libyaml rvm (or use your alias). These are installed into /usr/local/homebrew/opt. But this folder is not checked when ruby is looking for the libraries. So just create a symbolic link sudo ln -s /usr/local/homebrew/opt /usr/local/opt and you are done.