Skip to content

Instantly share code, notes, and snippets.

@T1T4N
Created July 12, 2022 14:43
Show Gist options
  • Save T1T4N/9d64ac4f87c5e0e89bfcdd7e4bd9edc1 to your computer and use it in GitHub Desktop.
Save T1T4N/9d64ac4f87c5e0e89bfcdd7e4bd9edc1 to your computer and use it in GitHub Desktop.
Getting clang-format to work in Xcode 12+

Version info

The original repository can be found on GitHub: XcodeClangFormat

Tested with version 1.2.1 (commit 240bba0)

Setup

  1. Clone the original repository from GitHub (XcodeClangFormat)
  2. Navigate into the directory (cd XcodeClangFormat)
  3. Make sure to read the README.md file
  4. Execute ./configure in the repository directory, which will generate an xcconfig file

Required changes

Build Settings

ARCHS = x86_64

Linking

Link XcodeKit.framework to clang-format meta-target and Embed without Signing.

Testing a debug build

Trying to run a debug build can result in a greyed-out menu item in Xcode.

These are the steps necessary to get it working:

  1. Make sure you have no other clang-format bundle installed on the system
  2. Uncheck it from the Extensions list in System Preferences
  3. Clean rebuild the extension
  4. Run the debug build
  5. ⌘+Q Xcode (make sure it has no dot under the dock icon)
  6. Check the clang-format entry on the Extensions page

Troubleshooting

Even if everything is done correctly, sometimes the extension cannot be found on the Extension page in System Preferences, or the complete section Xcode Source Editor can be missing.

This happens more often when there are multiple parallel versions of Xcode installed on the system.

To fix this, Quit Xcode (⌘+Q) and run the following command: /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f "/Applications/Xcode.app"

This command forces Launch Services to force-update the bundle information.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment