This document summarizes the Buck2 migration attempt for the finch-buck2 project, demonstrating the "dogfooding" approach where the tool would migrate its own build system from CMake to Buck2.
- ✅ Created
.buckconfigwith proper cell configuration - ✅ Created
.buckrootto mark the repository root - ✅ Cloned the Buck2 prelude from Facebook's repository
- ✅ Created directory structure for Buck2 configuration
- ✅ Root
BUCKfile with:finch-corelibrary targetfinchexecutable targetfinch-teststest target- Version header generation via
genrule
- ✅ Platform configuration files
- ✅ Third-party dependency placeholders
[cells]
root = .
prelude = buck2/prelude
config = buck2/prelude
toolchains = buck2/prelude
fbsource = buck2/prelude
fbcode = buck2/prelude
buck = buck2/prelude
[parser]
target_platform_detector_spec = target:root//...->prelude//platforms:default- Proper C++20 configuration
- Platform-specific preprocessor flags
- Header and source file globbing
- Dependency management structure
The Buck2 prelude is deeply integrated with Meta's internal infrastructure and expects certain targets and configurations that don't exist in open-source projects:
python_bootstraptarget requirements- Internal toolchain configurations
- Facebook-specific cell aliases (fbsource, fbcode)
The current Buck2 setup doesn't have a standard way to fetch external dependencies like:
- fmt
- spdlog
- CLI11
- nlohmann_json
- GoogleTest
These would need custom http_archive rules or local vendoring.
Buck2's platform detection and constraint system is more complex than CMake's simple if/else approach, requiring:
- Constraint definitions
- Platform rules
- Execution platform specifications
Consider creating a minimal prelude specifically for open-source C++ projects that:
- Removes Meta-specific dependencies
- Provides simple C++ rules
- Includes common third-party dependency patterns
Implement proper third-party dependency fetching:
http_archive(
name = "fmt",
urls = ["https://github.com/fmtlib/fmt/archive/10.2.1.tar.gz"],
strip_prefix = "fmt-10.2.1",
build_file = "//third_party:fmt.BUILD",
)Create explicit toolchain configurations for common platforms:
- macOS with Apple Clang
- Linux with GCC/Clang
- Windows with MSVC
Based on this experience, finch should:
- Generate simpler Buck2 configurations for open-source projects
- Provide options for different prelude versions
- Include dependency migration patterns
- Generate platform-specific configurations
While we couldn't get Buck2 to build successfully, the expected performance improvements would be:
| Metric | CMake | Buck2 (Expected) | Improvement |
|---|---|---|---|
| Clean Build | ~2s | ~1.5s | 25% |
| Incremental (1 file) | ~0.5s | ~0.1s | 80% |
| Incremental (header) | ~1s | ~0.3s | 70% |
| With Cache | N/A | ~0.05s | 95% |
While the full Buck2 migration wasn't completed due to prelude complexity, this exercise:
- ✅ Demonstrated the structure needed for Buck2 migration
- ✅ Identified key challenges in migrating open-source projects
- ✅ Provided insights for improving the finch tool
- ✅ Created a foundation that could be built upon with a simpler prelude
The Buck2 configuration files have been created and committed, serving as a starting point for future migration attempts when Buck2 becomes more accessible for open-source projects.