Can I install arm64 libraries on x86_64 with homebrew? - 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 ?

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]

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.

Related

Finding the binary's name after package installation

When I installed 7zip via home brew (Formula sevenzip), i noticed that i cannot run it via sevenzip and even brew info sevenzip did not tell me the name of the binary.
Only after looking in the script file on Github I noticed a command 7zz but there must be an easier way to find out the binaries or commands associated with a homebrew package.
The simplest I know is:
brew ls PACKAGE
and you can normally see it pretty quickly. Personally, I use p7zip as PACKAGE.
Alternatively, as brew --prefix tells you where binaries are installed (via symlinks), you can find the newest installed binary with:
ls -lrt $(brew --prefix)/bin
and it's the last one listed.

Error: yq#3 has been disabled because it is not maintained upstream! How to install a disabled brew Formulae?

I'm trying to install yq#3 on my Mac running brew install yq#3 and I get the error:
Error: yq#3 has been disabled because it is not maintained upstream!
I see that it's there on their website at https://formulae.brew.sh/formula/yq#3#default but it doesn't seem to be supported anymore.
I still need to install it since our projects at work are using this specific version.
The only way that I'm thinking about is downloading the source code, building it myself, and adding it to the path but I'm thinking that there might be a simpler solution.
Any suggestion?
Thanks!
From yq github, you can install a binary by running:
wget https://github.com/mikefarah/yq/releases/download/3.4.1/yq_darwin_amd64 -O /usr/local/bin/yq &&\
chmod +x /usr/local/bin/yq
3.4.1 is the latest 3 version, darwin_amd64 is the Mac package (don't worry about having an Intel machine and installing the package that says AMD, the name comes from something about AMD invented the 64-bit instruction set).

How can I install a Homebrew bottle designed for a different (previous) version of macOS

I haven't been able to find a way to install prior versions of software since the removal of the versions command and tap in Homebrew. I'm running macOS 10.14.3 (Mojave) on a 2008 Mac Pro (3,1). I've run into one or two Homebrew packages that assume I have a Nehalem processor, but my Penryn Xeon doesn’t' support some of the instructions.
After some troubleshooting, I was told to install a previous version of a bottle, but I can't find any instructions or documentation on how to specify a bottle version. Is there a way from within Homebrew to specify a bottle version? Preferably one that will allow me to use brew update in the future? The current method of brew install foo --build-bottle --build-arch=core2 isn't really ideal when someone else has already built an appropriate bottle.
As of 2021, BinTray has closed down, and bottles are now stored as GitHub Packages instead.
You can download these using the following cURL invocation:
curl -L -H "Authorization: Bearer QQ==" -o x.tar.gz https://ghcr.io/v2/homebrew/core/NAME/blobs/sha256:HASH
...replacing NAME with the name of the package whose bottle you would like to download, and HASH with the SHA-256 identifier for the bottle you would like.
The hashes can be found in the formula file for the package, inside the bottle block. Each OS and architecture has a different hash:
class Gettext < Formula
# ...
bottle do
sha256 arm64_monterey: "6e2c829031949c0cbd758d0701ed62c191387736e76a98a046c0619907632225"
sha256 arm64_big_sur: "339b62b52ba86dfa73091d37341104b46c01ae354ca425000732df689305442b"
sha256 monterey: "0e93b5264879cd5ece6efb644fd6320b0b96cce36de3901c1926e53f851d14c7"
sha256 big_sur: "a025e143fe3f5f7e24a936b8b0a4926acfdd025b11d62024e3d355c106536d56"
sha256 catalina: "cdea54f52b7c36ebcb5fe26a1cf736d7cd6fd5f2fd016dd8357a8624ffd6b5f8"
sha256 mojave: "99707d4dcc731faf980333365a694e9500f2f012f84c0bcb6d8cb5d620c2ce08"
sha256 high_sierra: "5ac5783e31205b92907b46bfaaa142620aea7ee3fc4d996876b0913fd2315695"
sha256 x86_64_linux: "33f840e667c6ee0f674adb279e644ca4a1b3cd1606894c85d9bbce1b5acc0273"
end
# ...
end
In my case, I'm trying to build on MacOS 10.15 (Catalina) via Github build machines and I wanted to force install 10.14 (Mojave) bottles so that I could link against SDL2 for earlier OSes.
I was able to download the specific bottle file from bintray and install that manually.
curl -L https://bintray.com/homebrew/bottles/download_file?file_path=sdl2-2.0.10.mojave.bottle.tar.gz -o sdl2-2.0.10.mojave.bottle.tar.gz
brew install -f sdl2-2.0.10.mojave.bottle.tar.gz
It's not pretty, and unfortunately hardcodes the software version. I'd love to know if there's a way to tell brew "just use Mojave (or whatever OS) bottles if possible".

brew install libusb linking failed

I am installing libusb with brew in my Mac
brew install libusb
The linking step failed as below
Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local
Could not symlink lib/libusb-1.0.0.dylib
Target /usr/local/lib/libusb-1.0.0.dylib already exists.
You may want to remove it: rm '/usr/local/lib/libusb-1.0.0.dylib'
To force the link and overwrite all conflicting files: brew link
--overwrite libusb
So I removed the existing libusb with
sudo rm '/usr/local/lib/libusb-1.0.0.dylib'
and then did a link
brew link --overwrite libusb
The linking doesn't work, shows error below
Error: Could not symlink lib/libusb-1.0.0.dylib
/usr/local/lib is not writable.
If I try
sudo brew link --overwrite libusb
instead, that doesn't work either. What am I missing?
I am using OSX El Capitan version 10.11.4 (15E65)
If things seem not to work with homebrew, my general strategy is first to try:
brew doctor
and do whatever the good doctor recommends.
If that fails, I tend to uninstall things, normally using --force which really does a good clean-up and removes old versions. So, in your case:
brew rm libusb --force
Then re-install the "unhappy" package. So, in your case:
brew install libusb
In answer to your new question in the comments. Your installation looks correct because libusb isn't an executable program - it is just a library without any associated command-line tools - so it won't show up when you run which libusb.
You can see the constituent parts of the package with this command:
brew ls libusb
/usr/local/Cellar/libusb/1.0.20/include/libusb-1.0/libusb.h
/usr/local/Cellar/libusb/1.0.20/lib/libusb-1.0.0.dylib
/usr/local/Cellar/libusb/1.0.20/lib/pkgconfig/libusb-1.0.pc
/usr/local/Cellar/libusb/1.0.20/lib/ (2 other files)
And, as you can see, there is no stand-alone executable program in /usr/local/bin called libusb, there are just
libusb.h - a C header file you would compile against
libusb...dylib - a dynamic library you would link against
libusb...pc - which supplies the info for the pkgconfig tool
So, if you wanted to compile and link an application against libusb, you would run pkg-config like this to find out the "Include path" and linker details
pkg-config --cflags --libs libusb
-I/usr/local/Cellar/libusb-compat/0.1.5/include \
-I/usr/local/Cellar/libusb/1.0.20/include/libusb-1.0 \
-L/usr/local/Cellar/libusb
which means your compilation command would look like this:
gcc yourApp.c $(pkg-config --cflags --libs libusb) -o yourApp

I've already installed binutils in osx 10.11, but objdump still doesn't work

I've tried hard to install binutil with HomeBrew onto osx 10.11, finally succeed, but objdump still doesn't work. The response given by terminal is as follow:
MacBook-Pro:~ Mars$ brew install binutils
==> Downloading https://homebrew.bintray.com/bottles/binutils-2.26.el_capitan.bo
Already downloaded: /Library/Caches/Homebrew/binutils-2.26.el_capitan.bottle.tar.gz
==> Pouring binutils-2.26.el_capitan.bottle.tar.gz
🍺 /usr/local/Cellar/binutils/2.26: 109 files, 140.3M
MacBook-Pro:~ Mars$ objdump
-bash: objdump: command not found
Anybody can help?
To avoid conflicts with the utilities distributed by Apple, the binutils executables installed by Homebrew all have "g" prefixed to their names (so, for instance, objdump becomes gobjdump).
you need to update your $PATH to include the homebrew install location. you probably want to look at other places people have asked this question like:
https://superuser.com/questions/324616/how-should-i-set-the-path-variable-on-my-mac-so-the-hombrew-installed-tools-are

Resources