{"title":"Building Xcode Projects From The Command Line In 2026","html_url":"https://deallocatedobjects.com/posts/building-xcode-projects-from-the-command-line-in-2026","source_url":"","markdown_content":"In 2012 I wrote about [a couple of little tools](/posts/building-xcode-projects-from-the-command-line) that made building Xcode projects from the command line less painful. Both were Ruby scripts wrapped around `xcodebuild`.\n\nI still build almost everything from the command line. Here's what that looks like for me now.\n\n### XcodeGen\n\nEvery Apple project I start now begins with a `project.yml` and [XcodeGen](https://github.com/yonaskolb/XcodeGen). The `.xcodeproj` gets generated from that file, so I never hand-edit a `project.pbxproj` or untangle a merge conflict in one.\n\nHere's a whole project file for a small Mac command line tool:\n\n```yaml\nname: TodoDemo\noptions:\n  bundleIdPrefix: com.example\ntargets:\n  TodoDemo:\n    type: tool\n    platform: macOS\n    deploymentTarget: \"15.0\"\n    sources: [Sources]\n```\n\nRun `xcodegen` next to it:\n\n```\n⚙️  Generating project...\n⚙️  Writing project...\nCreated project at /Users/jake/TodoDemo/TodoDemo.xcodeproj\n```\n\nAdd a file, a target or a build setting by editing the YAML and running it again.\n\n### xcodebuild\n\nThen a plain `xcodebuild` builds it:\n\n```bash\nxcodebuild -project TodoDemo.xcodeproj -scheme TodoDemo -derivedDataPath build build\n```\n\n`-derivedDataPath` puts the build output in the project folder instead of `~/Library/Developer/Xcode/DerivedData`, which makes it easy for a script to find the product, and easy to delete.\n\nAny build setting can be overridden right on the command line by tacking `NAME=value` onto the end. One I like turning on now and then makes the Swift compiler warn about anything slow to type-check:\n\n```bash\nxcodebuild -project TodoDemo.xcodeproj -scheme TodoDemo build \\\n  OTHER_SWIFT_FLAGS='-Xfrontend -warn-long-expression-type-checking=100 -Xfrontend -warn-long-function-bodies=100'\n```\n\nAnything over 100 ms becomes a warning like this one (from a test where I turned the limit way down to 1 ms):\n\n```\nSources/main.swift:4:12: warning: expression took 27ms to type-check (limit: 1ms)\n```\n\nAnd when I need to know what a setting ended up as, `-showBuildSettings` prints all of them:\n\n```bash\nxcodebuild -project TodoDemo.xcodeproj -scheme TodoDemo -showBuildSettings | grep -E \" (PRODUCT_BUNDLE_IDENTIFIER|MACOSX_DEPLOYMENT_TARGET) =\"\n```\n\n```\n    MACOSX_DEPLOYMENT_TARGET = 15.0\n    PRODUCT_BUNDLE_IDENTIFIER = com.example.TodoDemo\n```\n\n### xcbeautify\n\n`xcodebuild` is loud. That one-file tool above printed about 600 lines for a single build. [xcbeautify](https://github.com/cpisciotta/xcbeautify) boils it down to the parts you'd want to read:\n\n```bash\nxcodebuild -project TodoDemo.xcodeproj -scheme TodoDemo build | xcbeautify\n```\n\n```\n[TodoDemo] Compiling main.swift\n[TodoDemo] Copy arm64-apple-macos.abi.json -> TodoDemo.abi.json\nBuild Succeeded\n```\n\nOne gotcha when you use it in a script: the exit status of a pipeline is the last command's, so a failed build piped into `xcbeautify` still exits 0. Put `set -o pipefail` at the top of the script and a failed build fails the script too.\n\nBoth XcodeGen and xcbeautify install with Homebrew (`brew install xcodegen xcbeautify`). Kinda neat that both of them are written in Swift.","html_content":"<p>In 2012 I wrote about <a href=\"https://deallocatedobjects.com/posts/building-xcode-projects-from-the-command-line\">a couple of little tools</a> that made building Xcode projects from the command line less painful. Both were Ruby scripts wrapped around <code>xcodebuild</code>.</p>\n<p>I still build almost everything from the command line. Here’s what that looks like for me now.</p>\n<h2 id=\"xcodegen\" data-level=\"3\">XcodeGen</h2>\n<p>Every Apple project I start now begins with a <code>project.yml</code> and <a href=\"https://github.com/yonaskolb/XcodeGen\">XcodeGen</a>. The <code>.xcodeproj</code> gets generated from that file, so I never hand-edit a <code>project.pbxproj</code> or untangle a merge conflict in one.</p>\n<p>Here’s a whole project file for a small Mac command line tool:</p>\n<figure class=\"code\" data-lang=\"yaml\"><figcaption><span class=\"lang\">YAML</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">name</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">TodoDemo</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">options</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">:</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">  bundleIdPrefix</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">com.example</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">targets</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">:</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">  TodoDemo</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">:</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">    type</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">tool</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">    platform</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">macOS</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">    deploymentTarget</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: </span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">\"15.0\"</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#22863A;--shiki-dark:#85E89D\">    sources</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">: [</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">Sources</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">]</span></span></code></pre></figure><p>Run <code>xcodegen</code> next to it:</p>\n<figure class=\"code\" data-lang=\"text\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span>⚙️  Generating project...</span></span>\n<span class=\"line\"><span>⚙️  Writing project...</span></span>\n<span class=\"line\"><span>Created project at /Users/jake/TodoDemo/TodoDemo.xcodeproj</span></span></code></pre></figure><p>Add a file, a target or a build setting by editing the YAML and running it again.</p>\n<h2 id=\"xcodebuild\" data-level=\"3\">xcodebuild</h2>\n<p>Then a plain <code>xcodebuild</code> builds it:</p>\n<figure class=\"code\" data-lang=\"bash\"><figcaption><span class=\"lang\">Shell</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">xcodebuild</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -project</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> TodoDemo.xcodeproj</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -scheme</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> TodoDemo</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -derivedDataPath</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> build</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> build</span></span></code></pre></figure><p><code>-derivedDataPath</code> puts the build output in the project folder instead of <code>~/Library/Developer/Xcode/DerivedData</code>, which makes it easy for a script to find the product, and easy to delete.</p>\n<p>Any build setting can be overridden right on the command line by tacking <code>NAME=value</code> onto the end. One I like turning on now and then makes the Swift compiler warn about anything slow to type-check:</p>\n<figure class=\"code\" data-lang=\"bash\"><figcaption><span class=\"lang\">Shell</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">xcodebuild</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -project</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> TodoDemo.xcodeproj</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -scheme</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> TodoDemo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> build</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> \\</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\">  OTHER_SWIFT_FLAGS='-Xfrontend -warn-long-expression-type-checking=100 -Xfrontend -warn-long-function-bodies=100'</span></span></code></pre></figure><p>Anything over 100 ms becomes a warning like this one (from a test where I turned the limit way down to 1 ms):</p>\n<figure class=\"code\" data-lang=\"text\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span>Sources/main.swift:4:12: warning: expression took 27ms to type-check (limit: 1ms)</span></span></code></pre></figure><p>And when I need to know what a setting ended up as, <code>-showBuildSettings</code> prints all of them:</p>\n<figure class=\"code\" data-lang=\"bash\"><figcaption><span class=\"lang\">Shell</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">xcodebuild</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -project</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> TodoDemo.xcodeproj</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -scheme</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> TodoDemo</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -showBuildSettings</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> |</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> grep</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -E</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> \" (PRODUCT_BUNDLE_IDENTIFIER|MACOSX_DEPLOYMENT_TARGET) =\"</span></span></code></pre></figure><figure class=\"code\" data-lang=\"text\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span>    MACOSX_DEPLOYMENT_TARGET = 15.0</span></span>\n<span class=\"line\"><span>    PRODUCT_BUNDLE_IDENTIFIER = com.example.TodoDemo</span></span></code></pre></figure><h2 id=\"xcbeautify\" data-level=\"3\">xcbeautify</h2>\n<p><code>xcodebuild</code> is loud. That one-file tool above printed about 600 lines for a single build. <a href=\"https://github.com/cpisciotta/xcbeautify\">xcbeautify</a> boils it down to the parts you’d want to read:</p>\n<figure class=\"code\" data-lang=\"bash\"><figcaption><span class=\"lang\">Shell</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\">xcodebuild</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -project</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> TodoDemo.xcodeproj</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> -scheme</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> TodoDemo</span><span style=\"--shiki-light:#032F62;--shiki-dark:#9ECBFF\"> build</span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\"> |</span><span style=\"--shiki-light:#6F42C1;--shiki-dark:#B392F0\"> xcbeautify</span></span></code></pre></figure><figure class=\"code\" data-lang=\"text\"><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span>[TodoDemo] Compiling main.swift</span></span>\n<span class=\"line\"><span>[TodoDemo] Copy arm64-apple-macos.abi.json -> TodoDemo.abi.json</span></span>\n<span class=\"line\"><span>Build Succeeded</span></span></code></pre></figure><p>One gotcha when you use it in a script: the exit status of a pipeline is the last command’s, so a failed build piped into <code>xcbeautify</code> still exits 0. Put <code>set -o pipefail</code> at the top of the script and a failed build fails the script too.</p>\n<p>Both XcodeGen and xcbeautify install with Homebrew (<code>brew install xcodegen xcbeautify</code>). Kinda neat that both of them are written in Swift.</p>","created_at":"2026-12-01T14:00:00.000Z","updated_at":"2026-12-01T14:00:00.000Z"}