.buckconfig files. BuckSample uses a base configuration (.buckconfig) and specialized configs in BuildConfigurations/.
Configuration Files
.buckconfig
.buckconfig
Location: Root directoryPurpose: Base configuration for all buildsUsage: Automatically loaded by Buck for all commands
BuildConfigurations/Release.buckconfig
BuildConfigurations/Release.buckconfig
Location:
BuildConfigurations/Release.buckconfigPurpose: Release-specific optimizationsUsage:code_coverage.buckconfig
code_coverage.buckconfig
Location: Root directoryPurpose: Code coverage instrumentation flagsUsage: Automatically included via
$(config code_coverage.*) references in main .buckconfigConfiguration Sections
[cxx] - C/C++/Objective-C Settings
Controls compilation of C, C++, and Objective-C code.Default target platform for C/C++/Objective-C compilation.Options:
iphonesimulator-x86_64- 64-bit iOS Simulator (Intel Macs)iphonesimulator-arm64- ARM64 iOS Simulator (Apple Silicon)iphoneos-arm64- Physical iOS devices
C and Objective-C compiler flags.Flags:
-g- Generate debug symbols-fmodules- Enable Clang modules-fobjc-arc- Enable ARC-D BUCK- Define BUCK preprocessor macro-w- Suppress warnings$(config code_coverage.clang_flags)- Inject coverage flags when enabled
C++ compiler flags.Flags:
-fobjc-arc- Enable ARC (for Objective-C++)-std=c++14- Use C++14 standard-D DEBUG- Define DEBUG preprocessor macro-g- Generate debug symbols
Combine preprocessing and compilation into a single step for faster builds.
Disable precompiled headers.
Linker flags for C/C++/Objective-C targets.Flags:
-Xlinker -objc_abi_version -Xlinker 2- Objective-C ABI version-fobjc-arc- Link ARC runtime-fobjc-link-runtime- Link Objective-C runtime
[swift] - Swift Settings
Controls Swift compilation.Swift language version.
Swift compiler flags.Flags:
-DBUCK- Define BUCK conditional compilation symbol-whole-module-optimization- Enable WMO for better performance$(config custom.optimization)- Optimization level from [custom] section$(config custom.config_swift_compiler_flags)- Additional flags from [custom]$(config code_coverage.swift_flags)- Coverage instrumentation flags
Use filelists to pass source files to swiftc (avoids command line length limits).
[apple] - Apple Platform Settings
Apple-specific build settings.Use Swift compiler delegate for compilation.
Disable header maps in generated Xcode projects.
Automatically generate umbrella headers for Objective-C modules.
Minimum iOS version for Simulator builds.
Minimum iOS version for device builds.
Command to read provisioning profiles.
Default simulator for xctool test runner.
Path to xctool binary.
[parser] - BUCK File Parsing
Controls how BUCK files are parsed.Enable polyglot parsing (allows Python and Skylark).
Default syntax for BUCK files.Options:
SKYLARK- Starlark/Bazel syntax (recommended)PYTHON_DSL- Python-based DSL
[project] - Xcode Project Generation
Settings forbuck project command.
When to force-kill IDE before project generation.Options:
always- Always kill IDEnever- Never kill IDEprompt- Ask user
Generate Xcode schemes for targets.
IDE type for project generation.
Symlink handling in generated projects.Options:
forbid- Don’t allow symlinksallow- Allow symlinks
Comma-separated list of directories to ignore in project.Default ignored:
tools.git
[build] - Build Execution
Build system behavior.Number of parallel build threads.Recommendation: Set to number of CPU cores for optimal performance.
[custom] - Project-Specific Settings
Custom configuration values referenced by build macros.- Debug (.buckconfig)
- Release (BuildConfigurations/Release.buckconfig)
Build configuration name.Values:
debug- Development buildsrelease- Production builds
Swift optimization level.Options:
-Onone- No optimization (debug)-O- Standard optimization-Osize- Optimize for size-Ounchecked- Aggressive optimization (removes safety checks)
Additional Swift compiler flags.Debug flags:
-DDEBUG- Define DEBUG symbol-enable-testing- Enable @testable imports-g- Generate debug symbols
-DRELEASE- Define RELEASE symbol
C/Objective-C coverage flags (injected into [cxx].cflags).Flags:
-fprofile-instr-generate- Generate instrumentation-fcoverage-mapping- Generate coverage mapping
C++ coverage flags (injected into [cxx].cxxflags).
Linker flags for coverage (injected into [cxx].ldflags).
Swift coverage flags (injected into [swift].compiler_flags).Flags:
-profile-generate- Generate profile data-profile-coverage-mapping- Generate coverage mapping
[code_coverage] - Coverage Configuration
Defined incode_coverage.buckconfig, referenced by main config.
Clang coverage instrumentation flags.Referenced by:
[cxx].cflags via $(config code_coverage.clang_flags)Swift coverage instrumentation flags.Referenced by:
[swift].compiler_flags via $(config code_coverage.swift_flags)Linker flags for coverage.Referenced by:
[cxx].ldflags via $(config code_coverage.ldflags)Configuration Hierarchy
Buck loads configurations in this order:.buckconfig- Base configuration (always loaded)--config-file- Overlay config specified on command line--config- Individual setting overrides on command line
Example: Release Build
- Base settings from
.buckconfig - Overridden by
BuildConfigurations/Release.buckconfig:[custom].config = release[custom].optimization = -Osize[custom].config_swift_compiler_flags = -DRELEASE
Example: Command Line Override
- Base settings from
.buckconfig [swift].versionoverridden to5.5
Config References
Configurations can reference other sections using$(config section.key) syntax.
Example: Swift Flags
Coverage Flag Injection
The main.buckconfig injects coverage flags conditionally:
code_coverage.buckconfig:
$(config code_coverage.clang_flags) expands to -fprofile-instr-generate -fcoverage-mapping.
Build Configurations in Code
TheConfig/configs.bzl file defines build configuration dictionaries used by macros:
SHARED_CONFIGS
Common settings for all targets:Configuration Dictionary Structure
Buck expects configurations as nested dictionaries:Common Configuration Patterns
Adding a New Build Configuration
- Create
BuildConfigurations/MyConfig.buckconfig:
- Use in build commands:
Conditional Compilation
Use configuration flags for conditional code:- Swift
- Objective-C
Xcode Beta Handling
Theapple_lib macro automatically disables warnings-as-errors for Xcode beta:
.buckconfig:
Debugging Configuration
View Effective Configuration
View Specific Section
[swift] settings.
View With Config File
Trace Config References
Add debug output to verify flag expansion:Best Practices
Use Config Files for Major Changes
Use Config Files for Major Changes
Create separate config files in
BuildConfigurations/ for distinct build types (Debug, Release, AppStore, Enterprise).Don’t: Use --config flags for complex changesDo: Use config files that can be version controlledReference Custom Section for Dynamic Values
Reference Custom Section for Dynamic Values
Use This allows different configs to override just
[custom] section for values that change between configurations.[custom].optimization.Keep Coverage Flags Separate
Keep Coverage Flags Separate
Define coverage flags in a separate file that’s explicitly loaded:This prevents accidental coverage overhead in non-test builds.
Document Custom Settings
Document Custom Settings
Add comments to custom configuration sections:
Use Consistent Naming
Use Consistent Naming
Follow naming conventions:
- Config files:
BuildConfigurations/{ConfigName}.buckconfig - Custom config value:
[custom].config = {lowercase} - Conditional compilation:
-D{UPPERCASE}