Skip to content

Latest commit

 

History

History
141 lines (97 loc) · 3.95 KB

File metadata and controls

141 lines (97 loc) · 3.95 KB

Buck2 Migration Summary for finch-buck2

Overview

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.

What Was Accomplished

1. Buck2 Infrastructure Setup

  • ✅ Created .buckconfig with proper cell configuration
  • ✅ Created .buckroot to mark the repository root
  • ✅ Cloned the Buck2 prelude from Facebook's repository
  • ✅ Created directory structure for Buck2 configuration

2. Build Files Created

  • ✅ Root BUCK file with:
    • finch-core library target
    • finch executable target
    • finch-tests test target
    • Version header generation via genrule
  • ✅ Platform configuration files
  • ✅ Third-party dependency placeholders

3. Configuration Details

.buckconfig

[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

Main BUCK file structure

  • Proper C++20 configuration
  • Platform-specific preprocessor flags
  • Header and source file globbing
  • Dependency management structure

Challenges Encountered

1. Prelude Complexity

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_bootstrap target requirements
  • Internal toolchain configurations
  • Facebook-specific cell aliases (fbsource, fbcode)

2. Missing External Dependencies

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.

3. Platform Detection

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

Recommendations for Future Work

1. Simplified Prelude

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

2. Dependency Management

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",
)

3. Toolchain Configuration

Create explicit toolchain configurations for common platforms:

  • macOS with Apple Clang
  • Linux with GCC/Clang
  • Windows with MSVC

4. Migration Tool Enhancements

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

Performance Comparison (Theoretical)

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%

Conclusion

While the full Buck2 migration wasn't completed due to prelude complexity, this exercise:

  1. ✅ Demonstrated the structure needed for Buck2 migration
  2. ✅ Identified key challenges in migrating open-source projects
  3. ✅ Provided insights for improving the finch tool
  4. ✅ 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.