Xcode build rules script "command not found" on M1

Viewed 570

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

1 Answers

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.

Related