skip to Main Content

I have a project that runs some utility I’ve installed using homebrew on one of its build rules.

On my M1 mac, homebrew is installed on /opt/homebrew/bin.

I have eval "$(/opt/homebrew/bin/brew shellenv)" present in my ~/.zprofile file, but it seems like Xcode doesn’t respect that (or maybe overrides it?).

When trying to evaluate the PATH variable during Xcode run script command I get the following:

PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/bin:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/libexec:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/local/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/local/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

For clearance, this is the phase I was running, under Build rules.
Image showing the script i've ran

3

Answers


  1. Chosen as BEST ANSWER

    I've managed to find two workarounds that work with this issue, the first is to symlink the program you want from /opt/homebrew/bin onto /usr/local/bin (protoc in my case)

    sudo ln -s /opt/homebrew/bin/protoc /usr/local/bin/protoc
    

    The second is to add the following line to the build rule script:

    eval "$(/opt/homebrew/bin/brew shellenv)"
    

    This has the disadvantage of not working on non M1 Macs.


  2. There is a possible, very simple solution provided by this answer.

    Basically, freshly upgraded versions of XCode (for example, 13.4.1) running on Apple Silicon-powered Macs (like my M1 MacBook Pro), have components that cannot properly use/output the appropriate object files in all the output platform combinations you need.

    This leads to some "interesting" issues and error message cross-overs that find "almost correct" answers on StackOverflow. Hence the many suggestions to exclude "arm64" platform and similar from the build options.

    The simple answer to all of that is… to just run XCode with Rosetta enabled. Rosetta will engage with the components that miss the needed cross-platform capabilities.

    Here is an example of how to enable an application to use Rosetta. You select the app icon, then go to the File menu and select "Get Info". Then click the "Open using Rosetta" checkbox.

    enter image description here

    Login or Signup to reply.
  3. To fix this the solution for now is adding the these lines to my Xcode run scripts.

    if [[ ! $PATH =~ /opt/homebrew/bin: ]] ; then 
    PATH=/opt/homebrew/bin/:/opt/homebrew/sbin:${PATH}
    fi
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search