maxirmx
maxirmx

Reputation: 374

Can I install arm64 libraries on x86_64 with homebrew?

I am cross-compiling on x86_64 MacOS 11 for arm64 architecture. clang/XCode support it but I face an issue when external library is required. Let it be boost, for example. I know that the bottle for arm64 is available but it looks like there is no way to select it for installation.

arch -arm64 brew ... says that this architecture is unknown which sounds fair.

So the question is wheather there is an option to force brew install bottles for 'foreign' architecture ?

Upvotes: 7

Views: 7216

Answers (2)

maxirmx
maxirmx

Reputation: 374

Thanks to Homebrew team https://github.com/Homebrew/discussions/discussions/2843

I made it work with the code like this:

setopt sh_word_split
mkdir arm-homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C arm-homebrew 
alias arm-brew='$(pwd)/arm-homebrew/bin/brew'
response=$(arm-brew fetch --force --bottle-tag=arm64_big_sur boost | grep "Downloaded to")
parsed=($response)  
arm-brew install $parsed[3] 

UPDATE Comprehensive script kindly provide by @tresf https://gist.github.com/tresf/9a45e1400a91f4c9c14a2240967094ff

Upvotes: 6

Adam
Adam

Reputation: 17369

Native system brew can be asked to download any desired bottle version with two switches:

  • --force ignores the compatibility check
  • --bottle-tag=arm64_big_sur downloads the ARM Big Sur build. This assumes the formula has this build, check the formula .rb for available tags. Big Sur is the earliest macOS with ARM support.

Then use brew --cache to get the filename of the downloaded bottle and pass to brew install:

brew fetch --force --bottle-tag=arm64_big_sur boost
brew install $(brew --cache --bottle-tag=arm64_big_sur boost)

You can verify that it worked with cd $(brew --prefix boost) then use file on any .dylib files to see what architecture they're built for.

If the formula has any dependencies then they will still be installed normally (for the native architecture), so you may have to follow the same process for them.

Upvotes: 1

Related Questions