r/Xcode • • 10d ago

XcodeGen setup for a sandboxed Mac app + widget extension + StoreKit config: the lines that actually matter

Post image

I keep my Mac app's .xcodeproj out of git and generate it with XcodeGen. The app is a small menu bar utility with a WidgetKit extension, App Intents and a tip jar, and almost every "why doesn't this work" moment came down to a handful of lines in project.yml. Sharing in case it saves someone an evening:

  1. StoreKit config without bundling it. - path: Configuration.storekit with buildPhase: none keeps the file in the project but out of Copy Bundle Resources, and scheme: storeKitConfiguration: Configuration.storekit wires it into the generated scheme, so local IAP testing works right after xcodegen generate.
  2. Embed + sign the extension from the app target. dependencies: - target: HeadphoneWidgets, embed: true, codeSign: true. An embedded appex that isn't signed with the same team simply won't load, and the failure is quiet.
  3. Runpath for the extension. LD_RUNPATH_SEARCH_PATHS: $(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks. The second entry is what lets an appex inside Contents/PlugIns find the host app's frameworks.
  4. One App Group, defined once. APP_GROUP: $(TeamIdentifierPrefix)com.example.app in base settings, then $(APP_GROUP) in both entitlements files and in Info.plist (AppGroupIdentifier). Shared code reads it from the bundle and falls back if the variable didn't expand, so a misconfigured build fails visibly instead of silently writing to .standard defaults.
  5. Compile shared code into both targets, branch with a flag. A Shared/ folder is a source path in both targets, and the extension gets SWIFT_ACTIVE_COMPILATION_CONDITIONS: $(inherited) WIDGET_EXTENSION for the few places that must differ.

Also worth it: ENABLE_APP_SANDBOX, ENABLE_HARDENED_RUNTIME and DEAD_CODE_STRIPPING in base settings so every target inherits them.

Anyone else generating projects with XcodeGen or Tuist for macOS apps with extensions? Curious whether you hit anything with Control Center controls (macOS 26) that needed extra config.

1 Upvotes

4 comments sorted by

1

u/DueMode3191 9d ago

I'd add a clean checkout CI job that runs XcodeGen, builds both targets, and checks the generated scheme. That catches missing settings before someone opens Xcode

1

u/azardandona26 9d ago

Good call. Right now I only run xcodegen generate locally, so a missing setting shows up the first time Xcode opens the project. A clean-checkout job that generates, runs xcodebuild for the app scheme (which builds the embedded widget too) and then checks the generated .xcscheme for the StoreKit config line would have caught both of my early mistakes. Noted for the CI setup, thanks.

1

u/DueMode3191 5d ago

Nice, that covers the two failures you mentioned. Are you planning to run the generated project checks on every pull request, or only when project.yml changes?

1

u/azardandona26 5d ago

Every PR, I think. project.yml isn't the only input: XcodeGen globs the source folders, so adding or moving a file in Shared/ or the widget folder changes the generated project too, and a path filter on project.yml would skip exactly those PRs. Generate + one xcodebuild of the app scheme is a few minutes on a macOS runner, which is cheap next to finding out when someone opens Xcode.

To be upfront: it isn't set up yet, right now it's still only a local xcodegen generate. So that's the plan, not something I've been running for weeks.