How to detect a platform in a Homebrew formula?

Viewed 239

I have a cross-platform Swift tool that I'd like to make available both on macOS and Linux through Homebrew.

I currently have a dependency on Xcode in the formula file for it:

depends_on :xcode => "11.4"

This obviously doesn't work when attempting to install this formula on Linux, as Xcode is only available on macOS.

How do I detect the platform the formula is being run on and then specify a different dependency based on that?

1 Answers

Homebrew has some initiative to merge homerbew-core and linuxbrew-core for this year. And as result of that, we did introduce on_linux vs on_macos in this PR.

So if you are talking about formula authoring, I would recommend to use those two syntax rather than OS.mac? and OS.linux? to specify the dependencies.

Related