Quick Start
Generate and open an Xcode workspace:App/ExampleApp-BUCK.xcworkspace and opens it in Xcode.
How It Works
Buck’s project generation analyzes your BUCK files and creates equivalent Xcode projects:- Reads BUCK files: Parses build rules and dependencies
- Creates .xcodeproj files: Generates Xcode project files for each module
- Creates workspace: Combines projects into a workspace
- Configures schemes: Sets up build schemes with proper dependencies
The generated projects use Buck for building, not Xcode’s native build system. This ensures consistency between CLI and IDE builds.
Project Generation
Using Make
The recommended way to generate projects:- Runs
make cleanto remove old projects - Executes
tools/buck project //App:workspace - Opens the workspace in Xcode
Using Buck Directly
Generate without opening Xcode:Workspace Configuration
The workspace is defined inApp/BUCK:135-147:
workspace_name: Name of the generated workspacesrc_target: Main app bundle targetui_test_target: UI tests to includenative_xcode_scheme_actions: Pre/post build actionsaction_config_names: Custom build configurations
Workspace Structure
The generated workspace includes:Included Projects
The workspace contains multiple Xcode projects:- ExampleApp.xcodeproj: Main app target
- Library projects: Each first-party library
- Pod projects: CocoaPods dependencies
- Framework projects: Prebuilt frameworks
Scheme Configuration
Available Schemes
The workspace includes schemes for:- ExampleApp: Main app build and run
- XCUITests: UI test execution
- Individual libraries: Build and test library modules
Scheme Actions
Pre and post-build actions can be configured in the workspace definition:Build Phase Scripts
Xcode-specific build scripts are defined usingxcode_prebuild_script and xcode_postbuild_script:
App/BUCK:106-124
Working with the Generated Project
Open the workspace
After generation, open the workspace:
Always open the
.xcworkspace, not individual .xcodeproj files, to ensure all dependencies are loaded.Select the scheme
In Xcode:
- Click the scheme selector near the Run button
- Choose “ExampleApp”
- Select your target simulator or device
Development Workflow
Editing Code
Use Xcode normally for:- Code editing with autocomplete
- Syntax highlighting
- Code navigation
- Debugging with breakpoints
- Interface Builder for storyboards
Building
When you build in Xcode:- Xcode invokes Buck with appropriate targets
- Buck builds dependencies in correct order
- Build products are placed in
buck-out/ - Xcode installs the app on the simulator/device
Testing
Run tests from Xcode:- Unit tests: Cmd+U runs all tests
- Single test: Click the diamond icon next to a test method
- Test navigator: View all tests and results
- Coverage: Enable in scheme settings
Regenerating Projects
You’ll need to regenerate projects when:- Adding new BUCK files or targets
- Modifying dependencies in BUCK files
- Changing workspace configuration
- Switching branches with different BUCK changes
Clean old projects
- All
.xcworkspacedirectories - All
.xcodeprojfiles - Buck build outputs
Project Generation Options
Custom Workspace Target
Generate a different workspace configuration:Including Tests
Tests are automatically included based on the workspace configuration. Theui_test_target parameter adds UI tests:
tests parameter on library targets:
App/BUCK:58-86
Build Configurations
Xcode projects include standard build configurations:- Debug: Development builds with symbols
- Release: Optimized production builds
- Profile: Performance profiling builds
action_config_names:
Debugging
Setting Breakpoints
Set breakpoints normally in Xcode:- Click the gutter next to a line number
- Run the app with Cmd+R
- Debugger pauses when breakpoint is hit
LLDB Console
Use LLDB commands in the console:po variable- Print object descriptionp variable- Print valuebt- Print backtracecontinue- Resume execution
Debug Symbols
Buck generates dSYM files for debugging. They’re located in:Xcode automatically finds and uses the dSYM files for symbolication.
Limitations
Buck-Powered Builds
The generated projects use Buck for building, which means:- ✅ Consistent builds between CLI and Xcode
- ✅ Fast incremental builds
- ❌ Can’t modify build settings in Xcode UI (must edit BUCK files)
- ❌ Build output appears in Buck format
Project Modification
Changes made in Xcode don’t persist:- ⚠️ Adding files in Xcode won’t update BUCK files
- ⚠️ Changing build settings in Xcode has no effect
- ⚠️ All changes must be made in BUCK files
Xcode vs Buck Local
BuckSample offers two Xcode integration approaches:| Feature | Standard Project | Buck Local Project |
|---|---|---|
| Build system | Buck | Xcode (with Buck libraries) |
| Generation command | make project | make buck_local_project |
| Build speed | Fast | Faster (incremental) |
| Xcode integration | Limited | Full |
Troubleshooting
Project Generation Fails
Problem: Buck project command errors- Solution: Ensure BUCK files are valid:
Fix any errors and try again.
- Solution: Check that the workspace file was created:
Xcode Build Issues
Problem: Build fails in Xcode but works from CLI- Solution: Regenerate the project:
- Solution: The files exist but the project references are stale. Regenerate.
- Solution: Always regenerate after editing BUCK files:
Debugging Issues
Problem: Breakpoints not hitting- Solution: Ensure Debug configuration is selected and optimization is disabled
- Solution: Build with Debug configuration, not Release
Next Steps
Buck Local
Use Buck Local for faster Xcode builds with better integration
Testing
Learn how to run tests in Xcode and from the command line