How Rebaze Works
Rebaze analyzes your existing build system and generates equivalent Bazel build files.
Migration Pipeline
Section titled “Migration Pipeline”┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐│ Analyze │ ──▶ │ Parse │ ──▶ │ Transform │ ──▶ │ Generate ││ │ │ │ │ │ │ ││ Detect build│ │ Extract │ │ Map deps, │ │ Write Bazel ││ system │ │ targets │ │ filter │ │ files │└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘Phase 1: Analysis
Section titled “Phase 1: Analysis”Rebaze detects the build system by looking for marker files:
| File | Build System |
|---|---|
CMakeLists.txt | CMake |
build.gradle / build.gradle.kts | Gradle |
pom.xml | Maven |
Makefile | Make |
Cargo.toml | Cargo |
Phase 2: Parsing
Section titled “Phase 2: Parsing”CMake Parser
Section titled “CMake Parser”The CMake parser handles:
- Commands:
project(),add_executable(),add_library(), etc. - Variables:
${VAR},$ENV{VAR},$CACHE{VAR} - Control flow:
if(),foreach(),function(),macro() - Generator expressions:
$<TARGET_FILE:...>
Two parsing modes:
- CMakeLists.txt parsing - Analyzes CMake files directly
- cmake-file-api - Uses CMake’s File API for exact build info
Gradle Parser
Section titled “Gradle Parser”Extracts:
- Project structure from
settings.gradle - Dependencies from
build.gradle - Plugins and versions
- Source sets
Phase 3: Transformation
Section titled “Phase 3: Transformation”- Maps dependencies - Translates CMake/Gradle deps to Bazel targets
- Filters artifacts - Removes platform-specific files and flags
- Resolves includes - Converts include paths to Bazel format
- Groups sources - Organizes files into appropriate targets
Dependency Mapping Example
Section titled “Dependency Mapping Example”CMake Bazel───── ─────find_package(ZLIB) ──▶ @zlibtarget_link_libraries( deps = [ mylib "@zlib", ZLIB::ZLIB "@openssl//:ssl", OpenSSL::SSL ])Filtering
Section titled “Filtering”Rebaze filters out:
- Platform-specific sources (
.rc,.plist) - Build-type defines (
_DEBUG,NDEBUG) - Compiler-specific flags (
/W4,-march=native) - System include paths (
/usr/include)
Phase 4: Generation
Section titled “Phase 4: Generation”Always Generated
Section titled “Always Generated”| File | Purpose |
|---|---|
MODULE.bazel | Module definition, dependencies |
BUILD.bazel | Build targets |
.bazelversion | Pins Bazel version |
.bazelrc | Build configuration |
For CMake with pkg-config
Section titled “For CMake with pkg-config”| File | Purpose |
|---|---|
third_party/BUILD.bazel | Dependency aliases |
third_party/config.bzl | Strategy configuration |
Build Generators
Section titled “Build Generators”| Generator | Description |
|---|---|
native | Pure Rust implementation, always available |
bazelle | Uses gazelle_cc for complex projects |
auto | Prefers bazelle if available |
Architecture
Section titled “Architecture”rebaze-cli Command-line interface │rebaze-core Orchestration, shared logic │ ├── rebaze-cmake CMake parser ├── rebaze-cmake-file-api CMake File API ├── rebaze-gradle Gradle parser │rebaze-bazel Bazel file generator │rebaze-starlark Starlark AST/serialization