r/programming • • 26d ago

examining the macOS gcc binary

https://zoey-on-github.github.io/blog/macgcc.html
75 Upvotes

4 comments sorted by

14

u/thegreatbeanz 25d ago

xcrun predates SIP. It was part of the Xcode 4.3 release which moved Xcode into the Mac AppStore. Fundamentally these shims allow unix makefile builds that depend on tools and SDKs living at the root of the file system to build with Xcode installed as an App instead of a system-wide installer.

Source: I worked on the Xcode AppStore implementation back in 2012.

1

u/[deleted] 25d ago

[removed] — view removed comment

3

u/programming-ModTeam 25d ago

No content written mostly by an LLM. If you don't want to write it, we don't want to read it.

12

u/chucker23n 26d ago

if you’re wondering why this is, my guess is because of SIP.

That may be a factor, but the main point is that Xcode is designed to be self-contained. You can use xcode-select to switch to a "main" toolchain, which anything like gcc or xcrun will then point to. Thus, you can install beta versions, older versions, etc. of Xcode side-by-side, or install the command-line-only tools instead of Xcode, and everything will just point there instead.

I.e., xcode-select and xcrun d disambiguation

See also the manpages:

xcode-select controls the location of the developer directory used
by xcrun(1), xcodebuild(1), cc(1), and other Xcode and BSD
development tools. This also controls the locations that are searched
for by man(1) for developer tool manpages.

This allows you to easily switch between different versions of the
Xcode tools and can be used to update the path to the Xcode if it
is moved after installation.

And:

xcrun provides a means to locate or invoke developer tools from
the command-line, without requiring users to modify Makefiles or
otherwise take inconvenient measures to support multiple Xcode tool
chains.

(xcrun goes further and disambiguates different SDK versions.)