Installing a Universal 2 binary #4985
-
Output of
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 4 replies
-
This is not possible since managing dependencies for distribution outside of Homebrew is not a design goal of Homebrew. I feel the optimisation we can provide by not making universal binaries and the headaches we avoid by not making universal binaries far outweigh the benefit for this use case that very few users encounter. |
Beta Was this translation helpful? Give feedback.
-
If you look around the internet a bit you might come across other package managers for MacOS that do attempt to support universal binaries. It's possible one of those might save you some manual labour, although homebrew is by far and away the biggest name in the package manager game on MacOS, and I do use it for many things. Also, the Apple engineer that is in charge of https://github.com/XQuartz/XQuartz has written a very elegant build system in shell that generates universal binaries for that complex project with many dependencies. You may find that quite adaptable, depending your number of dependencies and tolerance for manually building things. |
Beta Was this translation helpful? Give feedback.
-
I have a quick update following several hours of experimentation. I thought that the easiest way to approach this would be to use My invocation was simple enough:
According to AppleClang documentation, if multiple
This baffled me as I was not even setting the After reviewing I still do not entirely understand how to proceed from here, but I just thought it would be helpful for someone in the future to share my findings. If I am unable to re-configure Homebrew to build a universal binary from source, I may have to resort to plan B. This would mean having two independent Cellars, one for each CPU architecture, and running |
Beta Was this translation helpful? Give feedback.
-
I have another update. TL;DR: I managed to get it done. First things first, I figured out why setting For that reason, my current solution was as follows:
I find this nice and elegant, since in step 2 we essentially use the compiler shim, which was previously causing me problems by swallowing some flags, to actually inject the Following this I verified that the installed package now contains Universal 2 binaries for both Intel and Apple Silicon:
My last goal is to automate this process for my CI and scale it up to my other dependencies. Hopefully, they will be as easy to work with as ZeroMQ. |
Beta Was this translation helpful? Give feedback.
-
using dual archflags works for some things. You will find (as I have done it hundreds of times) many other things will not build universal with this simple approach. I suggest you try macports instead. They have infrastructure to support universal building. It’s not perfect, because supporting universal is hard, but it’s many many hours of work ahead of what you have here, and officially supported there. |
Beta Was this translation helpful? Give feedback.
-
I thought it would be a good idea to check in after a couple weeks. Even though my previously presented approach works for now, I took on board some points made in this thread. Most importantly, that it is a finicky business to convince HB to build universal binaries because that we are bending things out of shape to get the job done, and that while it may be working for now, it may easily break for many reasons in the future. Obviously that would be a dealbreaker for me, as I am trying to set up a somewhat robust CI/CD infrastructure for my project. Long story short, I followed the suggestion made by @kencu and gave MacPorts a try. The bottom line is that I managed to get it done, but I made some observations along the way and encountered a some roadblocks that needed to be sidestepped. I thought this would be a good venue to share them in case future me (or anybody else in a similar position) needs to revisit them. First, it was a good sign that all my HB packages had their equivalent counterparts in the MacPorts universe. This was not guaranteed, and would be a tremendous pain in the ass if that had not been so. Just like HB allows to enable options during Unfortunately that was not the end of it; I had two more setbacks. First happened when I tried to install the My last problem was with the I am much happier that I devoted time to resolving this properly. Unlike my previous solution that was based on HB, with MacPorts I did not really need to hack anything or bend anything out of shape to get the job done. This suggests to me that the new solution will be much more robust and sustainable in the long term (famous last words). Thanks again for your inputs. I hope that this thread helps any other poor soul trying to cross-compile things for universal binaries. |
Beta Was this translation helpful? Give feedback.
-
(late reply, but I stumbled onto this issue and found some of the comments helpful) You might also try an approach like this: This will pull bottled binaries for both architectures from homebrew to a specific directory, and lipo them together. It was made for a specific and narrow use-case, so I'm sure it will not work universally (no pun intended...), but I think the approach is valid - especially if you have a package with more complex dependencies, where individually dealing with each dependency is not feasible. |
Beta Was this translation helpful? Give feedback.
using dual archflags works for some things.
You will find (as I have done it hundreds of times) many other things will not build universal with this simple approach.
I suggest you try macports instead. They have infrastructure to support universal building. It’s not perfect, because supporting universal is hard, but it’s many many hours of work ahead of what you have here, and officially supported there.